tools

package
v0.78.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package tools is the agent's tool kit: what a tool is, what a call and a result are, the catalog with its permissions and policy, and the registry every tool package registers into from its own init. A tool reaches the run it is part of — the person, the agent, the database, the operations — through the context, never through the loop's own types, so a tool package imports this package and nothing above it.

Index

Constants

View Source
const DeferralThreshold = 40

DeferralThreshold is how many definitions go in a request before the rest wait behind tool_search: forty is what a model keeps straight.

View Source
const PictureLargest = 8 << 20

PictureLargest is the largest picture this program sends to a model.

Smaller than the twenty-five megabytes a scan will carry off a person's machine, because carrying a file and paying to look at it are different questions: a four-thousand-pixel screenshot costs several times what a thousand-pixel one does and says the same thing. Anything above this is passed over with its reason rather than spent on.

One number for the night and for the conversation on purpose. A look the person asked for costs what the night's own look costs, so a picture the night was willing to open is one the agent can open again when they ask about it, and a picture it refused is refused the same way to their face rather than silently costing more.

View Source
const ResultCharacters = 24000

ResultCharacters bounds a tool's answer as the history keeps it and as a tab's answer is cut.

Variables

View Source
var ErrLeftOpen = errors.New("the person has not answered yet; the card stays open")

ErrLeftOpen is what Run.Ask answers when the person did not answer while the turn waited: the question card stays open for them, and a late answer starts a new turn with it.

View Source
var Renamed = map[string]string{
	"domain_list": "domain", "domain_get": "domain", "domain_add": "domain",
	"domain_update": "domain", "domain_remove": "domain", "domain_dns_check": "domain",
	"alias_list": "alias", "alias_match": "alias", "alias_add": "alias",
	"alias_update": "alias", "alias_remove": "alias",
	"credential_list": "credential", "credential_create": "credential",
	"credential_update": "credential", "credential_remove": "credential",
	"queue_list": "queue", "queue_retry": "queue",
	"rule_list": "rule", "rule_add": "rule", "rule_update": "rule",
	"rule_remove": "rule", "rule_test": "rule", "rule_apply": "rule",
	"user_list": "user", "user_add": "user", "user_update": "user", "user_remove": "user",
	"calendar_agenda": "calendar", "calendar_free": "calendar", "calendar_add": "calendar",
	"calendar_edit": "calendar", "calendar_remove": "calendar",
	"mail_audit_search": "mail_audit", "mail_audit_get": "mail_audit",
	"mail_audit_content": "mail_audit", "mail_audit_mark": "mail_audit",
	"account_get": "account", "account_update": "account",
	"settings_get": "settings", "settings_update": "settings",
}

Renamed maps the names the catalog used before its tools were merged to what they are called now.

An operator's policy and a person's own "always ask me" list are written down by name (agent.tools.disabled, agent.tools.confirm, and the agent's Confirm), and those lists were written when every verb had a name of its own. A list naming domain_remove means what it meant: do not let this happen. Because the verb is an action now, the whole tool is what the name resolves to -- so a policy that switched one verb off switches its tool off. That is broader than what was asked for and never narrower, which is the direction a policy may safely be wrong in, and the release notes say so.

Functions

func ActionOf

func ActionOf(arguments json.RawMessage) string

ActionOf is the "action" of a call's arguments, lowercased, for a tool whose risk depends on it. Read from the JSON, never by looking for the word inside it: a name or a title containing "delete" is not a delete.

func ActionsOf

func ActionsOf(tool *Tool) []string

ActionsOf is the verbs a tool takes, read out of its own schema: the values of its "action" enumeration, in the order they are offered.

From the schema rather than from a field, because a tool is action-shaped whether it was merged out of several tools or written that way in the first place. The policy page listed the verbs of the merged ones and nothing beside group_manage, which takes add, update and remove of its own -- so the page looked as though the two kinds of tool differed, and they do not.

Empty for a tool that is one thing, and for one whose action is free text rather than a choice.

func AllowedByPermissions

func AllowedByPermissions(tool *Tool, permissions *models.EffectivePermissions) bool

AllowedByPermissions says whether the person holds one of the permissions a tool asks for.

func ArrayProperty

func ArrayProperty(description string, items map[string]any) map[string]any

func BooleanProperty

func BooleanProperty(description string) map[string]any

func ConversationIDOf added in v0.49.0

func ConversationIDOf(run Run) string

ConversationIDOf is the conversation a run is part of, or empty when it is part of none: the night, and a call from a harness over the protocol.

Every tool reads it through here rather than as Conversation().ID. That form dereferenced a nil conversation, and through the protocol it took down the request: the harness saw its connection dropped, with no answer and no error.

func DecodeArguments

func DecodeArguments[T any](call *Call) (T, error)

DecodeArguments reads a call's arguments, repairing what a model mangled.

func DocumentBytes

func DocumentBytes(ctx context.Context, files storage.Files, document *models.AgentDocument) ([]byte, error)

DocumentBytes is an attachment document's bytes, out of the store.

The whole reason the bytes are kept rather than fetched when they are wanted: this answers with the laptop they came from shut and the person asleep, which is when the reading happens.

func DurationWords

func DurationWords(difference time.Duration) string

func EnumProperty

func EnumProperty(description string, values ...string) map[string]any

func FeatureAllowed

func FeatureAllowed(configuration *config.Configuration, feature string) bool

FeatureAllowed says whether the deployment offers a feature at all: the agent switched on, and the feature not switched off by the operator.

func FirstWords

func FirstWords(text string, count int) string

FirstWords is the first few words of a text, with a mark where it goes on.

func HTMLToText

func HTMLToText(html string) string

HTMLToText reduces HTML to the text a person would read: block elements become line breaks, links keep their text, everything in a script or a style goes.

func In

func In(where string) string

In is " in <where>", or nothing: where a call names a mailbox or a domain the card says which, and where it does not there is only one to mean.

func IntegerProperty

func IntegerProperty(description string) map[string]any

func IsImage

func IsImage(contentType string) bool

IsImage says whether a file is a picture a model can look at.

func IsOneMoment added in v0.58.7

func IsOneMoment(expression string) bool

IsOneMoment says a schedule's line is a single moment, "@at" and a time, rather than one that repeats.

func Listed

func Listed(entries []string, tool *Tool) bool

Listed says whether a policy list names the tool, by name or family, or by a name one of its actions used to have.

func Location

func Location(user *models.User) *time.Location

Location is the zone a person's times are told in: their own, or the server's when they have none yet.

func MustJSON

func MustJSON(value any) json.RawMessage

MustJSON encodes a value the code built itself.

func Named

func Named(value, stand string) string

Named is how a card points at a thing: what the person calls it, in quotes, or a stand-in when the call gives no name.

func NeedsConfirmation

func NeedsConfirmation(tool *Tool, arguments json.RawMessage, policy *config.AgentTools, agent *models.Agent) bool

NeedsConfirmation says whether a call must wait for the person: the risk class first, then the operator's list, then the person's own. Without arguments it answers for the tool as a whole.

func NextCron

func NextCron(expression string, after time.Time, location *time.Location) (time.Time, error)

NextCron is the first moment after the given one that a cron line admits, in the zone, or zero when none is found in four years.

func NormalizeText

func NormalizeText(text string) string

NormalizeText squares the line endings, trims trailing blanks and collapses runs of blank lines.

func Object

func Object(properties map[string]any, required ...string) map[string]any

func OpenWorldRead added in v0.74.4

func OpenWorldRead() *mcp.ToolAnnotations

OpenWorldRead are the annotations of a tool that changes nothing and reaches beyond this server to read: the web, a search service.

func ParseDuration

func ParseDuration(value string) (time.Duration, error)

ParseDuration reads 3d, 2h30m, -1w and Go's own forms.

func ParseMoment

func ParseMoment(text string, location *time.Location) (time.Time, error)

ParseMoment reads a date and time the way a person writes one, in their zone unless the text carries its own offset.

func ParsePhrase

func ParsePhrase(text string, location *time.Location, now time.Time) (time.Time, error)

ParsePhrase reads the phrases people write: today, tomorrow, yesterday, next Monday, in 3 days, 3pm, and a clock time after any of them.

func ParseTime

func ParseTime(value string, location *time.Location, now time.Time) (time.Time, error)

ParseTime reads an ISO time, or a date, or a date and a time, in the given zone; empty is now.

func PermissionWords

func PermissionWords(permissions *models.EffectivePermissions) string

PermissionWords says what the person may do, in words.

func PreviewOf

func PreviewOf[T any](say func(T) string) func(json.RawMessage) string

PreviewOf builds a tool's Preview from a function of its arguments, so that a card is written as the sentence it is rather than as JSON handling. Arguments that will not decode give the tool's own words back through the fallback, because a card is shown before anything runs and must say something either way.

func Register

func Register(factory func() []*Tool)

Register adds a factory. Called from a tool package's init.

func Rename

func Rename(names []string) []string

Rename maps a list of tool names onto what those tools are called now, keeping the order and dropping the duplicates a merge creates: a policy naming rule_add and rule_remove names the rule tool once.

func ReplySubject

func ReplySubject(subject string) string

ReplySubject is the answer's subject: the original's with one Re:.

func Reset

func Reset()

Reset forgets every factory, for a test that registers its own.

func ResolveRelative

func ResolveRelative(expression string, now time.Time, location *time.Location) (string, error)

ResolveRelative turns "@in 5m" into the "@at" moment it means from now, so the schedule stores a moment and not a distance that would move with every look. Anything else is returned as it came.

func SearchMode

func SearchMode(configuration *config.Configuration, source *models.AgentMailbox) string

SearchMode says how a mailbox is searched: by meaning where it can be.

func SettledArguments

func SettledArguments(arguments json.RawMessage) json.RawMessage

SettledArguments are a call's arguments as everything that reads them must see them: repaired once, so that what a call is judged by and what it does cannot be two different things.

Arguments that are already JSON are returned untouched, which is nearly every call. Anything else is put through the same repair the tool's own decoding would have done, and what will not parse even then is given back as it came, for the tool to refuse in its own words.

func Some

func Some(values []string, limit int) string

Some is a few things named in a line, with the rest counted.

func StringProperty

func StringProperty(description string) map[string]any

func StripQuoted

func StripQuoted(text string) string

StripQuoted cuts the quoted history: everything from the first line that introduces it, and any line quoted with ">" before that.

func ThreadSubject

func ThreadSubject(subject string) string

ThreadSubject is a conversation's subject without the Re: and Fwd: its answers added.

func WithRun

func WithRun(ctx context.Context, run Run) context.Context

WithRun puts the run into the context for the tools called in it.

Types

type Action

type Action struct {
	Name string
	Tool *Tool
}

Action is one verb of a merged tool: the word the model passes as "action", and the tool it stands for.

type BackgroundHolder added in v0.57.0

type BackgroundHolder interface {
	HasBackground() bool
}

BackgroundHolder is a computer whose program keeps commands running in the background: one started that way, and one left running when its wait ran out. A program that predates them is not one.

type BackgroundOrigin added in v0.57.0

type BackgroundOrigin struct {
	AgentID        string `json:"agentId"`
	ConversationID string `json:"conversationId"`
	IsHeadless     bool   `json:"isHeadless,omitempty"`
}

BackgroundOrigin is who started a background command, as the shell tool hands it to the computer and the computer hands it back when the command ends: which agent and conversation to wake, and whether the turn that started it had anybody present. The computer keeps it without reading it.

type Browsing

type Browsing interface {
	// BrowserPage is the turn's page, opened on first use.
	BrowserPage(ctx context.Context) (*browser.Context, error)

	// AttachedTab is the person's tab, or nil.
	AttachedTab() Tab

	// TabsAllowed says whether the operator lets people attach a tab.
	TabsAllowed() bool
}

Browsing is what a run offers the browser tool: a page of its own in the operator's headless browser, and the person's own attached tab when they attached one. A run that has no browser does not implement it.

type Call

type Call struct {
	ID        string
	Arguments json.RawMessage

	// Confirmed says the person approved this call.
	Confirmed bool
}

Call is one use of a tool. The run it is part of — the person, the agent, the database, the operations — is in the context, through RunFrom, so a tool package needs nothing of the loop's own types.

type Catalog

type Catalog struct {
	// contains filtered or unexported fields
}

Catalog is every tool the server knows.

func Build

func Build() *Catalog

Build is a catalog of everything registered, in registration order.

func NewCatalog

func NewCatalog() *Catalog

NewCatalog is an empty catalog.

func (*Catalog) All

func (self *Catalog) All() []*Tool

All is every tool, in registration order.

func (*Catalog) Get

func (self *Catalog) Get(name string) *Tool

Get is a tool by name, or nil.

func (*Catalog) Offered

func (self *Catalog) Offered(permissions *models.EffectivePermissions, policy *config.AgentTools) []*Tool

Offered is the catalog as one person sees it: what their permissions admit, minus what the operator switched off.

func (*Catalog) Register

func (self *Catalog) Register(tool *Tool)

Register adds a tool; a second tool of the same name is a programming error.

type Computer

type Computer interface {
	// Ask sends a request and waits up to wait for the answer.
	Ask(ctx context.Context, action string, args any, wait time.Duration) (json.RawMessage, error)
	Name() string
	System() string
	// Home is the person's home directory there, which ~ and a relative
	// path are from.
	Home() string
	// Description is the person's sentence about what the computer is for,
	// or empty; it is how the agent tells several apart.
	Description() string
}

Computer is the attached computer as a tool reaches it: a request sent across, and the answer it gives.

type Computing

type Computing interface {
	// AttachedComputers are the person's computers, by name; none when
	// none is attached.
	AttachedComputers() []Computer

	// ComputersAllowed says whether the operator lets people attach a
	// computer.
	ComputersAllowed() bool

	// ComputersUnattended says a run with nobody present may reach one
	// anyway. It is false for almost everything: the confirmation card is
	// what stands between the agent and the grave shapes, and a run
	// nobody is watching cannot be shown one. The night is the exception
	// the owner decided on.
	ComputersUnattended() bool
}

Computing is what a run offers the shell and filesystem tools: the person's own computer, when they attached one with `teanode computer`. A run that has no such thing does not implement it.

type Family

type Family string

Family is a tool's group, which is also what the operator's policy can name to switch the whole group off.

const (
	FamilyMailbox  Family = "mailbox"
	FamilyDomains  Family = "domains"
	FamilyAudit    Family = "audit"
	FamilyPeople   Family = "people"
	FamilyServer   Family = "server"
	FamilyAccount  Family = "account"
	FamilyGeneral  Family = "general"
	FamilyServers  Family = "servers"
	FamilyBrowser  Family = "browser"
	FamilyComputer Family = "computer"
	FamilySkills   Family = "skills"
)

The families.

type GraphSearching

type GraphSearching interface {
	SearchGraphByMeaning(ctx context.Context, words string, limit int) ([]*models.AgentNode, []*models.AgentFact)
}

GraphSearching is finding a page or a fact by what it means rather than by the words it happens to use. A person asking about "the boat" means the page that says "Marigold", and no word of theirs appears in it.

As with Remembering, a run on a deployment with no embedding model does not implement it and the search is by words alone.

type Group

type Group struct {
	Name        string
	Family      Family
	Description string
	Guidance    string
	Core        bool
	Members     []Member
}

Group is a merged tool described by the names of its parts, so that a package can go on declaring its tools exactly as it does and say, in one line at the end, which of them are one tool.

type KnowledgeSearching

type KnowledgeSearching interface {
	// SearchKnowledgeByMeaning is the passages nearest the words, and
	// whether the database ranked them itself. False means the caller
	// should fall back to re-ranking.
	SearchKnowledgeByMeaning(ctx context.Context, sourceIds []string, words string, limit int) ([]*models.AgentChunk, bool)

	// RankChunksByMeaning puts a set the words found into the order the
	// meaning wants.
	RankChunksByMeaning(ctx context.Context, words string, chunks []*models.AgentChunk, limit int) []*models.AgentChunk
}

KnowledgeSearching is searching what the person pointed their agent at by meaning as well as by words.

Two methods rather than one because the two paths are genuinely different. Where the database can rank vectors it does, and the words and the meaning are separate searches fused by rank. Where it cannot, reading a few hundred thousand vectors into memory to sort them is not a search, it is a memory leak with a result -- so the words find a bounded set and the meaning re-ranks that.

type Linking added in v0.50.0

type Linking interface {
	// SharedLink is a full address that opens the file, or "" when the run
	// cannot make one; the caller keeps the plain path then.
	SharedLink(attachmentId string) string

	// IsLinkInPlaceOfPath says every file this run hands out goes by its
	// shared link, because whoever reads the answer has no session here: a
	// program over MCP. A conversation hands one out only when asked.
	IsLinkInPlaceOfPath() bool
}

Linking is a run that can hand out an address for a file which opens by itself: signed for that one file, expiring, and needing no sign-in.

The dashboard fetches a file with the person's own session, so a plain path is enough to show one there. A program using the agent tools over MCP has neither the session nor, usually, a token that works outside the tools endpoint, so a plain path was a file it could see and not fetch; one fell back to copying five megabytes through the shell in base64 chunks. And a person who asks for a link to open on their phone has no session there either: a conversation hands one out when asked.

type Member

type Member struct {
	Action string
	Tool   string
}

Member names one tool a group is made of: the word the model will pass as the action, and the name the tool is registered under today.

type MergedTool

type MergedTool struct {
	Name        string
	Family      Family
	Description string
	Guidance    string
	Core        bool
	Actions     []Action
}

MergedTool is what to build: the merged tool's own name and family, the sentence that introduces it, and its actions in the order they should be read.

type Operations

type Operations interface {
	// Execute runs one document of the API as the person and decodes the
	// data into result.
	Execute(ctx context.Context, document string, variables map[string]any, result any) error

	// Permissions is what the person may do.
	Permissions() *models.EffectivePermissions
}

Operations is the API as the person, for a tool: every call runs in its own transaction with the person's permissions, and the audit trail names the person with the agent as the actor.

type PreparedPage added in v0.48.0

type PreparedPage func(tx db.Transaction) (*models.AgentNode, error)

PreparedPage resolves a page using model input prepared before the transaction.

type Remembering

type Remembering interface {
	// NoteFact gives a fact its vector as it is written and answers the
	// facts already on the same page that are near enough in meaning to be
	// the same thing said twice, nearest first. Nothing comes back where
	// there is no embedding model, or where nothing is that near.
	//
	// Merging stays within one page on purpose. Two short sentences about
	// two different people sit closer together than either does to a long
	// one about its own subject, so "near in meaning" is only evidence of
	// a duplicate when the two are already about the same thing.
	NoteFact(ctx context.Context, fact *models.AgentFact) []*models.AgentFact

	// NoteNode gives a page its vector when its words change.
	NoteNode(ctx context.Context, node *models.AgentNode)

	// PreparePage obtains any model input before a write transaction begins.
	// The returned resolver only reads or writes through the supplied transaction.
	PreparePage(ctx context.Context, path string, kind models.AgentNodeKind, name string) PreparedPage
}

Remembering is what a run offers the memory tool beyond the store: the meaning of what is written, where the deployment has a model that can say it. A run without one does not implement it, and the tool works as it always did -- by words.

type Result

type Result struct {
	// Content is what the model reads: JSON, or plain text.
	Content string

	// Untrusted marks content that came from outside — a message, a page —
	// so the loop wraps it as data that never instructs.
	Untrusted bool

	// ShowVerbatim marks a secret the person asked to see: relayed once,
	// exactly, never kept.
	ShowVerbatim bool

	// Note is a line for the drawer, saying what was done.
	Note string

	// Images are pictures the model asked to look at, given to it as a
	// turn of its own after this round's results; not kept.
	Images []llm.ContentPart
}

Result is what a tool answers, for the model and for the person.

func JSONResult

func JSONResult(value any) (*Result, error)

JSONResult encodes a value as a tool's content.

func TextResult

func TextResult(format string, arguments ...any) *Result

TextResult is a plain-text tool answer.

type Risk

type Risk string

Risk is what a tool can cost.

const (
	RiskRead        Risk = "read"
	RiskWrite       Risk = "write"
	RiskDestructive Risk = "destructive"
	RiskOutward     Risk = "outward"
	RiskGranting    Risk = "granting"
)

The risk classes. Read changes nothing; write changes something the person can change back; destructive cannot be undone; outward leaves the server — a message sent, a request made on the person's behalf; granting hands out a way in, or changes who may do what.

Granting is its own class because it is neither of the two it kept being filed under. Minting an API token is not destructive -- nothing is lost -- and it is not outward -- nothing leaves. It was therefore an ordinary write, so an agent following instructions it read in a message could mint a token for the whole account, and the person was never asked. What a credential costs is not measured by what it changes; it is measured by what somebody holding it can do afterwards.

type Run

type Run interface {
	Owner() *models.User
	Agent() *models.Agent
	Conversation() *models.AgentConversation
	Operations() Operations
	Database() db.Database
	Configuration() *config.Configuration

	// Surface is where the person is: drawer, cli, api, mail, phone, or
	// empty for a run with nobody present.
	Surface() string
	Headless() bool

	// CanAsk says a question card may be put to the person and waited on:
	// they are there, whether or not they started the turn.
	CanAsk() bool
	ReadOnly() bool

	// Offered is every tool this run may use; Loaded is which of the
	// deferred ones tool_search has loaded; Load marks one loaded.
	Offered() []*Tool
	Loaded() map[string]bool
	Load(name string)

	// Storage is where a file the agent makes is kept.
	Storage() storage.Storage

	// Recall keeps a line a memory search found, for the <recalled>
	// overlay; Recalled is what has been kept this turn.
	Recall(line string)
	Recalled() []string

	// Ask puts a question to the person and waits for the answer.
	Ask(ctx context.Context, callId, question string, choices []string) (string, error)

	// Enqueue queues a job of the agent's, in the transaction given.
	Enqueue(tx db.Transaction, kind models.AgentJobKind, mailboxId, subjectId string) error

	// DraftReply writes a reply the way the draft pipeline does; DiscardDraft
	// removes a draft the agent holds; MeaningSearch finds messages that say
	// the same thing in other words, or nothing where search by meaning is
	// off.
	DraftReply(ctx context.Context, request *models.AgentDraftRequest) (*models.AgentDraft, error)
	DiscardDraft(ctx context.Context, tx db.Transaction, itemId string) error
	MeaningSearch(ctx context.Context, mailboxId, query string, limit int) ([]string, error)
}

Run is the turn a tool is called in, as a tool sees it: who it is for, what it may reach, and what has been loaded so far. The loop puts its run into the context with WithRun; a tool takes it out with RunFrom. What a family of tools needs beyond this — a browser, an attached tab, a question put to the person — is an interface of its own that the run may also satisfy.

func MustRun

func MustRun(ctx context.Context) Run

MustRun is the run a tool was called in, for a tool the loop calls — the loop always puts one in. A test that calls a tool directly puts one in with WithRun; a call without one is a programming error and panics with RunFrom's message.

func RunFrom

func RunFrom(ctx context.Context) (Run, error)

RunFrom is the run a tool was called in. A tool called with none is a programming error, said plainly rather than dereferenced.

type Screen

type Screen struct {
	Columns int    `json:"columns"`
	Rows    int    `json:"rows"`
	Text    string `json:"text"`
	CursorX int    `json:"cursorX"`
	CursorY int    `json:"cursorY"`
	// Changed says it differs from the last read.
	Changed bool `json:"changed"`
	// Ended says the program finished, with Code; the screen is what it left.
	Ended bool `json:"ended"`
	Code  int  `json:"code"`
}

Screen is what a terminal shows at one moment.

type SessionHolder

type SessionHolder interface {
	// StartSession runs a program and returns the session's identifier.
	// kind is "stdio" or "pty"; columns and rows size a terminal.
	StartSession(ctx context.Context, kind, command string, arguments []string,
		directory string, environment map[string]string, columns, rows int) (string, error)
	// WriteSession writes to its input.
	WriteSession(ctx context.Context, id string, data []byte) error
	// ReadScreen is a terminal's screen as it stands.
	ReadScreen(ctx context.Context, id string) (*Screen, error)
	// ResizeSession changes a terminal's size.
	ResizeSession(ctx context.Context, id string, columns, rows int) error
	// SignalSession sends int, term, kill or hup.
	SignalSession(ctx context.Context, id, signal string) error
	// CloseSession ends it.
	CloseSession(ctx context.Context, id string) error
	// AttachedTerminal is the session of a terminal the person is sitting
	// in themselves, or empty when they attached none.
	AttachedTerminal() string
}

SessionHolder is a computer that can hold a program open: a terminal the agent drives, a server spoken to over its standard input. Separate from Computer so that what only asks and answers need not pretend to.

type Tab

type Tab interface {
	Ask(ctx context.Context, action string, args any) (json.RawMessage, error)
	Title() string
	URL() string
	// HasTab says there is a tab to act in: a browser connected through
	// the extension may have none until one is opened or attached.
	HasTab() bool
}

Tab is a person's attached browser tab as the tool drives it.

type Tool

type Tool struct {
	Name        string
	Family      Family
	Description string
	Risk        Risk

	// Annotations are what the tool says about its effects in the Model
	// Context Protocol's terms, where they are given rather than read off
	// the risk: a connected server's, carried through as the server gave
	// them, and a tool that reads the open web. Nil derives them; see Hints.
	Annotations *mcp.ToolAnnotations

	// Parameters is the JSON schema of the arguments.
	Parameters map[string]any

	// Permissions are what the person must hold for the tool to be offered
	// at all: any one of them. Empty means anybody signed in.
	Permissions []models.Permission

	// Core tools are always in the request; the rest may be deferred
	// behind tool_search when the catalog is long.
	Core bool

	// Headless says a run with nobody present may use it: a remote tool
	// the operator marked read-only on a headless server.
	Headless bool

	// Guidance is put in the prompt when the tool is in the request, so a
	// person who cannot manage domains is not told how to.
	Guidance string

	// Preview says what a call would do, in a line, for the confirmation
	// card. Nil uses the tool's name and arguments.
	//
	// The card is the one moment a person decides, and it has to say what
	// will happen in the words they would use -- "Send \"Thursday?\" to
	// maria@example.net", not the call. A card that prints the arguments
	// makes the person parse JSON to decide, and the identifiers in it
	// mean nothing to them.
	Preview func(arguments json.RawMessage) string

	// PreviewIn is the same line for a tool that has to look something up
	// to say it: mail_send is handed a draft id, and what the person needs
	// to see is the subject and who it goes to. The run is in the context.
	// Set one or the other; this wins where both are set.
	PreviewIn func(ctx context.Context, arguments json.RawMessage) string

	// RiskOf, when set, says what one call would cost, for a tool whose
	// actions differ: mail_act is a write until it is delete_forever.
	RiskOf func(arguments json.RawMessage) Risk

	// JudgedCall, when set, is what one call would do, written out for a
	// fast model to judge whether it only reads or changes something on the
	// person's own machine, and so runs, or speaks for them or destroys
	// something, and so asks. Empty says there is nothing to judge.
	JudgedCall func(arguments json.RawMessage) string

	// Run does it.
	Run func(ctx context.Context, call *Call) (*Result, error)

	// Overlay, when set, is asked each round for what is true now; the run
	// is in the context.
	Overlay func(ctx context.Context) string
}

Tool is one entry of the catalog.

func Grouped

func Grouped(all []*Tool, groups ...Group) []*Tool

Grouped merges what the groups name and keeps everything else as it is.

A group naming a tool that is not there is a wiring mistake, and it panics: this runs while the catalog is being built, and a capability that quietly disappears because somebody renamed a tool is worse than a server that will not start. Every package that registers tools is imported by internal/agent/tools/all, so any test that builds the catalog finds it.

func Merge

func Merge(merged MergedTool) *Tool

Merge builds the merged tool.

Three things are carried over from the actions rather than written again.

The parameters are an "action" enumeration and the union of what the actions take; where two actions use the same field for different things, both descriptions are kept, so "for save: ..." and "for remove: ..." read as they do in the tools that were written this way by hand.

The risk is the gentlest of the actions, and RiskOf raises it for the call in hand. That is what lets a read-only run offer a tool whose other actions write: the loop keeps a tool with a RiskOf and refuses the call itself if the action turns out not to be a read. Arguments that cannot be read at all take the strictest risk any action carries, never the gentlest -- a call nobody can parse is not a call anybody should wave through.

The permissions are the union, because they decide only whether the tool is offered; each action checks its own before it runs, and says so in words the model can relay when it does not hold.

Each action's guidance and overlay are kept too, after the merged tool's own: a tool says what the prompt needs to know about it whether or not it was folded into another, and a folded rule_add lost its advice to prefer a rule over remembering to do it by hand.

func Search(deferred []*Tool, query string, limit int) []*Tool

Search is the deferred tools matching the words, for tool_search.

func Split

func Split(offered []*Tool, loaded map[string]bool, compact bool) (sent, deferred []*Tool)

Split divides the offered tools into the ones sent this round and the ones only listed: everything when the catalog is short; the core set plus whatever was loaded when it is long.

func (*Tool) Definition

func (self *Tool) Definition() llm.ToolDefinition

Definition is the tool as a model is given it.

func (*Tool) Hints added in v0.74.4

func (self *Tool) Hints() *mcp.ToolAnnotations

Hints are the tool's annotations: its own where it has them, else read off its risk, which stays the one place a built-in tool says what it does.

A read changes nothing and reaches nothing beyond what the person may see here; a write changes something here and can be undone; a destructive one cannot; an outward one speaks to the world as the person. A tool whose risk depends on the call (RiskOf) is only read-only when every call is, so it keeps the protocol's cautious defaults for whatever it may raise to.

func (*Tool) PreviewLine

func (self *Tool) PreviewLine(ctx context.Context, arguments json.RawMessage) string

PreviewLine is what the confirmation card says.

func (*Tool) RiskFor

func (self *Tool) RiskFor(arguments json.RawMessage) Risk

RiskFor is what a call would cost: the call's own class when the tool tells them apart, the tool's otherwise.

Judged from the arguments as the tool will read them, which is why they are settled first. Read strictly here and repaired there, the two disagreed about the same call: a RiskOf that cannot parse what it is given falls back to the tool's own class, and the tool then repaired the braces and did the thing. Writing the arguments sloppily was enough to turn an outward call into an ordinary write and walk past the question -- a rule that forwards every message to a stranger, an invitation to a list of them, a token, a command. The gate and the act have to read the same bytes.

Directories

Path Synopsis
Package account is the person's own account: profile, tokens, sessions, app passwords, and what their permissions let them do.
Package account is the person's own account: profile, tokens, sessions, app passwords, and what their permissions let them do.
Package agentprofile is the agent's own profile, as the person tells it in conversation: what it is called, which language it talks in, and the lines the person wants added to its standing instructions.
Package agentprofile is the agent's own profile, as the person tells it in conversation: what it is called, which language it talks in, and the lines the person wants added to its standing instructions.
Package all imports every tool package, so that importing it is importing the catalog.
Package all imports every tool package, so that importing it is importing the catalog.
Package artifact is what the agent makes for the person to open beside the conversation: a page, a drawing or a document it wrote, kept as a file of the conversation, served to its owner alone and in a sandbox.
Package artifact is what the agent makes for the person to open beside the conversation: a page, a drawing or a document it wrote, kept as a file of the conversation, served to its owner alone and in a sandbox.
Package askuser is the question to the person, for when the answer changes what happens.
Package askuser is the question to the person, for when the answer changes what happens.
Package browser is the agent's browser: a page in the operator's headless Chrome, signed in as nobody, read as a tree with [ref=N] on everything that can be acted on; or, with target tab, the person's own attached tab, with their session, while they watch.
Package browser is the agent's browser: a page in the operator's headless Chrome, signed in as nobody, read as a tree with [ref=N] on everything that can be acted on; or, with target tab, the person's own attached tab, with their session, while they watch.
Package calendar is what the agent knows about its person's diary: what they have on, when they are free, and -- asking first -- putting something in.
Package calendar is what the agent knows about its person's diary: what they have on, when they are free, and -- asking first -- putting something in.
Package coding hands a piece of work to a coding agent on the person's own computer.
Package coding hands a piece of work to a coding agent on the person's own computer.
Package computer is the person's own computer, when they attached one with `teanode computer`: a shell to run a command in, and its files to read, write, list and search, as the person, anywhere on it.
Package computer is the person's own computer, when they attached one with `teanode computer`: a shell to run a command in, and its files to read, write, list and search, as the person, anywhere on it.
Package connected is the tool for the servers that speak the Model Context Protocol: what the operator has declared, what this person has connected, and the two steps of setting one up.
Package connected is the tool for the servers that speak the Model Context Protocol: what the operator has declared, what this person has connected, and the two steps of setting one up.
Package contact is the person's address book: the people they keep.
Package contact is the person's address book: the people they keep.
Package conversation is how the agent reaches what was said before: the other conversations this person has with it, and the transcripts of the runs nobody watched.
Package conversation is how the agent reaches what was said before: the other conversations this person has with it, and the transcripts of the runs nobody watched.
Package datetime is the agent's time arithmetic: now, a conversion between zones, a duration added, the difference between two times, a phrase such as "next Tuesday 3pm" read in the person's zone.
Package datetime is the agent's time arithmetic: now, a conversion between zones, a duration added, the difference between two times, a phrase such as "next Tuesday 3pm" read in the person's zone.
Package domain is the operator's domains and their delivery: domains, addresses, sending credentials, the queue.
Package domain is the operator's domains and their delivery: domains, addresses, sending credentials, the queue.
Package folder lists and manages a mailbox's folders.
Package folder lists and manages a mailbox's folders.
Package goal is the conversation's standing instruction: the sentence the agent keeps working toward across turns of its own, and the one tool that says where it is with it.
Package goal is the conversation's standing instruction: the sentence the agent keeps working toward across turns of its own, and the one tool that says where it is with it.
Package idea is the agent's list of ideas for the person, as the agent manages it in conversation: what is on offer, one it found for them, one they took up, finished or do not want.
Package idea is the agent's list of ideas for the person, as the agent manages it in conversation: what is on offer, one it found for them, one they took up, finished or do not want.
Package knowledge is the tool for what the person pointed their agent at: their checkout, their chat archive, their notes, their wiki.
Package knowledge is the tool for what the person pointed their agent at: their checkout, their chat archive, their notes, their wiki.
Package mailact acts on messages: marks, stars, files, junks, trashes.
Package mailact acts on messages: marks, stars, files, junks, trashes.
Package mailaudit is the mail audit as tools: search, one message, its content, marks, and the reports.
Package mailaudit is the mail audit as tools: search, one message, its content, marks, and the reports.
Package mailbox is what the mailbox tools share: the person's mailboxes and folders as the API lists them, a conversation and a message's content as the tools read them.
Package mailbox is what the mailbox tools share: the person's mailboxes and folders as the API lists them, a conversation and a message's content as the tools read them.
Package mailboxsettings renames a mailbox or sets its signature.
Package mailboxsettings renames a mailbox or sets its signature.
Package mailcomposehelp writes the body of a reply for the person to use, without saving anything.
Package mailcomposehelp writes the body of a reply for the person to use, without saving anything.
Package maildraft writes a draft into Drafts for the person to send.
Package maildraft writes a draft into Drafts for the person to send.
Package mailread reads a message, or the conversation it belongs to, as text the model can weigh.
Package mailread reads a message, or the conversation it belongs to, as text the model can weigh.
Package mailsearch finds messages by words, by meaning where it exists, and by what the agent decided about them.
Package mailsearch finds messages by words, by meaning where it exists, and by what the agent decided about them.
Package mailsend sends a draft, with the person's word.
Package mailsend sends a draft, with the person's word.
Package memory is the tool the agent keeps what it knows about the person with: a graph of pages, each addressed by a path, with facts on them and links between them.
Package memory is the tool the agent keeps what it knows about the person with: a graph of pages, each addressed by a path, with facts on them and links between them.
Package memorycheck is the memory check as the agent runs it in conversation: drafting questions from what it remembers about the person, putting them one at a time, and recording what the person says.
Package memorycheck is the memory check as the agent runs it in conversation: drafting questions from what it remembers about the person, putting them one at a time, and recording what the person says.
Package note is the person's notes, as the agent keeps them for them: the ones their phone's Notes app keeps in their mailbox.
Package note is the person's notes, as the agent keeps them for them: the ones their phone's Notes app keeps in their mailbox.
Package operator is what the operator's tools share: a document run as the person with its answer as a map, and the domains the person manages as the API lists them.
Package operator is what the operator's tools share: a document run as the person with its answer as a map, and the domains the person manages as the API lists them.
Package people is the operator's people and access: accounts, groups, roles, and the audit log.
Package people is the operator's people and access: accounts, groups, roles, and the audit log.
Package reminder is the person's reminders list, as the agent keeps it for them: the list beside their calendar that their phone's Reminders app syncs.
Package reminder is the person's reminders list, as the agent keeps it for them: the list beside their calendar that their phone's Reminders app syncs.
Package replyqueue is the replies the agent holds on the person's behalf, and the <pending> overlay that lists them.
Package replyqueue is the replies the agent holds on the person's behalf, and the <pending> overlay that lists them.
Package rule is the mailbox's rules as tools: listed, added, changed, removed, tried and applied.
Package rule is the mailbox's rules as tools: listed, added, changed, removed, tried and applied.
Package schedule is the tool the agent keeps its own times with: a prompt run on a cron line, at one moment, or a distance from now, in the person's zone, with nobody present.
Package schedule is the tool the agent keeps its own times with: a prompt run on a cron line, at one moment, or a distance from now, in the person's zone, with nobody present.
Package server is the server itself: its status, its settings, an upgrade.
Package server is the server itself: its status, its settings, an upgrade.
Package share is how the agent hands the person a file: the photo on a message, a file from their computer, something already in the conversation.
Package share is how the agent hands the person a file: the photo on a message, a file from their computer, something already in the conversation.
Package subscription is the mailing lists a mailbox receives and the ways out of each.
Package subscription is the mailing lists a mailbox receives and the ways out of each.
Package todo is a conversation's task list: the agent's own, laid out when a piece of work has several steps and kept as it goes, so the agent keeps its place and the person watches its progress.
Package todo is a conversation's task list: the agent's own, laid out when a piece of work has several steps and kept as it goes, so the agent keeps its place and the person watches its progress.
Package toolsearch loads tools that are listed but not sent, when the catalog is long: the model names what it wants to do and the matching tools join the request from the next round.
Package toolsearch loads tools that are listed but not sent, when the catalog is long: the model names what it wants to do and the matching tools join the request from the next round.
Package webfetch reads a web page as text for the agent: a public one through this server, with the same guarded fetcher the rest of the server uses, or any one through a computer the person attached, on the networks that computer is on.
Package webfetch reads a web page as text for the agent: a public one through this server, with the same guarded fetcher the rest of the server uses, or any one through a computer the person attached, on the networks that computer is on.
Package websearch asks the search service the operator configured.
Package websearch asks the search service the operator configured.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL