feat(tui): loop-swap adapter — race genuinely different reasoning loops#165
Merged
Conversation
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>
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.
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 posturesplan/tddfrom 3.3).The adapter
Only
AgentLoopemits theLoopEvents the TUI renders; the strategy loops inchimera/core/loops/instead exposeiter_steps() -> StepResult.chimera/assembly/loop_adapter.pybridges them:provider calls don't stall the event loop and lanes stay concurrent;
StepResult(assistant text / tool calls / results) intoLoopEvents, ending with exactly one terminalresult(likeAgentLoop);complete()uses a boundedmax_tokens— glm-5.2's large default otherwise trips the SDK's "streamingrequired" guard (which
AgentLoopsidesteps viaasync_stream).CodingAgent.runbranches to the adapter for a real loop; postures and thedefault stay on
AgentLoop.Verification
tests/assembly/test_loop_adapter.py(7): translation, terminal result,cancel, error path, bounded provider. Suite 79 passed.
mypy chimera/green (CI-parity, 674 files).plan-executelane race one task; theswapped loop executes real tools, writes its file in its isolated worktree,
and streams
tool_use/tool_result/assistantinto its pane.🤖 Generated with Claude Code