Skip to content

feat(zarvis): steer the agent mid-turn between tool steps#193

Merged
edwin-zvs merged 1 commit into
mainfrom
steer-while-running
May 24, 2026
Merged

feat(zarvis): steer the agent mid-turn between tool steps#193
edwin-zvs merged 1 commit into
mainfrom
steer-while-running

Conversation

@edwin-zvs

Copy link
Copy Markdown
Contributor

Problem

In a zarvis session, a prompt typed while a turn is running is enqueued but only consumed after the entire turn finishes — so you can't redirect the agent between tool calls while it's working on a multi-step task.

Change

At each step boundary of a turn (after that step's tool results are appended to the conversation, before the next model request), drain anything the user typed during the step and fold it in as a User message. The model then incorporates the steering on its very next step — no need to wait for the whole turn to end.

assistant(tool_calls) → tool_result(s) → user(your steering) → next model step

This is additive steering, not an interrupt — in-flight model/tool work is never aborted. Stop / Interrupt (Ctrl-C) remain the way to abort. Input typed during the silent provider stream / tool execution is back-filled into the chat history (PTY echo + Message event) exactly like the outer loop's queued-input path, so it shows up where you'd expect.

Provider-safe: injecting a user message after tool results is the standard interjection pattern; the Anthropic adapter already emits consecutive user-role messages for multi-tool turns, and OpenAI/Ollama accept user-after-tool.

Notes

  • Always-on (no flag). Steering only applies when the turn continues to another step; a turn that ends with a text-only response still hands a queued message to the next turn as before.
  • Text-only steering during a long single tool call is picked up after that tool finishes (the next step boundary); to abort the tool itself, use Interrupt.

Tests

  • New drain_steering helper + unit tests: empty → none; multi-entry → newline-joined and queue emptied; and the coalesced multi-submit case (enqueue_line combines consecutive submits, whitespace ignored).
  • Full agentd-adapter-zarvis suite (126) green; --locked workspace build clean.

🤖 Generated with Claude Code

Previously a prompt typed while a turn was running was enqueued and only
picked up after the *entire* turn finished — the user couldn't redirect the
agent between tool calls. Now, at each step boundary (after a step's tool
results are appended, before the next model request), any input the user
enqueued during the step is folded into the conversation as a user message,
so the model incorporates the new guidance on its very next step.

This is additive steering, not an interrupt: in-flight model/tool work
isn't aborted (Stop / Interrupt remain the way to abort). Input typed during
the silent provider stream / tool execution is back-filled into the chat
history (echo + Message event) just like the outer loop's queued-input path.

Adds `drain_steering` (newline-joins the queued entries, empties the queue)
with unit tests, including the coalesced-multi-submit case.
@edwin-zvs
edwin-zvs merged commit 7422f62 into main May 24, 2026
1 check passed
@edwin-zvs
edwin-zvs deleted the steer-while-running branch May 24, 2026 15:40
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