The agent loop & events
The agent loop is the small, reusable engine that turns messages, tools, and provider streams into a flow of progress events. It’s the part that makes something an agent rather than a chat box.
What the loop does
Section titled “What the loop does”For each turn, the loop:
- takes the current system prompt, transcript, tools, and model selection;
- asks the provider to stream a response;
- emits events as text and tool calls arrive;
- collects the assistant message;
- executes any requested tools;
- appends the tool results to the transcript;
- repeats until the assistant produces no more tool calls.
That “call a tool, feed the result back, continue” cycle is what lets the model read a file, see its contents, and then decide what to edit.
What the loop does not do
Section titled “What the loop does not do”The loop knows nothing about CLI arguments, Textual widgets, session file
locations, or resource discovery. Those belong to tau_coding. Keeping them out
is what makes the loop reusable across every frontend.
Event-first design
Section titled “Event-first design”Every meaningful step is observable as an event, so print mode, Rich rendering, and the Textual TUI all share the same core. Frontends render from these provider-neutral events — never from raw provider chunks. The main event types include:
AgentStartEvent/AgentEndEvent— a run begins / endsMessageStartEvent/MessageDeltaEvent/MessageEndEvent— streamed assistant textThinkingDeltaEvent— optional streamed reasoning (hidden by default)ToolExecutionStartEvent/ToolExecutionUpdateEvent/ToolExecutionEndEvent— a tool runsQueueUpdateEvent— pending steering / follow-up promptsErrorEvent— recoverable or fatal errors
Because the contract is events, a frontend’s job is reduced to: send a prompt, consume the stream, draw what you see.
→ See Build your own frontend for the concrete API, and Architecture overview for where the loop sits.