kc-beta 0.7.3 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -4
- package/bin/kc-beta.js +20 -6
- package/package.json +3 -2
- package/src/agent/engine.js +493 -132
- package/src/agent/pipelines/_advance-hints.js +92 -0
- package/src/agent/pipelines/_milestone-derive.js +387 -17
- package/src/agent/pipelines/initializer.js +4 -1
- package/src/agent/pipelines/skill-authoring.js +30 -1
- package/src/agent/skill-loader.js +433 -111
- package/src/agent/tools/agent-tool.js +2 -2
- package/src/agent/tools/consult-skill.js +127 -0
- package/src/agent/tools/copy-to-workspace.js +4 -3
- package/src/agent/tools/dashboard-render.js +48 -1
- package/src/agent/tools/document-parse.js +31 -2
- package/src/agent/tools/phase-advance.js +17 -13
- package/src/agent/tools/release.js +378 -8
- package/src/agent/tools/sandbox-exec.js +65 -8
- package/src/agent/tools/worker-llm-call.js +95 -15
- package/src/agent/tools/workspace-file.js +7 -7
- package/src/agent/workspace.js +25 -4
- package/src/cli/components.js +4 -1
- package/src/cli/index.js +97 -1
- package/src/config.js +20 -3
- package/src/marathon/driver.js +217 -0
- package/src/marathon/prompts.js +93 -0
- package/template/.env.template +16 -0
- package/template/AGENT.md +182 -7
- package/template/skills/en/{meta-meta/auto-model-selection → auto-model-selection}/SKILL.md +1 -0
- package/template/skills/en/{meta-meta/bootstrap-workspace → bootstrap-workspace}/SKILL.md +15 -0
- package/template/skills/{zh/meta → en}/compliance-judgment/SKILL.md +1 -0
- package/template/skills/en/{meta/confidence-system → confidence-system}/SKILL.md +1 -0
- package/template/skills/en/{meta/corner-case-management → corner-case-management}/SKILL.md +1 -0
- package/template/skills/en/{meta/cross-document-verification → cross-document-verification}/SKILL.md +1 -0
- package/template/skills/en/{meta-meta/dashboard-reporting → dashboard-reporting}/SKILL.md +1 -0
- package/template/skills/en/{meta/data-sensibility → data-sensibility}/SKILL.md +1 -0
- package/template/skills/{zh/meta → en}/document-chunking/SKILL.md +1 -0
- package/template/skills/en/{meta/document-parsing → document-parsing}/SKILL.md +1 -0
- package/template/skills/{zh/meta → en}/entity-extraction/SKILL.md +1 -0
- package/template/skills/en/{meta-meta/evolution-loop → evolution-loop}/SKILL.md +1 -0
- package/template/skills/en/{meta-meta/pdf-review-dashboard → pdf-review-dashboard}/SKILL.md +1 -0
- package/template/skills/en/{meta-meta/quality-control → quality-control}/SKILL.md +10 -0
- package/template/skills/en/{meta-meta/rule-extraction → rule-extraction}/SKILL.md +1 -0
- package/template/skills/en/{meta-meta/rule-graph → rule-graph}/SKILL.md +1 -0
- package/template/skills/en/{meta-meta/skill-authoring → skill-authoring}/SKILL.md +40 -0
- package/template/skills/en/skill-creator/SKILL.md +2 -1
- package/template/skills/en/{meta-meta/skill-to-workflow → skill-to-workflow}/SKILL.md +58 -4
- package/template/skills/en/{meta-meta/task-decomposition → task-decomposition}/SKILL.md +1 -0
- package/template/skills/en/{meta/tree-processing → tree-processing}/SKILL.md +1 -0
- package/template/skills/en/{meta-meta/version-control → version-control}/SKILL.md +1 -0
- package/template/skills/en/{meta-meta/work-decomposition → work-decomposition}/SKILL.md +51 -6
- package/template/skills/phase_skills.yaml +112 -0
- package/template/skills/zh/{meta-meta/auto-model-selection → auto-model-selection}/SKILL.md +1 -0
- package/template/skills/zh/{meta-meta/bootstrap-workspace → bootstrap-workspace}/SKILL.md +15 -0
- package/template/skills/zh/compliance-judgment/SKILL.md +83 -0
- package/template/skills/zh/{meta/confidence-system → confidence-system}/SKILL.md +1 -0
- package/template/skills/zh/{meta/corner-case-management → corner-case-management}/SKILL.md +1 -0
- package/template/skills/zh/{meta/cross-document-verification → cross-document-verification}/SKILL.md +1 -0
- package/template/skills/zh/{meta-meta/dashboard-reporting → dashboard-reporting}/SKILL.md +1 -0
- package/template/skills/zh/{meta/data-sensibility → data-sensibility}/SKILL.md +1 -0
- package/template/skills/zh/document-chunking/SKILL.md +40 -0
- package/template/skills/zh/document-parsing/SKILL.md +102 -0
- package/template/skills/zh/entity-extraction/SKILL.md +121 -0
- package/template/skills/zh/{meta-meta/evolution-loop → evolution-loop}/SKILL.md +1 -0
- package/template/skills/zh/{meta-meta/pdf-review-dashboard → pdf-review-dashboard}/SKILL.md +1 -0
- package/template/skills/zh/{meta-meta/quality-control → quality-control}/SKILL.md +10 -0
- package/template/skills/zh/{meta-meta/rule-extraction → rule-extraction}/SKILL.md +1 -0
- package/template/skills/zh/{meta-meta/rule-graph → rule-graph}/SKILL.md +1 -0
- package/template/skills/zh/{meta-meta/skill-authoring → skill-authoring}/SKILL.md +40 -0
- package/template/skills/zh/skill-creator/SKILL.md +205 -200
- package/template/skills/zh/skill-to-workflow/SKILL.md +243 -0
- package/template/skills/zh/{meta-meta/task-decomposition → task-decomposition}/SKILL.md +1 -0
- package/template/skills/zh/tree-processing/SKILL.md +126 -0
- package/template/skills/zh/{meta-meta/version-control → version-control}/SKILL.md +1 -0
- package/template/skills/zh/{meta-meta/work-decomposition → work-decomposition}/SKILL.md +49 -4
- package/template/workflows/common/llm_client.py +168 -0
- package/template/workflows/common/utils.py +132 -0
- package/template/CLAUDE.md +0 -150
- package/template/skills/en/meta/compliance-judgment/SKILL.md +0 -82
- package/template/skills/en/meta/document-chunking/SKILL.md +0 -32
- package/template/skills/en/meta/entity-extraction/SKILL.md +0 -120
- package/template/skills/zh/meta/document-parsing/SKILL.md +0 -101
- package/template/skills/zh/meta/tree-processing/SKILL.md +0 -121
- package/template/skills/zh/meta-meta/skill-to-workflow/SKILL.md +0 -188
- /package/template/skills/en/{meta/compliance-judgment → compliance-judgment}/references/output-format.md +0 -0
- /package/template/skills/en/{meta/cross-document-verification → cross-document-verification}/references/contradiction-taxonomy.md +0 -0
- /package/template/skills/en/{meta-meta/dashboard-reporting → dashboard-reporting}/scripts/generate_dashboard.py +0 -0
- /package/template/skills/en/{meta/document-parsing → document-parsing}/references/parser-catalog.md +0 -0
- /package/template/skills/en/{meta-meta/evolution-loop → evolution-loop}/references/convergence-guide.md +0 -0
- /package/template/skills/en/{meta-meta/pdf-review-dashboard → pdf-review-dashboard}/scripts/generate_review.js +0 -0
- /package/template/skills/en/{meta-meta/quality-control → quality-control}/references/qa-layers.md +0 -0
- /package/template/skills/en/{meta-meta/quality-control → quality-control}/references/sampling-strategies.md +0 -0
- /package/template/skills/en/{meta-meta/rule-extraction → rule-extraction}/references/chunking-strategies.md +0 -0
- /package/template/skills/en/{meta-meta/skill-authoring → skill-authoring}/references/skill-format-spec.md +0 -0
- /package/template/skills/en/{meta-meta/skill-to-workflow → skill-to-workflow}/references/worker-llm-catalog.md +0 -0
- /package/template/skills/en/{meta-meta/task-decomposition → task-decomposition}/references/decision-matrix.md +0 -0
- /package/template/skills/en/{meta-meta/version-control → version-control}/references/trace-id-spec.md +0 -0
- /package/template/skills/zh/{meta/compliance-judgment → compliance-judgment}/references/output-format.md +0 -0
- /package/template/skills/zh/{meta/cross-document-verification → cross-document-verification}/references/contradiction-taxonomy.md +0 -0
- /package/template/skills/zh/{meta-meta/dashboard-reporting → dashboard-reporting}/scripts/generate_dashboard.py +0 -0
- /package/template/skills/zh/{meta/document-parsing → document-parsing}/references/parser-catalog.md +0 -0
- /package/template/skills/zh/{meta-meta/evolution-loop → evolution-loop}/references/convergence-guide.md +0 -0
- /package/template/skills/zh/{meta-meta/pdf-review-dashboard → pdf-review-dashboard}/scripts/generate_review.js +0 -0
- /package/template/skills/zh/{meta-meta/quality-control → quality-control}/references/qa-layers.md +0 -0
- /package/template/skills/zh/{meta-meta/quality-control → quality-control}/references/sampling-strategies.md +0 -0
- /package/template/skills/zh/{meta-meta/rule-extraction → rule-extraction}/references/chunking-strategies.md +0 -0
- /package/template/skills/zh/{meta-meta/skill-authoring → skill-authoring}/references/skill-format-spec.md +0 -0
- /package/template/skills/zh/{meta-meta/skill-to-workflow → skill-to-workflow}/references/worker-llm-catalog.md +0 -0
- /package/template/skills/zh/{meta-meta/task-decomposition → task-decomposition}/references/decision-matrix.md +0 -0
- /package/template/skills/zh/{meta-meta/version-control → version-control}/references/trace-id-spec.md +0 -0
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: tree-processing
|
|
3
|
-
description: >
|
|
4
|
-
Design production-grade document chunking mechanisms for verification workflows. Use when
|
|
5
|
-
building the chunking step of a workflow that will run repeatedly on many documents.
|
|
6
|
-
The approach: observe sample documents, find structural patterns, write a chunking script
|
|
7
|
-
in code, that script runs in production. Also use for navigating large documents via
|
|
8
|
-
hierarchical structure when a rule targets a specific section.
|
|
9
|
-
For quick, cheap batch chunking during exploration, use document-chunking instead.
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
# Tree Processing
|
|
13
|
-
|
|
14
|
-
Most verification rules do not need the entire document. They need a specific section, a specific table, a specific disclosure. The tree is your map for navigating large documents efficiently.
|
|
15
|
-
|
|
16
|
-
## Production Chunking Methodology
|
|
17
|
-
|
|
18
|
-
For verification workflows that process many documents, the chunking mechanism must be precise, consistent, and fast. The approach:
|
|
19
|
-
|
|
20
|
-
1. **Observe**: Read 3-5 sample documents. Note their structure — headers, numbering, section patterns.
|
|
21
|
-
2. **Find patterns**: Identify what's consistent (header format, numbering convention, TOC structure).
|
|
22
|
-
3. **Write code**: Design a chunking script (regex-based splitter, header detector, TOC parser) that captures the pattern.
|
|
23
|
-
4. **Test**: Run the script on samples. Verify it produces correct, consistent chunks.
|
|
24
|
-
5. **Deploy**: The script runs in production workflows. It's deterministic, free, and fast.
|
|
25
|
-
|
|
26
|
-
This is different from `document-chunking` (quick, cheap splits for exploration). Production chunking is a one-time design effort that pays off across all documents of the same type.
|
|
27
|
-
|
|
28
|
-
## Why Trees
|
|
29
|
-
|
|
30
|
-
Two reasons:
|
|
31
|
-
|
|
32
|
-
1. **Rules have scope.** "The risk disclosure in Chapter 5 must contain..." — you need to find Chapter 5, not read 1000 pages.
|
|
33
|
-
2. **Worker LLMs have limits.** A 16K-32K context window cannot hold a 1000-page document. You must narrow to the relevant section.
|
|
34
|
-
|
|
35
|
-
The tree structure solves both: it tells you WHERE things are, and lets you extract JUST what you need.
|
|
36
|
-
|
|
37
|
-
## Building the Tree
|
|
38
|
-
|
|
39
|
-
### Step 1: Discover the Structure
|
|
40
|
-
|
|
41
|
-
Before building a tree parser, explore several sample documents to find structural patterns. Look for:
|
|
42
|
-
|
|
43
|
-
- **Header conventions**: Do chapters start with "Chapter X"? "第X章"? "Part X"? A Roman numeral?
|
|
44
|
-
- **Numbering systems**: "1.1.2", "Article 3", "(a)(i)", hierarchical numbering?
|
|
45
|
-
- **Visual markers**: Bold text, larger font, horizontal rules, page breaks before chapters?
|
|
46
|
-
- **Table of contents**: Most formal documents have one. It is the document's own tree.
|
|
47
|
-
|
|
48
|
-
Spend time here. The patterns you find determine whether the tree builder is a simple regex or a complex parser.
|
|
49
|
-
|
|
50
|
-
### Step 2: Choose the Parser
|
|
51
|
-
|
|
52
|
-
**If patterns are consistent** (they usually are in regulated documents):
|
|
53
|
-
- Write a regex-based splitter. For example:
|
|
54
|
-
- `^第[一二三四五六七八九十百千]+章` for Chinese chapter headers
|
|
55
|
-
- `^Chapter \d+` for English
|
|
56
|
-
- `^\d+\.\d+(\.\d+)*\s` for numbered sections
|
|
57
|
-
- This is fast, deterministic, and reliable. Prefer this when it works.
|
|
58
|
-
|
|
59
|
-
**If patterns are inconsistent or absent**:
|
|
60
|
-
- Use the LLM-guided wedge-driving approach (see `rule-extraction/references/chunking-strategies.md` for the full algorithm: rolling context window, K-token quoting, Levenshtein fuzzy matching).
|
|
61
|
-
- This is slower and costs LLM calls, but handles unstructured documents. The rolling window means even very large unstructured leaf nodes can be chunked incrementally.
|
|
62
|
-
|
|
63
|
-
**If the document has a table of contents**:
|
|
64
|
-
- Parse the TOC first. It gives you the tree structure and page numbers for free.
|
|
65
|
-
- Then use the TOC-derived structure to split the document body.
|
|
66
|
-
|
|
67
|
-
### Step 3: Build the Tree
|
|
68
|
-
|
|
69
|
-
The tree is a simple nested structure:
|
|
70
|
-
|
|
71
|
-
```
|
|
72
|
-
Document
|
|
73
|
-
├── Part I: General Provisions
|
|
74
|
-
│ ├── Chapter 1: Definitions (pages 1-15)
|
|
75
|
-
│ └── Chapter 2: Scope (pages 16-22)
|
|
76
|
-
├── Part II: Capital Requirements
|
|
77
|
-
│ ├── Chapter 3: Minimum Capital (pages 23-45)
|
|
78
|
-
│ │ ├── Section 3.1: Tier 1 Capital
|
|
79
|
-
│ │ └── Section 3.2: Tier 2 Capital
|
|
80
|
-
│ └── Chapter 4: Risk Weighting (pages 46-78)
|
|
81
|
-
└── Part III: Disclosure
|
|
82
|
-
└── Chapter 5: Risk Disclosure (pages 79-120)
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
Each node stores: the header text, the level, the start/end positions in the document, and the content size (in tokens or characters).
|
|
86
|
-
|
|
87
|
-
### Step 4: Use the Tree
|
|
88
|
-
|
|
89
|
-
Given a rule that says "check the risk disclosure section":
|
|
90
|
-
|
|
91
|
-
1. **Search the tree** for the relevant node. Match the rule's scope description against node headers.
|
|
92
|
-
- Exact match: "Chapter 5" → find node with "Chapter 5" header.
|
|
93
|
-
- Semantic match: "risk disclosure section" → find node whose header or content relates to risk disclosure. May need fuzzy matching or LLM classification.
|
|
94
|
-
2. **Extract the content** of that node (and optionally its children).
|
|
95
|
-
3. **Check the size.** If the content fits in the worker LLM's context window, use it directly. If not, descend to child nodes and find the specific subsection needed.
|
|
96
|
-
|
|
97
|
-
## The Full Context → Chapter → Entity Pipeline
|
|
98
|
-
|
|
99
|
-
This is the standard narrowing funnel for extracting entities for verification:
|
|
100
|
-
|
|
101
|
-
1. **Full context**: Use the tree to understand the document structure. Know where everything is.
|
|
102
|
-
2. **Chapter**: Navigate to the specific section that the rule targets. Extract its content.
|
|
103
|
-
3. **Entity**: Within the chapter content, extract the specific entity (number, text, clause) using the techniques from `entity-extraction`.
|
|
104
|
-
|
|
105
|
-
For worker LLMs with 16K-32K context:
|
|
106
|
-
- The chapter content + the extraction prompt must fit in the context window.
|
|
107
|
-
- If a chapter is too large, descend further in the tree.
|
|
108
|
-
- Always include the parent header chain for context: "Part II > Chapter 3 > Section 3.1" so the LLM knows where this content sits in the document.
|
|
109
|
-
|
|
110
|
-
## Caching and Reuse
|
|
111
|
-
|
|
112
|
-
Build the tree once per document, reuse across all rules:
|
|
113
|
-
- Save the tree structure as JSON alongside the parsed document.
|
|
114
|
-
- Multiple rules may need different sections of the same document. The tree lets each rule navigate directly to its section without re-parsing.
|
|
115
|
-
|
|
116
|
-
## Edge Cases
|
|
117
|
-
|
|
118
|
-
- **Flat documents**: Some documents have no structural hierarchy. Treat the entire document as one node. Use LLM-guided chunking if it exceeds the context window.
|
|
119
|
-
- **Deeply nested structures**: Some legal documents have 6+ nesting levels. Build all levels but typically only navigate 2-3 levels deep for any given rule.
|
|
120
|
-
- **Cross-section references**: A section might reference "as defined in Section 1.2." When extracting, you may need content from multiple tree nodes. Collect them into a single context for the LLM.
|
|
121
|
-
- **Appendices and annexes**: Often contain critical tables and data. Include them as top-level nodes in the tree.
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: skill-to-workflow
|
|
3
|
-
description: Distill a proven verification skill into a Python workflow with worker LLM prompts. Use when a rule skill has been tested and reaches the SKILL_ACCURACY threshold defined in .env. Covers the decision of what to implement as code vs LLM calls, prompt engineering for small context windows, model tier selection and progressive downgrade, and testing workflows against the coding agent's own results as ground truth. Also use when optimizing existing workflows for cost or speed.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Skill to Workflow
|
|
7
|
-
|
|
8
|
-
The skill is the ground truth. The workflow is a cheaper, faster approximation. Your job is to make the approximation as good as the original while being as cheap as possible.
|
|
9
|
-
|
|
10
|
-
## Engineering Goal
|
|
11
|
-
|
|
12
|
-
Optimize the full chain: **shortest workflow** (fewest nodes) → **smallest model per node** (cheapest tier that meets accuracy) → **shortest prompt per model** (minimum tokens). This is the engineering objective — not prompt template sophistication or framework compliance.
|
|
13
|
-
|
|
14
|
-
## When to Start
|
|
15
|
-
|
|
16
|
-
A skill is ready for workflow distillation when:
|
|
17
|
-
- It has been tested on all documents in Samples/.
|
|
18
|
-
- Its accuracy meets or exceeds the SKILL_ACCURACY threshold in `.env`.
|
|
19
|
-
- Edge cases are documented in the skill's `assets/corner_cases.json`.
|
|
20
|
-
- You understand the rule well enough to explain exactly how you verify it.
|
|
21
|
-
|
|
22
|
-
If any of these are not true, go back and iterate on the skill first.
|
|
23
|
-
|
|
24
|
-
## The Distillation Decision
|
|
25
|
-
|
|
26
|
-
For each step in your skill-based verification process, ask:
|
|
27
|
-
|
|
28
|
-
### Can this be done with regex or Python? (Cost: zero)
|
|
29
|
-
- Date extraction with known formats → regex
|
|
30
|
-
- Numeric comparison against threshold → Python arithmetic
|
|
31
|
-
- Chinese numeral conversion → Python lookup table
|
|
32
|
-
- Format validation (ID numbers, codes) → regex
|
|
33
|
-
- Table cell extraction from structured markdown → string manipulation
|
|
34
|
-
|
|
35
|
-
If yes, write it as code. These are free, fast, and deterministic.
|
|
36
|
-
|
|
37
|
-
### Does this require language understanding? (Cost: worker LLM call)
|
|
38
|
-
- Finding the relevant section in a document → LLM
|
|
39
|
-
- Extracting an entity described in natural language → LLM
|
|
40
|
-
- Judging semantic adequacy ("adequate risk disclosure") → LLM
|
|
41
|
-
- Resolving ambiguous references → LLM
|
|
42
|
-
|
|
43
|
-
If yes, design a worker LLM prompt. Use the smallest model tier that maintains accuracy.
|
|
44
|
-
|
|
45
|
-
### The hybrid approach (most common)
|
|
46
|
-
Most rules are a mix: regex extracts the number, Python compares it to the threshold, LLM handles the exceptional cases. Design the workflow as a pipeline where cheap steps run first and expensive steps run only when needed.
|
|
47
|
-
|
|
48
|
-
### When regex alone isn't enough — decision rubric
|
|
49
|
-
|
|
50
|
-
Before declaring distillation complete, audit each rule's `verification_type` / `metric` / `evidence_type` (or equivalent fields in your catalog). For rules where the required verification is one of:
|
|
51
|
-
|
|
52
|
-
- **Semantic** ("is this a positive guarantee or a disclaimer?")
|
|
53
|
-
- **Contextual** ("interpret this in light of the document's product type")
|
|
54
|
-
- **Counterfactual** ("what should this value be, given the other fields?")
|
|
55
|
-
- **Cross-field arithmetic** ("does 期初 + 收益 - 分配 = 期末?")
|
|
56
|
-
|
|
57
|
-
regex alone rarely suffices. Three acceptable forms:
|
|
58
|
-
|
|
59
|
-
1. **Pure regex with documented limits** — write the regex check, include a comment explaining the fragility (e.g., "matches syntactic pattern only; cannot detect semantic guarantees")
|
|
60
|
-
2. **Hybrid regex + LLM** — regex baseline catches obvious cases, `worker_llm_call` (tier1-2) handles ambiguous ones. The hybrid workflow declares which rule_ids escalate.
|
|
61
|
-
3. **Pure LLM via `worker_llm_call`** — for fully semantic rules where no regex baseline is meaningful.
|
|
62
|
-
|
|
63
|
-
Don't ship pure regex for a rule whose `verification_type` is `judgment` / `semantic` without the documented-limits note. Future-you or a colleague will assume the regex is sufficient and that bug will hide for months.
|
|
64
|
-
|
|
65
|
-
### Worker LLM cost-aware tier choice
|
|
66
|
-
|
|
67
|
-
If you do escalate to LLM:
|
|
68
|
-
- **tier1** (most capable, ~¥0.001-0.002/doc): cross-field reasoning, ambiguity resolution, rules that benefit from chain-of-thought
|
|
69
|
-
- **tier2-3**: bulk extraction with simple semantic checks
|
|
70
|
-
- **tier4** (cheapest): high-volume keyword-spotting that regex can't handle. Note: tier4 models on SiliconFlow are Qwen3.5 thinking-mode — `content` can return empty if `reasoning_content` consumes max_tokens. Test with realistic prompts before relying. If you see empty responses, either bump max_tokens to ≥8192, shorten your prompt, or fall back to tier1-2.
|
|
71
|
-
|
|
72
|
-
Both v0.7.1 audit conductors (DS and GLM) defaulted to all-regex distillation and only added LLM escalation when the human user explicitly asked for "V2 with worker LLM". If your rule catalog has any rules where the verification is genuinely semantic, you should reach for `worker_llm_call` yourself — don't wait to be asked.
|
|
73
|
-
|
|
74
|
-
## Workflow Structure
|
|
75
|
-
|
|
76
|
-
A workflow is a Python file (or small set of files) in `workflows/`:
|
|
77
|
-
|
|
78
|
-
```
|
|
79
|
-
workflows/
|
|
80
|
-
rule_001_capital_adequacy/
|
|
81
|
-
workflow_v1.py # The main workflow script
|
|
82
|
-
prompts/
|
|
83
|
-
extract.txt # Worker LLM prompt for extraction
|
|
84
|
-
judge.txt # Worker LLM prompt for judgment (if needed)
|
|
85
|
-
config.json # Model assignments, thresholds
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
The workflow file should have a clear entry point:
|
|
89
|
-
|
|
90
|
-
```python
|
|
91
|
-
def verify(document_text: str, config: dict) -> dict:
|
|
92
|
-
"""
|
|
93
|
-
Returns:
|
|
94
|
-
{
|
|
95
|
-
"rule_id": "R001",
|
|
96
|
-
"result": "pass" | "fail" | "missing" | "error",
|
|
97
|
-
"extracted_value": ...,
|
|
98
|
-
"confidence": 0.0-1.0,
|
|
99
|
-
"comment": "..." (only when fail),
|
|
100
|
-
"model_used": "...",
|
|
101
|
-
"llm_calls": int,
|
|
102
|
-
"llm_tokens": int
|
|
103
|
-
}
|
|
104
|
-
"""
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
This is a reference, not a rigid contract. Adapt the structure to the specific rule. The important thing is that every workflow produces a result that can be compared against the skill-based ground truth.
|
|
108
|
-
|
|
109
|
-
## Prompt Engineering for Worker LLMs
|
|
110
|
-
|
|
111
|
-
Worker LLMs have smaller context windows (typically 16K-32K tokens). Design prompts that:
|
|
112
|
-
|
|
113
|
-
1. **Are self-contained.** Include everything the model needs in the prompt. Do not assume the model has context from previous calls.
|
|
114
|
-
2. **Specify the output format.** "Return a JSON object with fields: value, confidence, reasoning." Structured output reduces parsing errors.
|
|
115
|
-
3. **Include the narrowed context.** Do not send the entire document. Use the tree-processing pipeline (full document → relevant chapter → relevant section) to narrow the context before calling the worker LLM.
|
|
116
|
-
4. **Are written in the document's language.** Chinese documents get Chinese prompts. English documents get English prompts. Do not mix languages in a single prompt.
|
|
117
|
-
5. **Provide examples sparingly.** One or two examples help. Ten examples waste context window and risk overfitting.
|
|
118
|
-
|
|
119
|
-
## Model Tier Selection
|
|
120
|
-
|
|
121
|
-
Start with the highest tier (TIER1) for each step. Measure accuracy. Then try lower tiers:
|
|
122
|
-
|
|
123
|
-
1. Run the workflow with TIER1 on all Samples/. Record accuracy per step.
|
|
124
|
-
2. For each step, try TIER2. If accuracy stays above WORKFLOW_ACCURACY, keep TIER2.
|
|
125
|
-
3. Continue downgrading per step until accuracy drops below threshold.
|
|
126
|
-
4. Record the optimal tier per step in `config.json`.
|
|
127
|
-
|
|
128
|
-
Different steps within the same workflow can use different model tiers. Extraction might need TIER2 while judgment might work fine with TIER3.
|
|
129
|
-
|
|
130
|
-
### Formal Downgrade Protocol
|
|
131
|
-
|
|
132
|
-
The basic approach above works, but a more rigorous protocol prevents premature tier commitments:
|
|
133
|
-
|
|
134
|
-
**Direction**: Start top-down (TIER1 → TIER4) to establish the accuracy ceiling first. You need to know the best possible accuracy before trading it for cost savings.
|
|
135
|
-
|
|
136
|
-
**Minimum test runs**: Run at least a meaningful number of documents (e.g., min(10, total_samples)) at each candidate tier before making a tier decision. Small samples are unreliable — a 3-document test could be misleading.
|
|
137
|
-
|
|
138
|
-
**Accuracy delta trigger**: If a lower tier's accuracy is significantly below the higher tier (e.g., >5 percentage points), stay at the higher tier for that step. If the delta is within tolerance, use the cheaper tier.
|
|
139
|
-
|
|
140
|
-
**Per-step independence**: Each workflow step is assessed separately. Record the optimal tier per step in `config.json`. Do not assume the whole workflow must use one tier.
|
|
141
|
-
|
|
142
|
-
**Re-assessment trigger**: If production quality control shows a step's accuracy degrading (e.g., due to new document formats), re-run the tier assessment for that step.
|
|
143
|
-
|
|
144
|
-
**Model-task recommendation list**: Maintain a per-project mapping of (task_type → recommended_tier) based on your testing experience. Over time, these lists can be collected across projects to build generalized tier recommendations.
|
|
145
|
-
|
|
146
|
-
All numbers here (10 documents, 5 percentage points, etc.) are recommended starting points. The coding agent and developer user should calibrate these — or replace them entirely with a different assessment approach — based on their specific volume, accuracy requirements, and cost constraints. The pattern matters: **test at each tier → compare accuracy → commit when within tolerance → re-assess on degradation**.
|
|
147
|
-
|
|
148
|
-
This follows the same tier-transition framework as parser escalation in `document-parsing`: a quality/accuracy score drives the decision to stay, escalate, or skip.
|
|
149
|
-
|
|
150
|
-
## Testing Against Ground Truth
|
|
151
|
-
|
|
152
|
-
The coding agent's skill-based results are the ground truth. For each document in Samples/:
|
|
153
|
-
|
|
154
|
-
1. Run the workflow.
|
|
155
|
-
2. Compare the workflow's result against the skill-based result.
|
|
156
|
-
3. Log discrepancies: which step failed, what was expected vs actual.
|
|
157
|
-
4. Compute accuracy: `(matching results) / (total documents)`.
|
|
158
|
-
5. If accuracy < WORKFLOW_ACCURACY, diagnose and fix. Use `evolution-loop` methodology.
|
|
159
|
-
|
|
160
|
-
## Versioning
|
|
161
|
-
|
|
162
|
-
Each iteration of a workflow is a new version file: `workflow_v1.py`, `workflow_v2.py`, etc. Track which version is active in `config.json`. See `version-control` skill for the full methodology.
|
|
163
|
-
|
|
164
|
-
## Releasing Workflows
|
|
165
|
-
|
|
166
|
-
Once workflows hit accuracy threshold, they can be packaged for end users via the `release` tool. Each release is a self-contained directory under `output/releases/<slug>/` with the pinned workflows, a Python runner, a confidence scorer, an HTML dashboard generator, and a `serve.sh` helper. The bundle has no kc-beta dependency — anyone with Python and a worker LLM API key can run `python run.py <doc>` and produce verification results.
|
|
167
|
-
|
|
168
|
-
What to include is your call: all rules in catalog, or a curated subset via the `include` parameter; bundling 1-3 representative samples as `fixtures/` if you want the recipient to be able to dry-run without their own data.
|
|
169
|
-
|
|
170
|
-
The `release` tool snapshots the workspace first (git tag `snap/release-<slug>`), so the bundle is regenerable from git even if `output/releases/` is later cleaned. Decide when to release — there's no automation, no forced cadence. Typical triggers: workflows reach SKILL/WORKFLOW_ACCURACY thresholds, a stakeholder needs a hand-off, a production cron should run pinned versions instead of latest. Discuss with the developer user.
|
|
171
|
-
|
|
172
|
-
## Cost Tracking
|
|
173
|
-
|
|
174
|
-
Track the cost of each workflow run:
|
|
175
|
-
- Number of LLM calls per document.
|
|
176
|
-
- Total tokens consumed per document.
|
|
177
|
-
- Model tier used per call.
|
|
178
|
-
|
|
179
|
-
This data helps the developer user understand the production cost and informs further optimization.
|
|
180
|
-
|
|
181
|
-
## Worker LLM API
|
|
182
|
-
|
|
183
|
-
Worker LLMs are accessed via SiliconFlow API. Connection details are in `.env`:
|
|
184
|
-
- `SILICONFLOW_API_KEY` for authentication
|
|
185
|
-
- `SILICONFLOW_BASE_URL` for the API endpoint
|
|
186
|
-
- Model names in `TIER1` through `TIER4`
|
|
187
|
-
|
|
188
|
-
See `references/worker-llm-catalog.md` for current model capabilities and context window sizes.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/template/skills/en/{meta/document-parsing → document-parsing}/references/parser-catalog.md
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/template/skills/en/{meta-meta/quality-control → quality-control}/references/qa-layers.md
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/template/skills/zh/{meta/document-parsing → document-parsing}/references/parser-catalog.md
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/template/skills/zh/{meta-meta/quality-control → quality-control}/references/qa-layers.md
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|