Overview
The agent loop is the heart of klaw. It orchestrates the conversation between user input, LLM decisions, and tool execution, continuing until a task is complete.The Loop
Step-by-Step Flow
Stream Events
The provider returns a stream of events:| Event Type | Description |
|---|---|
text | Text chunk to stream to user |
tool_use | LLM wants to call a tool |
tool_result | Result of a tool call |
error | Error occurred |
stop | Generation complete |
Tool Execution
Timeout
Each tool has a 2-minute timeout by default:Result Formatting
Tool results are formatted for display:Error Handling
Tool errors are captured and fed back to the LLM:Conversation History
Each agent maintains conversation history:Memory Integration
Before each LLM call, workspace context is loaded:Performance Considerations
| Factor | Impact | Mitigation |
|---|---|---|
| Tool execution time | Blocks loop | Timeout, async tools |
| Large outputs | Token cost | Output truncation |
| Many tool calls | Latency | Batching where possible |
| Long history | Context limits | History pruning |

