v0.2.90 6a0d7ca

tool.go RawHistoryFolder

1// Package core implements the agent loop, tool runtime, and session
2// persistence. It is provider-agnostic: it talks to an LLM only through
3// the provider.Client interface.
4package core
5
6import (
7	"context"
8	"encoding/json"
9	"fmt"
10	"sort"
11
12	"github.com/patriceckhart/zot/packages/provider"
13)
14
15// Tool is a capability the agent can invoke.
16type Tool interface {
17	// Name is the unique tool id shown to the LLM.
18	Name() string
19	// Description is a one-line summary shown to the LLM.
20	Description() string
21	// Schema is a JSON Schema object for Execute's args.
22	Schema() json.RawMessage
23	// Execute runs the tool. progress may be called any number of times
24	// with partial textual output (for UIs); it is not sent to the LLM.
25	Execute(ctx context.Context, args json.RawMessage, progress func(string)) (ToolResult, error)
26}
27
28// ToolResult is the outcome of Tool.Execute.
29type ToolResult struct {
30	// Content is sent back to the LLM (text and/or images).
31	Content []provider.Content
32	// IsError marks this result as an error to the LLM.
33	IsError bool
34	// ActivateTools names previously deferred tools that become available
35	// after this result. Unknown names are ignored by the agent.
36	ActivateTools []string
37	// Details is arbitrary data for UIs and logs; not sent to the LLM.
38	Details any
39}
40
41// Registry is a name->Tool map.
42type Registry map[string]Tool
43
44// NewRegistry builds a Registry from a list of tools.
45func NewRegistry(tools ...Tool) Registry {
46	r := Registry{}
47	for _, t := range tools {
48		r[t.Name()] = t
49	}
50	return r
51}
52
53// Specs returns the tool definitions to advertise to the LLM.
54// Sorted by tool name so the order is stable across requests. This
55// is load-bearing for provider-side prompt caching: providers
56// prefix-match tool definitions, and Go's map iteration order is
57// randomized per call, which would otherwise bust the cache every
58// single turn.
59func (r Registry) Specs() []provider.Tool {
60	names := make([]string, 0, len(r))
61	for name := range r {
62		names = append(names, name)
63	}
64	sort.Strings(names)
65	out := make([]provider.Tool, 0, len(r))
66	for _, name := range names {
67		t := r[name]
68		deferred := false
69		if d, ok := t.(interface{ Deferred() bool }); ok {
70			deferred = d.Deferred()
71		}
72		out = append(out, provider.Tool{
73			Name:        t.Name(),
74			Description: t.Description(),
75			Schema:      t.Schema(),
76			Deferred:    deferred,
77		})
78	}
79	return out
80}
81
82// Get looks up a tool by name.
83func (r Registry) Get(name string) (Tool, error) {
84	t, ok := r[name]
85	if !ok {
86		return nil, fmt.Errorf("unknown tool %q", name)
87	}
88	return t, nil
89}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 476

↑↓ moveenter openesc close