agent

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package agent runs the conversation loop: send the history, stream the reply, execute whatever tools the model called, feed the results back, and repeat until the model ends its turn.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SystemPrompt

func SystemPrompt(now time.Time, persona, memoryIndex, skillsIndex string) string

SystemPrompt assembles tomo's identity plus whatever memory and skills indexes the caller has. Kept small on purpose: memory topics and skill bodies load on demand, not here. A non-empty persona sets a specialist worker's role on top of the shared identity.

Types

type Agent

type Agent struct {
	Provider  provider.Provider
	Model     string
	System    string
	Tools     *tool.Registry
	Gate      Gate
	MaxTokens int
	MaxTurns  int
}

Agent binds a provider, a toolset, and the loop knobs.

func (*Agent) Turn

func (a *Agent) Turn(ctx context.Context, history []provider.Message, user provider.Message, sink Sink) ([]provider.Message, error)

Turn runs one user turn to completion and returns every message it generated, the user message first, so the caller can persist them. On error the messages so far come back too, so a partial turn is not lost.

type Gate

type Gate interface {
	// Allow decides whether a call may run, blocking for approval if needed.
	// When it returns false the reason is fed back to the model as the tool
	// result, so a refusal becomes something the model can work around.
	Allow(ctx context.Context, name string, class tool.Class, input json.RawMessage) (bool, string)
	// Ingested is called after a tool ran so the gate can track taint.
	Ingested(class tool.Class, isErr bool)
}

Gate is the policy check the loop consults before and after every tool run. A nil Gate means allow everything, which is only appropriate for tests.

type Sink

type Sink interface {
	Text(s string)
	ToolStart(name string, input json.RawMessage)
	ToolEnd(name, result string, isErr bool)
}

Sink receives progress while a turn runs: text deltas as they stream and tool activity as it happens. Channels and the REPL implement this.

Jump to

Keyboard shortcuts

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