Skip to content

feat(tui): loop-swap adapter — race genuinely different reasoning loops#165

Merged
0bserver07 merged 2 commits into
masterfrom
feat/tui-loop-adapter
Jul 1, 2026
Merged

feat(tui): loop-swap adapter — race genuinely different reasoning loops#165
0bserver07 merged 2 commits into
masterfrom
feat/tui-loop-adapter

Conversation

@0bserver07

Copy link
Copy Markdown
Owner

Real backend heterogeneity — swap the reasoning loop

Phase 3.3 shipped per-lane preset + posture; this closes the gap I flagged as
deferred. A lane can now run a genuinely different reasoning loop — and the
multiplexer renders it like any other lane:

chimera code --tui --models glm-5.2,glm-5.2:coding_agent:plan-execute
#                           default ReAct    PlanAndExecute (a different loop)

Loops: plan-execute, reflexion, tot (+ the postures plan/tdd from 3.3).

The adapter

Only AgentLoop emits the LoopEvents the TUI renders; the strategy loops in
chimera/core/loops/ instead expose iter_steps() -> StepResult.
chimera/assembly/loop_adapter.py bridges them:

  • runs the loop's synchronous generator in a worker thread, so its blocking
    provider calls don't stall the event loop and lanes stay concurrent;
  • translates each StepResult (assistant text / tool calls / results) into
    LoopEvents, ending with exactly one terminal result (like AgentLoop);
  • cooperative cancel at step boundaries via the agent's abort signal;
  • wraps the provider so the loops' non-streaming complete() uses a bounded
    max_tokens — glm-5.2's large default otherwise trips the SDK's "streaming
    required" guard (which AgentLoop sidesteps via async_stream).

CodingAgent.run branches to the adapter for a real loop; postures and the
default stay on AgentLoop.

Verification

  • tests/assembly/test_loop_adapter.py (7): translation, terminal result,
    cancel, error path, bounded provider. Suite 79 passed.
  • Ruff clean; mypy chimera/ green (CI-parity, 674 files).
  • Live on GLM-5.2: a ReAct lane and a plan-execute lane race one task; the
    swapped loop executes real tools, writes its file in its isolated worktree,
    and streams tool_use/tool_result/assistant into its pane.

🤖 Generated with Claude Code

0bserver07 and others added 2 commits July 1, 2026 18:52
Extends Phase 3.3 from prompt postures to real reasoning-loop heterogeneity. A
lane can now select a strategy loop — plan-execute / reflexion / tot — and the
multiplexer renders it like any other lane:

    chimera code --tui --models glm-5.2,glm-5.2:coding_agent:plan-execute

The strategy loops in chimera/core/loops/ expose iter_steps() -> StepResult, not
LoopEvents. chimera/assembly/loop_adapter.py bridges them:
- runs the loop's synchronous generator in a worker thread, so its blocking
  provider calls don't stall the event loop and lanes stay concurrent;
- translates each StepResult (assistant text / tool calls / tool results) into
  LoopEvents, ending with exactly one terminal `result` event;
- cooperative cancel at step boundaries via the agent's abort signal;
- wraps the provider so the loops' non-streaming complete() uses a bounded
  max_tokens (glm-5.2's large default otherwise trips the SDK's "streaming
  required" guard; AgentLoop sidesteps this via async_stream).

CodingAgent.run branches to the adapter when the lane's loop is a real loop;
postures (plan/tdd) and the default stay on AgentLoop. parse_lane_specs accepts
the real loops.

tests/assembly/test_loop_adapter.py (7): translation, terminal result, cancel,
error path, bounded provider. Verified live on GLM-5.2: a ReAct lane and a
plan-execute lane race one task; the swapped loop runs real tools, writes its
file, and streams into its pane. Suite 79 passed; ruff + mypy clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
spec §13.3 (loop adapter, no longer "deferred"), tracker, coding-agents-map
document racing whole loops (plan-execute / reflexion / tot).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@0bserver07 0bserver07 merged commit 9470aa2 into master Jul 1, 2026
12 checks passed
@0bserver07 0bserver07 deleted the feat/tui-loop-adapter branch July 1, 2026 22:57
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