Tool contract
The loop works against this interface:- a name from the map key
- a description from
Description() - a flat object schema built from
Arguments()
Fastest path: loop.NewSimpleTool
For simple tools, use the helper:
Example: custom tool type
Use a concrete type when you need dependencies:How argument schemas work
ToolArgument only contains Name and Type. The loop converts that into a flat JSON schema:
- no per-field descriptions
- no nested object schemas
- no optional arguments
How tool results flow back
When the model emits a tool call:loop.RunLoopparses the JSON argument string.- It emits a
tool_call_startchunk. - It executes
tool.Call(args). - It appends the returned string as a
toolmessage. - It makes another streamed chat completion request.
What the built-in tools show about the design
The bundled tools intools/ are intentionally simple:
read_filelist_fileswrite_filerun_commandweb_fetch