Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

feat(core): read what the steps printed, then answer the request - #28

Merged
mkhellat merged 1 commit into
mainfrom
feat/answer-after-steps
Nov 25, 2026
Merged

mkhellat merged 1 commit into
mainfrom
feat/answer-after-steps

Conversation

@mkhellat

Copy link
Copy Markdown
Owner

The main fix for the failed release-gate retest. Codebud planned steps, ran them, and stopped: no model call ever read their output, and the history kept only planned: tool(target). It listed a directory but couldn't summarise or count it, and two turns after writing log_calc.c it guessed a Python file. Its plain replies, prompted as "a helpful coding assistant", said it was Qwen and couldn't see the project.

Change

  • Answer after the steps. After a turn's steps run, chat, run and plan --execute call the model once more, with the request and each step's tool(target), status and output, and show its answer.
  • Outputs are data, not instructions. The prompt says so, and the output lines are indented so they can't forge a step N: line or the end marker. Secrets are masked, because the backend may be remote.
  • Outputs are bounded: at most 2800 characters per step (head and tail kept) and 9000 in all, cut from the largest first.
  • The history records outcomes. Its planned: … entry becomes ran: tool(target) -> exit N; …, followed by the answer. The entry is built from each step's tool and target, never from the model's descriptions (security review M1). Outputs never enter the history.
  • Edge cases: if no step ran, there's no call; if the model is unavailable, there's no answer and no error.
  • One identity prompt (persona.py) starts every reply: Codebud, a local coding agent in this project, running allow-listed programs without a shell, never another assistant.

Measured with scripts/chat_eval.py (#26), this PR together with #27

Model Before (main at #25) After Time
qwen2.5-coder:3b 9 / 18 12 / 18 287 → 249 s
qwen2.5-coder:7b 12 / 18 17 / 18 693 → 627 s

It now says "My name is Codebud", lists and counts the directories, summarises the files, and answers "I wrote log_calc.c earlier". It no longer claims to be Qwen.

Left for the next PR (reply or plan):

  • the 3B still writes pipes, now refused rather than misrun, and should get one retry with the reason;
  • the 7B reads src/codebud/planner.py, copied from the planner's few-shot examples;
  • the 3B's plain-chat fallback still sometimes refuses.

Review and CI

  • The design is mine; a Sonnet subagent implemented it, and I reviewed it locally before pushing.
  • The prompt text, the bounding, the indentation, the masking, the history entry built only from tool and target, and that both callers answer only when a step ran were all checked against the code.
  • One placement note, not blocking: the result formatting lives in llm_stub.py and imports step_summary from core lazily; it could move into the core later.
  • The branch was rebased onto the current main (it hadn't been pushed before). The full suite passes (1870), ruff is clean, and the manual builds without warnings.
  • CI runs once on this head: it changes the core, chat and run.

The maintainer's retest showed codebud plans steps, runs them, and
stops: no model call ever read their output, and the history kept only
"planned: tool(target)".  It listed a directory but could not
summarise or count it, and two turns after writing log_calc.c it
guessed a Python file.  Its plain replies, prompted as "a helpful
coding assistant", said it was Qwen and could not see the project.

After the steps of a turn run, chat, run and plan --execute now call
the model once more with the request and each step's tool(target),
status and output, and show its answer.  The outputs are data, not
instructions (the prompt says so; they are indented, so they cannot
forge a step line or the end marker), secrets in them are masked
(the backend may be remote), and they are bounded: at most 2800
characters per step (head and tail kept) and 9000 in all, cut from the
largest first.  The history's "planned: ..." entry becomes "ran:
tool(target) -> exit N; ..." -- from each step's tool and target, never
the model's descriptions (security review M1) -- followed by the
answer; outputs never enter the history.  No step ran: no call.  The
model unavailable: no answer, no error.

Every reply now starts from one identity prompt (persona.py): Codebud,
a local coding agent in this project, running allow-listed programs
without a shell, never another assistant.

* src/codebud/persona.py: New file.
* src/codebud/llm_stub.py (call_llm_plain): Use the identity prompt.
(call_llm_answer, format_step_results, _fair_caps, _cut)
(_step_status): New.
* src/codebud/cli/steps.py (StepsOutcome.records): New field.
(run_steps): Fill it.
* src/codebud/core.py (AgentCore.answer_after_steps): New.
* src/codebud/cli/chat.py: Answer after the steps.
* src/codebud/cli/run.py (_print_answer): New; used by run and
plan --execute.
* src/Makefile.am: Install persona.py.
* tests/test_answer_after_steps.py: New file.
* tests/test_cli.py: The fake agents answer nothing.
* tests/test_rag_context.py: The plain prompt starts with the identity.
* docs/chapters/usage.texi, docs/chapters/privacy.texi: Document it.
* docs/chapters/development.texi: List the test file.
* NEWS: Mention it.
@mkhellat

Copy link
Copy Markdown
Owner Author

Review summary: correct (one non-blocking note)

One sweep, locally, before pushing.

Conditions.

  • An answer call ⇔ some step ran (status ok or failed); in chat and run ⇔ outcome.ran ∨ outcome.failed.
  • The history entry of the turn becomes ran: …, built only from each step's tool and target and its status, followed by the answer; no output ever enters the history.
  • The prompt's results are masked (when masking is on), cut to 2800 characters per step and 9000 in all (_fair_caps: small outputs kept whole, the largest cut first), and indented under each step N: line.

Verified against the code:

  • _fair_caps and _cut arithmetic;
  • the data-not-instructions marker, and that indentation prevents forging step N: or the end marker;
  • the history update replaces only this turn's planned: entry;
  • LLMUnavailable gives no answer and no error;
  • plain plan (without --execute) gets no answer.

20 new tests; the full suite passes (1870).

Measured (#26's evaluation, with #27): 3B 9 → 12/18, 7B 12 → 17/18.

Non-blocking note: format_step_results lives in llm_stub.py and imports step_summary from core lazily to avoid an import cycle; it belongs in the core and can move later.

Verdict: correct. I'll merge when CI passes.

@mkhellat

Copy link
Copy Markdown
Owner Author

Merging. CI is green on all five jobs at eedfc79, macOS included. CI on the merge is skipped: this branch was rebased onto main at aba82d2 before it was pushed, and main has not moved since. So the merged tree is exactly the one CI tested, and the merge commit carries [skip ci]. I start the docs workflow by hand for the changed manual sections. The next PR (reply or plan) builds on this one.

@mkhellat
mkhellat merged commit f74c8c1 into main Nov 25, 2026
7 checks passed
@mkhellat
mkhellat deleted the feat/answer-after-steps branch November 25, 2026 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant