Purpose
Theloop package owns the conversation cycle between the model and your tools.
Main types
ToolArgument
Tool
SimpleTool
Use NewSimpleTool(...) when a closure is enough and you do not need a custom type.
Loop
Created with:
RunLoop
RunLoop(ctx, messages, model) does the core work:
- prepends the system message
- translates tools into function schemas
- starts a streamed chat completion
- emits output chunks while streaming
- accumulates the final assistant message and any tool calls
- executes tool calls and appends tool messages
- repeats until the assistant turn finishes without tool calls
ChunkTypeEnd.
Chunk types
The loop emits these chunk types:messagereasoningerrortool_call_starttool_call_errortool_call_resultend
Important behavior details
- Every declared tool argument is marked as required.
- Tool calls are executed synchronously.
- Tool results are appended as
toolrole messages. - Unknown tools and invalid tool-call JSON become error strings fed back into the conversation.
- Reasoning chunks are currently read from
delta.Extra["reasoning"]when present.