agent: inject tool documentation + schemas into preamble

Models that ignore native tool schemas (via the API tools parameter)
now see full tool documentation in-context: usage docs, argument
definitions, examples, and the JSON schema.

This is appended as a '# Tool Documentation' section in the system
prompt, below the compact '# Available Tools' listing.
This commit is contained in:
Levi Neely 2026-08-03 13:07:26 +02:00
parent 7189a9fc24
commit c9c76d51c0
1 changed files with 17 additions and 1 deletions

View File

@ -139,7 +139,8 @@ func BuildRuntime(cfg *AgentConfig, srv toolsrv.Runner, cwd string, env []string
}
}
// Append compact tool surface listing (name + description).
// Append compact tool surface listing (name + description) plus
// full documentation for loaded tools (schema, args, examples).
var toolListing strings.Builder
for _, ti := range allToolInfos {
if ti.Description != "" && ti.Server == "" {
@ -149,6 +150,21 @@ func BuildRuntime(cfg *AgentConfig, srv toolsrv.Runner, cwd string, env []string
if toolListing.Len() > 0 {
preamble += "\n# Available Tools\n\n" + toolListing.String()
}
// Inject full tool prompts so models that ignore native tool schemas
// still see usage docs, arg definitions, and examples in-context.
var toolDocs strings.Builder
for _, ti := range allToolInfos {
if ti.Prompt != "" && ti.Server == "" {
toolDocs.WriteString(ti.Prompt)
toolDocs.WriteString("\n\n")
if len(ti.InputSchema) > 0 && string(ti.InputSchema) != "{}" {
fmt.Fprintf(&toolDocs, "**Schema**:\n```json\n%s\n```\n\n", ti.InputSchema)
}
}
}
if toolDocs.Len() > 0 {
preamble += "\n# Tool Documentation\n\n" + toolDocs.String()
}
// Append 9P discovery instructions for loading additional tools.
preamble += "\n## Tool discovery\n\nUse the 9P filesystem to discover and load tools dynamically:\n- **List available tools** — `ollie-9p read session/{id}/agent/{aid}/tools`\n- **Load a tool** — `echo \"toolname\" | ollie-9p write session/{id}/agent/{aid}/tools`\n- **See loaded tools** — `ollie-9p read session/{id}/agent/{aid}/tools.loaded`\n"