Repository navigation
feat(cognition): deliberation agent loop — speaks→acts, tested + refined - #1665
Merged
Merged
Conversation
… (dormant) The LlmDeliberationFaculty can now ACT, not just speak: with an authorized tool set (NativeToolSpec) + an injected ToolExecutor, contribute() runs the agent loop — generate → if finish_reason=ToolUse, execute_native_batch the structured tool_calls → thread the ToolResults back as ContentPart::ToolResult → re-generate → until a final text Decision (bounded by max_tool_iterations; a turn is bounded work, not an open agent). Structured ContentPart contract, NOT text-parsing (per PERSONA-COGNITION-PIPELINE.md). ToolExecutor is injected (trait) — TS-IPC impl in prod, mock in tests; the loop is impl-agnostic. DORMANT + SAFE: backward-compatible — with no tools/executor (the current build_workspace_cycle default) the loop runs exactly once with tools:None and returns the same verdict as before. The existing deliberates_through_a_real_adapter test passes unchanged through the new loop (speak-only path regression-validated). The acting branch cannot fire in production until a persona is wired with tools + an executor. FOLLOW-UP (the activation slice, gated): (1) supervisor wires the persona's authorized NativeToolSpec set + a concrete ToolExecutor (TsIpcToolExecutor) into build_workspace_cycle; (2) the acting-path behavioral test (scripted adapter returning tool_use→text + a mock executor, asserting the loop executes + threads + decides); (3) thread the real session/context ids into tool_context() (nil today). Co-Authored-By: Claude Opus 4.8 <[email protected]>
…gance pass Activates task #15: the speaks→ACTS path now has end-to-end behavioral coverage with deterministic doubles, and the loop itself is refined. Tests (llm_deliberation_faculty): - persona_acts_then_speaks_threading_tool_results — model requests a tool → executor runs it → result threaded back → model re-generates → its post-tool text is the Speak verdict. Asserts the right tool ran, the loop re-generated (2 model calls), and the re-prompt carried the tool RESULT back (the agent transcript). The case that proves a persona can act on what its tools returned, not just speak. - tools_without_executor_stay_speak_only — the can_act gate: tools authorized but no executor → tools inert, single generate, no tool round. Backward-compat guard. Test doubles are LEAN thanks to the AIProviderAdapter default impls (#1667): ScriptedAdapter is 4 methods (canned response sequence + records requests); RecordingExecutor records the calls it ran. That boilerplate was the exact friction that made this test heavy enough to defer. Elegance pass on the loop (Joel: "elegant structs, good generics, adaptability"): - Extracted try_tool_round() — owns the whole can_act gate (authorized tools AND executor AND a non-empty tool-use response), runs the batch, threads the agent transcript, returns whether to re-generate. The loop body is now generate → maybe act → re-generate, bounded. - Extracted verdict() — text → Contribution in one place. - Added ChatMessage::assistant_tool_use(&[ToolCall]) and ChatMessage::tool_results(&[ToolResult]) — the two agent-transcript turn shapes the loop built inline now live as reusable constructors on ChatMessage (one place per concern; any future agent loop reuses them). Co-Authored-By: Claude Opus 4.8 <[email protected]>
joelteply
force-pushed
the
feat/deliberation-acts
branch
from
June 17, 2026 21:10
226b857 to
33151ba
Compare
… cut off Adversarial review (PR #1665) caught a no-fallbacks-doctrine violation: when the model hit the tool-iteration cap (or had no executor) and returned finish_reason=ToolUse with EMPTY text, the loop fell through to verdict("") → decision_from_response("") → Decision::Pass — silently turning a model cut off mid-reasoning into "chose silence (PASS)". Silence must be the model's choice, never a substrate artifact (same rule the inference-failure branch already honors by returning None). Fix: when the model still wanted to act but we're not acting AND it left no verdict text, abstain (return None) + warn at the cap boundary (OBSERVABILITY-AS-SUBSTRATE: hitting the ceiling is a load-bearing decision). Non-empty text is still honored — a model that says "PASS" alongside a tool call expressed a real verdict (tools_without_executor_stay_speak_only stays green). Regression test added: tool_want_with_empty_text_and_no_executor_abstains. All 5 deliberation tests pass. Co-Authored-By: Claude Opus 4.8 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The deliberation faculty gains the speaks→ACTS capability: when a persona has authorized tools + an executor, the model can emit tool_calls, the loop runs them, threads the results back, and re-generates — so the persona reasons over what its tools returned before it speaks. Structured
ContentPartcontract, never text-parsing.Still opt-in: a persona with no tools/executor is byte-for-byte the old speak-only path. Wiring a concrete
TsIpcToolExecutorintobuild_workspace_cycle(the live path) is the follow-up half of task #15.The loop
contribute()is now: generate →try_tool_round(maybe act) → re-generate, bounded bymax_tool_iterations. A turn is bounded work, not an open-ended agent.try_tool_round()owns the entirecan_actgate (authorized tools and an executor and a non-empty tool-use response), runs the batch, threads the agent transcript, and returns whether to re-generate. A tool batch that errors falls through to a text decision — never fabricates ([[no-fallbacks-ever]]).verdict()maps final text →Contributionin one place.ChatMessage::assistant_tool_use(&[ToolCall])+ChatMessage::tool_results(&[ToolResult])— the two agent-transcript turn shapes now live as reusable constructors onChatMessage(one place per concern; any future agent loop reuses them).Behavioral coverage (activates task #15)
persona_acts_then_speaks_threading_tool_results— the full round-trip: right tool ran, loop re-generated (2 model calls), re-prompt carried the tool result back, post-tool text is the Speak verdict.tools_without_executor_stay_speak_only— thecan_actgate: tools authorized but no executor → inert, single generate.Test doubles are lean thanks to the
AIProviderAdapterdefault impls (#1667, merged):ScriptedAdapteris 4 methods. That boilerplate was the exact friction that made this test heavy enough to defer.Test
cargo test -p continuum-core --lib --features metal,accelerate,test-fixtures cognition::llm_deliberation_faculty→ 4 passed. Clippy clean.🤖 Generated with Claude Code