Expand description
Claude-Code-shaped streaming agent loop.
run(...) returns an async stream of SdkMessage. The loop:
- Yields
System{Init}carrying the session id. - POSTs to the configured chat-completions endpoint.
- On
finish_reason == "tool_calls": yields oneAssistantmessage with text + tool_use blocks, runs each tool through the permission gate (read-only tools in parallel, mutating tools sequentially), yields oneUsermessage containing all tool_result blocks, and continues. - On any other finish reason: yields the final
Assistanttext and aResult{Success}carrying usage, cost, and turn count. - Enforces
max_turnsandmax_budget_usd; transport errors yieldResult{ErrorDuringExecution}.
Functionsยง
- run
- Run the agent loop and stream
SdkMessages in turn order.