Skip to content

fix(renderers): keep concurrent agent output in one block per agent - #85

Merged
galuszkm merged 1 commit into
mainfrom
fix/mg/ansi-renderer-parallel-agents
Sep 23, 2026
Merged

galuszkm merged 1 commit into
mainfrom
fix/mg/ansi-renderer-parallel-agents

Conversation

@galuszkm

Copy link
Copy Markdown
Member

Description

AnsiRenderer kept one set of stream fields, assuming a single writer. strands runs a turn's tool calls concurrently, so agents delegated together interleaved their events and flipped the (agent, mode) pair every few tokens - a header
per chunk, both responses shredded.

State is now per agent: one holds the terminal and streams live, the rest buffer into contiguous blocks.
On release the terminal goes to a mid-stream agent, and an agent awaiting tool results cannot take it.
Otherwise a streaming sub-agent stays invisible, or its block lands after the answer that consumes it.

Also fixes flush() resetting only _in_stream, which dropped the RESPONDING header from turn two onward in sca dev.

Known tradeoff: a delegator's TOOL USE line can print after the sub-agent block it started, printing it live would split that agent's block.

Related Issues

N/A

Type of Change

  • Bug fix

YAML / API Impact

None. No schema change, AnsiRenderer.__init__ signature unchanged, new state private. Rendering behaviour only.

Testing

  • I ran uv run just check (lint + type check)
  • I ran uv run just test for overall testing
  • I added or updated tests that prove my fix is effective or my feature works
  • I verified existing examples in examples/ still work

Checklist

  • I have read the CONTRIBUTING document
  • I have updated the documentation accordingly
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

- Track render state per agent so a neighbour's tokens cannot split a block
- Hand the terminal to a mid-stream agent so it never buffers invisibly
- Refuse the terminal to an agent with outstanding tool calls
- Reset state on flush so a reused renderer reprints headers
@galuszkm
galuszkm merged commit 5b5ff7f into main Sep 23, 2026
9 checks passed
@galuszkm
galuszkm deleted the fix/mg/ansi-renderer-parallel-agents branch September 23, 2026 22:02
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