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