From ee3116513b73a291d6f17afa87083dfab00ddd62 Mon Sep 17 00:00:00 2001 From: cflmy Date: Fri, 28 Aug 2026 17:26:16 +0800 Subject: [PATCH] feat(agent): A3 context budget and progressive READ disclose Budget source/skill in step prompts with truncation markers; allow READ:source|skill deepen; parent READ:skill. Co-authored-by: Cursor --- CHANGELOG.md | 1 + doc/design/ext-agent-parent.md | 3 + doc/roadmap/ext-agent-optimize.md | 4 +- ext/ai/agent.mq.md | 109 ++++++++++++++++--- tests/ext/agent-context-budget-a3.mq.md | 138 ++++++++++++++++++++++++ tests/gold.rs | 14 +++ 6 files changed, 250 insertions(+), 19 deletions(-) create mode 100644 tests/ext/agent-context-budget-a3.mq.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fb34ae..6670402 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased ### Added +- **`ext/agent` A3(上下文预算)**: `source_brief` / 加深版 `skill_brief`;`build_step_context` 默认截断并提示 `READ:source|skill`;`step` 支持最多 `max_reads` 次加深;父 `READ:skill`。金样 `agent-context-budget-a3`。 - **`ext/agent` A2(过程可见)**: `plan` 过程事件默认写入返回 map 的 `events`(SSE 仍仅 `stream=True`);OKF 命中记 `REUSE` decision;view plan 卡渲染过程时间线。对齐 [agent-streaming.md](doc/roadmap/agent-streaming.md)。 - **`ext/agent` A1(OKF 复用飞轮)**: `agent_kb_list_tasks` 返回 description/aliases/status/llm_free/hits;`plan` 命中路径暴露 `match`/`score`(summary 含 match kind);soft_match 策展提示带 status/llm_free/description;view plan 卡显示 match。金样 `agent-kb-plan-hit`。路线 [ext-agent-optimize.md](doc/roadmap/ext-agent-optimize.md)。 - **`ext/web` 样式装配(`web_style` / `网页.样式装配`)**: 样式即数据表格 —— GFM 样式表(`|选择器|属性|值|`,可用 `|媒体|` 列分组进 `@media` 块)经 `样式装配` 函数转成 CSS 文本,再拼装成完整主题。替代"整段手写 CSS 字符串"的写法,贯彻 文档即代码。见 [marqdo-blog](examples/marqdo-blog/styles/theme.mq.md)。 diff --git a/doc/design/ext-agent-parent.md b/doc/design/ext-agent-parent.md index de1f17f..e994c9a 100644 --- a/doc/design/ext-agent-parent.md +++ b/doc/design/ext-agent-parent.md @@ -82,8 +82,11 @@ | `stderr_tail` / `stdout_tail` | 子任务捕获尾部 ~2KiB | `READ:stderr` / `READ:stdout` | | `value` | ≤200 字;否则 `value_preview` + `value_len` | (一般不必加深) | | `slots` | `{key,line,body_len}`;`error` 槽可带短预览 | `READ:slots` | +| `skill_brief`(父 / 子) | ~1.2KiB(`skill_brief`) | `READ:skill` → ~4KiB | | `has_worker_step` / `solidify_on_done` | 布尔提示 | — | +`## step` 同样默认注入 **预算后的** `source_brief` + `skill_brief`(非全文);截断处带 `[truncated …; emit READ:…]` 标记,子轮最多 `max_reads` 次加深后再 CALL/作答。 + `quiet=True` **只表示不污染父 TTY**;file `wait` 仍返回截断后的 `stdout` / `stderr` 供父观察。 --- diff --git a/doc/roadmap/ext-agent-optimize.md b/doc/roadmap/ext-agent-optimize.md index 7ace0c8..25853d8 100644 --- a/doc/roadmap/ext-agent-optimize.md +++ b/doc/roadmap/ext-agent-optimize.md @@ -2,7 +2,7 @@ | | | |---|---| -| 状态 | **进行中 · A0–A2 完成**(A2:过程事件默认落盘;view plan 过程卡) | +| 状态 | **进行中 · A0–A3 完成**(A3:step/plan 源码·Skill 预算 + READ 渐进披露) | | 日期 | 2026-08-28 | | 调研 | [agent-frameworks-and-marqdo.md](../research/agent-frameworks-and-marqdo.md) | | 设计 | [ext-agent.md](../design/ext-agent.md) · [ext-agent-plan.md](../design/ext-agent-plan.md) · [ext-agent-parent.md](../design/ext-agent-parent.md) · [okf.md](../design/okf.md) | @@ -27,7 +27,7 @@ | **A0** | 工作簿补丁 / 固化可靠性 | **done** — 整文件 FIND 护栏;`soft` 仅 miss;decompose `n` 检查;`workbook_solidify` 单测;金样 `agent-workbook-patch-a0`(双 CONTINUE + solidify) | | **A1** | OKF 复用飞轮(lookup / near / soft_match UX) | **done** — `list_tasks` 含 description/aliases/status/llm_free/hits;`plan` 命中路径暴露 `match`/`score`;soft_match 策展行含 meta;view plan 卡显示 match;金样 `agent-kb-plan-hit`(exact hit + near soft-hit) | | **A2** | 过程可见(stream + view 过程卡) | **done** — `plan_append_*` / `plan_finish_stream` 始终写入 `events`(SSE 仍仅 `stream=True`);OKF REUSE 记 `decision`;view `plan-card` 渲染过程时间线(跳过 delta);金样断言 `events-ok`;对齐 [agent-streaming.md](agent-streaming.md) | -| **A3** | 上下文预算(源码/Skill 渐进披露) | 长 runbook 不爆窗,仍保持「源码即提示」 | +| **A3** | 上下文预算(源码/Skill 渐进披露) | **done** — `source_brief` / 加深 `skill_brief`;`build_step_context` 默认预算 + `READ:source|skill`;`step max_reads`;父 `READ:skill`;金样 `agent-context-budget-a3` | | **A4** | 可选:RAG/MCP 工具适配器 | 金样调用外置检索,权威仍是 `.mq.md` | 细节与行业对照以调研正文为准;本文件只跟踪实现分期。 diff --git a/ext/ai/agent.mq.md b/ext/ai/agent.mq.md index a907531..43da5c7 100644 --- a/ext/ai/agent.mq.md +++ b/ext/ai/agent.mq.md @@ -14,8 +14,11 @@ import plugin:lib/plugin.mq.md ## build_step_context + `agent` + `task` + + `source_depth`=default + + `skill_depth`=default -Assemble a readable prompt: standing, task, tools, call site, source, skill, and the act protocol (human-visible). +Assemble a readable prompt: standing, task, tools, call site, **budgeted** source + skill, and the act protocol. +Default budgets keep long runbooks from exploding the window; emit `READ:source` / `READ:skill` (Chinese `读取:`) to deepen, then answer or `CALL:`. *standing = > json.get value=`agent` key="standing"* 1. `standing` @@ -25,13 +28,13 @@ Assemble a readable prompt: standing, task, tools, call site, source, skill, and *tools = > json.get value=`agent` key="tools"* *tools_s = > agent_format_tools tools=`tools`* -*src = > agent_module_source* +*src = > source_brief depth=`source_depth`* *site = > agent_call_site* *site_s = > json.stringify value=`site`* -*skill = > agent_marqdo_skill* +*skill = > skill_brief depth=`skill_depth`* *task_s = > json.stringify value=`task`* -*esc = > json.parse text={"a":"\n\n--- standing ---\n","b":"\n\n--- task ---\n","c":"\n\n--- tools ---\n","d":"\n\n--- call site ---\n","e":"\n\n--- source (.mq.md) ---\n","f":"\n\n--- marqdo skill ---\n","g":"\n\n--- how to act ---\nCall ONLY names listed under --- tools --- (whitelist). If that section is empty or says none, do NOT emit CALL / 调用 — reply with the final answer only.\nNever CALL internal framework helpers (build_step_context, plan, inspect_workbook, etc.).\nWhen calling an allowed tool, reply with exactly one line: CALL:\n(Chinese ok: 调用:)\nOtherwise reply with the final answer only.\nTools run via Marqdo subtask (spawn fn / wait).\n"}* +*esc = > json.parse text={"a":"\n\n--- standing ---\n","b":"\n\n--- task ---\n","c":"\n\n--- tools ---\n","d":"\n\n--- call site ---\n","e":"\n\n--- source (.mq.md) ---\n","f":"\n\n--- marqdo skill ---\n","g":"\n\n--- how to act ---\nCall ONLY names listed under --- tools --- (whitelist). If that section is empty or says none, do NOT emit CALL / 调用 — reply with the final answer only.\nNever CALL internal framework helpers (build_step_context, plan, inspect_workbook, etc.).\nContext is budgeted: if you see a [truncated …] marker, you may first emit exactly one line READ:source or READ:skill (Chinese: 读取:source|skill) to deepen, then you will be re-prompted.\nWhen calling an allowed tool, reply with exactly one line: CALL:\n(Chinese ok: 调用:)\nOtherwise reply with the final answer only.\nTools run via Marqdo subtask (spawn fn / wait).\n"}* *a = > json.get value=`esc` key="a"* *b = > json.get value=`esc` key="b"* *c = > json.get value=`esc` key="c"* @@ -490,16 +493,58 @@ Write a scratch tool workbook under `.marqdo/agent-runs/tools/.mq.md`. ## skill_brief + `max_chars`=1200 + + `depth`=default +Budgeted marqdo skill text for prompts. `depth=deep` raises the char budget. + +1. `depth` == deep + *budget = 4000* +2. * + *budget = max_chars* *skill = > agent_marqdo_skill* -**> text_head_lines text=`skill` max_lines=40 max_chars=`max_chars`** +*full = > len value=`skill`* +*ex = > text_head_lines text=`skill` max_lines=80 max_chars=`budget`* +*used = > len value=`ex`* +1. `used` < `full` + *esc = > json.parse text={"a":"\n…[truncated skill_len=","b":" budget_chars=","c":"; emit READ:skill to deepen]"}* + *a = > json.get value=`esc` key="a"* + *b = > json.get value=`esc` key="b"* + *c = > json.get value=`esc` key="c"* + **ex + a + full + b + budget + c** +2. * + **ex** + +--- + +## source_brief + + `depth`=default + +Budgeted current-module `.mq.md` source for `step` prompts. Default ~80 lines / 4KiB; `depth=deep` ~200 / 12KiB. + +*src = > agent_module_source* +*full = > len value=`src`* +1. `depth` == deep + *ex = > workbook_source_excerpt source=`src` max_lines=200 max_chars=12000* + *budget = 12000* +2. * + *ex = > workbook_source_excerpt source=`src` max_lines=80 max_chars=4000* + *budget = 4000* +*used = > len value=`ex`* +1. `used` < `full` + *esc = > json.parse text={"a":"\n…[truncated source_len=","b":" budget_chars=","c":"; emit READ:source to deepen]"}* + *a = > json.get value=`esc` key="a"* + *b = > json.get value=`esc` key="b"* + *c = > json.get value=`esc` key="c"* + **ex + a + full + b + budget + c** +2. * + **ex** --- ## extract_plan_read + `reply` -Parse READ:source|stderr|stdout|slots (Chinese: 读取:…). +Parse READ:source|stderr|stdout|slots|skill (Chinese: 读取:…). *esc = > json.parse text={"nl":"\n","fw":":"}* *nl = > json.get value=`esc` key="nl"* @@ -683,7 +728,11 @@ Parent Plan-and-Move tools (helpers + whitelist `CALL:lib…`). *slots = > json.get value=`obs` key="slots"* *obs = > json.set map=`obs` key="slots_detail" value=`slots`* *obs = > json.set map=`obs` key="read_slots" value=True* -5. * +5. `kind` == skill + *brief = > skill_brief depth="deep"* + *obs = > json.set map=`obs` key="skill_brief" value=`brief`* + *obs = > json.set map=`obs` key="read_skill" value=True* +6. * *_ = 1* **obs** @@ -1056,11 +1105,15 @@ Parent Plan-and-Move prompt. Short protocol only — no long monologues. 2. * *up = None* -*skill = > skill_brief* +*skill_from_obs = > json.get value=`observation` key="skill_brief"* +1. `skill_from_obs` + *skill = skill_from_obs* +2. * + *skill = > skill_brief* *compact = > compact_plan_observation observation=`observation`* *obs_s = > json.stringify value=`compact`* *goal_s = > json.stringify value=`goal`* -*esc = > json.parse text={"a":"\n\n--- standing ---\n","b":"\n\n--- goal ---\n","c":"\n\n--- observation ---\n","d":"\n\n--- skill brief ---\n","tools":"\n\n--- parent tools ---\nCALL:workbook_read | workbook_excerpt | lib_catalog | scratch_tool_write\nCALL:lib.fs.read_text|exists|list_dir | lib.json.parse|stringify | lib.sys.cwd (+ ARGS:{json})\nREAD:source | stderr | stdout | slots\nCreate tools: CONTINUE PATCH add ##, or CALL:scratch_tool_write with NAME line and fenced body.\n","e_rev":"\n\n--- how to act ---\nPlan-and-Move parent. Reply with ONE protocol only (no long reasoning). Exactly one DECISION line.\n1) exit_code=0 and has_value → DECISION: DONE + one-line SUMMARY. solidify_on_done. Do not CONTINUE just because has_worker_step.\n2) Need more evidence → READ:kind or CALL:tool (then you will be re-prompted).\n3) Failure / wrong value → DECISION: CONTINUE + short PATCH (<20 lines). Never paste user prose into REPLACE.\n4) Do NOT CONTINUE only to rewrite frontmatter imports; skeleton already uses import llm:/agent:/json:….\nPATCH must use triple-angle blocks only:\n<<<\nFIND\n\n===\nREPLACE\n\n>>>\nDo not use \u0060\u0060\u0060find, \u0060\u0060\u0060replace, or *** Begin Patch ***.\nProtocols:\nCALL:name\nREAD:kind\nDECISION: DONE\nSUMMARY: one line\nDECISION: CONTINUE\n","e_dec":"\n\n--- how to act ---\nPRE-RUN decompose. Reply with ONE protocol only (no long reasoning). Exactly one DECISION line.\n1) Skeleton OK → DECISION: RUN (preferred). Do not rewrite imports; they are already import llm:/agent:/….\n2) Need evidence → READ:source or CALL:workbook_read / lib_catalog.\n3) Reshape body/logic only → DECISION: CONTINUE + short PATCH (<20 lines).\n4) Fixed answer without LLM → PATCH to return, then RUN or DONE.\nPATCH must use <<< FIND === REPLACE >>> only (no \u0060\u0060\u0060find / Begin Patch).\nProtocols:\nCALL:name\nREAD:kind\nDECISION: RUN\nDECISION: DONE\nSUMMARY: one line\nDECISION: CONTINUE\n","f":"\n\n--- explore ---\n"}* +*esc = > json.parse text={"a":"\n\n--- standing ---\n","b":"\n\n--- goal ---\n","c":"\n\n--- observation ---\n","d":"\n\n--- skill brief ---\n","tools":"\n\n--- parent tools ---\nCALL:workbook_read | workbook_excerpt | lib_catalog | scratch_tool_write\nCALL:lib.fs.read_text|exists|list_dir | lib.json.parse|stringify | lib.sys.cwd (+ ARGS:{json})\nREAD:source | stderr | stdout | slots | skill\nCreate tools: CONTINUE PATCH add ##, or CALL:scratch_tool_write with NAME line and fenced body.\n","e_rev":"\n\n--- how to act ---\nPlan-and-Move parent. Reply with ONE protocol only (no long reasoning). Exactly one DECISION line.\n1) exit_code=0 and has_value → DECISION: DONE + one-line SUMMARY. solidify_on_done. Do not CONTINUE just because has_worker_step.\n2) Need more evidence → READ:kind or CALL:tool (then you will be re-prompted).\n3) Failure / wrong value → DECISION: CONTINUE + short PATCH (<20 lines). Never paste user prose into REPLACE.\n4) Do NOT CONTINUE only to rewrite frontmatter imports; skeleton already uses import llm:/agent:/json:….\nPATCH must use triple-angle blocks only:\n<<<\nFIND\n\n===\nREPLACE\n\n>>>\nDo not use \u0060\u0060\u0060find, \u0060\u0060\u0060replace, or *** Begin Patch ***.\nProtocols:\nCALL:name\nREAD:kind\nDECISION: DONE\nSUMMARY: one line\nDECISION: CONTINUE\n","e_dec":"\n\n--- how to act ---\nPRE-RUN decompose. Reply with ONE protocol only (no long reasoning). Exactly one DECISION line.\n1) Skeleton OK → DECISION: RUN (preferred). Do not rewrite imports; they are already import llm:/agent:/….\n2) Need evidence → READ:source or READ:skill or CALL:workbook_read / lib_catalog.\n3) Reshape body/logic only → DECISION: CONTINUE + short PATCH (<20 lines).\n4) Fixed answer without LLM → PATCH to return, then RUN or DONE.\nPATCH must use <<< FIND === REPLACE >>> only (no \u0060\u0060\u0060find / Begin Patch).\nProtocols:\nCALL:name\nREAD:kind\nDECISION: RUN\nDECISION: DONE\nSUMMARY: one line\nDECISION: CONTINUE\n","f":"\n\n--- explore ---\n"}* *a = > json.get value=`esc` key="a"* *b = > json.get value=`esc` key="b"* *c = > json.get value=`esc` key="c"* @@ -1356,12 +1409,12 @@ Clear the plugin session bag for this agent id. + `writeback`=True + `stream`=False + `echo`=False + + `max_reads`=2 -One atomic turn: context → LLM → optional tool via subtask. Returns a **map** (`status`, `task`, `decision`, and on success `result` plus optional `tool` / `tool_result`; on failure `error`). By default (`writeback=True`) persists that map under named slots `ok` / `error` at the call site; pass `writeback=False` to skip. +One atomic turn: budgeted context → LLM → optional `READ:` deepen → optional tool via subtask. Returns a **map** (`status`, `task`, `decision`, and on success `result` plus optional `tool` / `tool_result`; on failure `error`). By default (`writeback=True`) persists that map under named slots `ok` / `error` at the call site; pass `writeback=False` to skip. -With `stream=True`, the model call uses SSE; `echo=True` prints delta text to stdout as it arrives. The returned map is unchanged (final `result` string). +With `stream=True`, the model call uses SSE; `echo=True` prints delta text to stdout as it arrives. The returned map is unchanged (final `result` string). Context source/skill start at default budget; up to `max_reads` of `READ:source` / `READ:skill` deepen before CALL/answer. -*ctx = > build_step_context agent=`self` task=`task`* *id = > json.get value=`self` key="id"* *model = > json.get value=`self` key="model"* *tools = > json.get value=`self` key="tools"* @@ -1370,11 +1423,33 @@ With `stream=True`, the model call uses SSE; `echo=True` prints delta text to st *user_turn = > json.set map=`user_turn` key="content" value=`task`* > agent_history_append id=`id` item=`user_turn` -1. `stream` - *evs = > model.complete prompt=`ctx` stream=True echo=`echo`* - *reply = > llm.stream_result events=`evs`* -2. * - *reply = > model.complete prompt=`ctx`* +*source_depth = "default"* +*skill_depth = "default"* +*reads_left = max_reads* +*reply = None* +*decision = None* + +- `reads_left` > 0 + 1. `decision` + *reads_left = 0* + 2. * + *ctx = > build_step_context agent=`self` task=`task` source_depth=`source_depth` skill_depth=`skill_depth`* + 1. `stream` + *evs = > model.complete prompt=`ctx` stream=True echo=`echo`* + *reply = > llm.stream_result events=`evs`* + 2. * + *reply = > model.complete prompt=`ctx`* + *reply = > trim value=`reply`* + *rk = > extract_plan_read reply=`reply`* + 1. `rk` == source + *source_depth = "deep"* + *reads_left = reads_left - 1* + 2. `rk` == skill + *skill_depth = "deep"* + *reads_left = reads_left - 1* + 3. * + *decision = reply* + *reads_left = 0* *reply = > trim value=`reply`* *decision = reply* diff --git a/tests/ext/agent-context-budget-a3.mq.md b/tests/ext/agent-context-budget-a3.mq.md new file mode 100644 index 0000000..b72d809 --- /dev/null +++ b/tests/ext/agent-context-budget-a3.mq.md @@ -0,0 +1,138 @@ +--- +title: agent context budget + progressive disclose (A3 offline) +description: source/skill briefs truncate with markers; READ:skill deepen; step protocol mentions READ. +import llm:ext/ai/llm.mq.md +import agent:ext/ai/agent.mq.md +import json:lib/json.mq.md +import plugin:lib/plugin.mq.md +import sys:lib/sys.mq.md +--- + +A3 padding block so this module source exceeds the default 4KiB budget when injected into step context. Keep as plain prose (not HTML comments) so strip_html_comments leaves it in place. + +PAD_START +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +PAD_END + +# main + +*p = > plugin.native_path name="agent"* +1. `p` + > plugin.load path=`p` +2. * + > print text=no-agent-plugin + > sys.exit code=1 + +> sys.env_set name="OPENAI_API_KEY" value="offline-a3-dummy" +*model = > llm.llm* +*tools = > json.parse text=[]* +*助手 = > agent.agent model=`model` tools=`tools` standing="a3 budget"* + +*brief = > agent.source_brief depth="default"* +*has = > split value=`brief` sep="truncated source_len="* +*hn = > len value=`has`* +1. `hn` > 1 + > print text=source-trunc +2. * + > print text=source-full + +*deep = > agent.source_brief depth="deep"* +*dhas = > split value=`deep` sep="truncated source_len="* +*dn = > len value=`dhas`* +1. `dn` > 1 + > print text=deep-still-trunc +2. * + > print text=deep-wider + +*sk = > agent.skill_brief depth="default"* +1. `sk` + > print text=skill-ok +2. * + > print text=skill-missing + +*rk = > agent.extract_plan_read reply="READ:skill"* +1. `rk` == skill + > print text=read-skill-parse +2. * + > print text=read-skill-bad + +*obs = > json.parse text={}* +*obs2 = > agent.plan_read_deepen observation=`obs` kind="skill" path="."* +*flag = > json.get value=`obs2` key="read_skill"* +1. `flag` + > print text=read-skill-ok +2. * + > print text=read-skill-miss + +*ctx = > agent.build_step_context agent=`助手` task="probe" source_depth="default" skill_depth="default"* +*c1 = > split value=`ctx` sep="truncated source_len="* +*cn = > len value=`c1`* +1. `cn` > 1 + > print text=ctx-trunc +2. * + > print text=ctx-no-trunc +*c2 = > split value=`ctx` sep="READ:source"* +*cn2 = > len value=`c2`* +1. `cn2` > 1 + > print text=ctx-protocol +2. * + > print text=ctx-no-protocol diff --git a/tests/gold.rs b/tests/gold.rs index 195ce79..455689e 100644 --- a/tests/gold.rs +++ b/tests/gold.rs @@ -2744,6 +2744,20 @@ fn ext_agent_kb_plan_hit() { ); } +#[test] +fn ext_agent_context_budget_a3() { + let status = Command::new("cargo") + .args(["build", "-p", "marqdo_plugin_agent"]) + .current_dir(env!("CARGO_MANIFEST_DIR")) + .status() + .expect("build agent plugin"); + assert!(status.success(), "failed to build marqdo_plugin_agent"); + assert_out( + "tests/ext/agent-context-budget-a3.mq.md", + "source-trunc\ndeep-still-trunc\nskill-ok\nread-skill-parse\nread-skill-ok\nctx-trunc\nctx-protocol", + ); +} + #[test] fn ext_agent_plan_observe() { assert_out(