Skip to content

feat(cognition): deliberation agent loop — speaks→acts, tested + refined - #1665

Merged
joelteply merged 3 commits into
canaryfrom
feat/deliberation-acts
Jun 20, 2026
Merged

joelteply merged 3 commits into
canaryfrom
feat/deliberation-acts

Conversation

@joelteply

@joelteply joelteply commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

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 ContentPart contract, never text-parsing.

Still opt-in: a persona with no tools/executor is byte-for-byte the old speak-only path. Wiring a concrete TsIpcToolExecutor into build_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 by max_tool_iterations. A turn is bounded work, not an open-ended agent.

  • try_tool_round() owns the entire can_act gate (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 → Contribution in one place.
  • ChatMessage::assistant_tool_use(&[ToolCall]) + ChatMessage::tool_results(&[ToolResult]) — the two agent-transcript turn shapes now live as reusable constructors on ChatMessage (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 — the can_act gate: tools authorized but no executor → inert, single generate.

Test doubles are lean thanks to the AIProviderAdapter default impls (#1667, merged): ScriptedAdapter is 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

joelteply and others added 2 commits June 17, 2026 16:09
… (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
joelteply force-pushed the feat/deliberation-acts branch from 226b857 to 33151ba Compare June 17, 2026 21:10
@joelteply joelteply changed the title feat(cognition): deliberation agent loop — the speaks→acts capability (dormant) feat(cognition): deliberation agent loop — speaks→acts, tested + refined Jun 17, 2026
@github-actions github-actions Bot added size: XL and removed size: M labels Jun 17, 2026
… 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]>
@joelteply
joelteply merged commit 1136242 into canary Jun 20, 2026
4 checks passed
@joelteply
joelteply deleted the feat/deliberation-acts branch June 20, 2026 01:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant