1package tools
2
3import (
4 "context"
5 "encoding/json"
6 "fmt"
7
8 "github.com/patriceckhart/zot/packages/core"
9 "github.com/patriceckhart/zot/packages/provider"
10)
11
12// OpenRouterServerToolCallLimit bounds the remote agent loop when zot
13// advertises OpenRouter server tools.
14const OpenRouterServerToolCallLimit = 4
15
16// ResolveToolCallLimit returns n when it is a positive int, otherwise the
17// built-in default. This lets callers resolve a config.json *int without
18// importing the agent config package.
19func ResolveToolCallLimit(n *int) int {
20 if n != nil && *n > 0 {
21 return *n
22 }
23 return OpenRouterServerToolCallLimit
24}
25
26// OpenRouterServerToolNames lists every OpenRouter server tool that zot
27// can advertise on Chat Completions. Shell, bash, apply_patch, and
28// tool_search require Responses/Messages and are omitted here.
29func OpenRouterServerToolNames() []string {
30 return []string{
31 "openrouter:web_search",
32 "openrouter:web_fetch",
33 "openrouter:advisor",
34 "openrouter:subagent",
35 "openrouter:fusion",
36 "openrouter:image_generation",
37 "openrouter:datetime",
38 "openrouter:experimental__search_models",
39 }
40}
41
42// IsOpenRouterServerTool reports whether name is an OpenRouter server tool
43// that zot may inject into the live registry.
44func IsOpenRouterServerTool(name string) bool {
45 for _, n := range OpenRouterServerToolNames() {
46 if n == name {
47 return true
48 }
49 }
50 return false
51}
52
53// OpenRouterServerTool is a stub advertised to the model so OpenRouter
54// can execute the matching server tool. The agent never runs it locally.
55type OpenRouterServerTool struct {
56 name string
57 description string
58 schema json.RawMessage
59}
60
61func (t *OpenRouterServerTool) Name() string { return t.name }
62func (t *OpenRouterServerTool) Description() string { return t.description }
63func (t *OpenRouterServerTool) Schema() json.RawMessage { return t.schema }
64
65func (t *OpenRouterServerTool) Execute(context.Context, json.RawMessage, func(string)) (core.ToolResult, error) {
66 return core.ToolResult{
67 Content: []provider.Content{provider.TextBlock{Text: fmt.Sprintf("%s is executed by OpenRouter, not locally", t.name)}},
68 IsError: true,
69 }, nil
70}
71
72// OpenRouterServerTools returns stubs for every Chat Completions-capable
73// OpenRouter server tool.
74func OpenRouterServerTools() []core.Tool {
75 return []core.Tool{
76 &OpenRouterServerTool{
77 name: "openrouter:web_search",
78 description: "Search the web for current information. Executed by OpenRouter.",
79 },
80 &OpenRouterServerTool{
81 name: "openrouter:web_fetch",
82 description: "Fetch and extract content from a URL. Executed by OpenRouter.",
83 },
84 &OpenRouterServerTool{
85 name: "openrouter:advisor",
86 description: "Consult a stronger model for guidance mid-generation. Executed by OpenRouter.",
87 schema: json.RawMessage(`{"model":"openai/gpt-4.1-mini"}`),
88 },
89 &OpenRouterServerTool{
90 name: "openrouter:subagent",
91 description: "Delegate a self-contained task to a smaller worker model. Executed by OpenRouter.",
92 schema: json.RawMessage(`{"model":"openai/gpt-4.1-mini"}`),
93 },
94 &OpenRouterServerTool{
95 name: "openrouter:fusion",
96 description: "Run a panel of models and an analyst for multi-model analysis. Executed by OpenRouter.",
97 },
98 &OpenRouterServerTool{
99 name: "openrouter:image_generation",
100 description: "Generate an image from a text prompt. Executed by OpenRouter.",
101 },
102 &OpenRouterServerTool{
103 name: "openrouter:datetime",
104 description: "Get the current date and time. Executed by OpenRouter.",
105 },
106 &OpenRouterServerTool{
107 name: "openrouter:experimental__search_models",
108 description: "Search and filter the OpenRouter model catalog. Executed by OpenRouter.",
109 schema: json.RawMessage(`{"max_results":5}`),
110 },
111 }
112}