agent

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultModel is the Claude model used when none is specified.
	DefaultModel = anthropic.ModelClaudeSonnet4_20250514
)

Variables

This section is empty.

Functions

func BuildSystemPrompt

func BuildSystemPrompt(workDir string, registry *tool.Registry) string

BuildSystemPrompt constructs the system prompt for the agent, including environment info and available tool descriptions.

Types

type Agent

type Agent struct {
	PermResp chan PermissionResponse
	// contains filtered or unexported fields
}

Agent is the core agentic loop that sends messages to Claude, streams the response, executes tools, and loops until done.

func New

func New(client anthropic.Client, registry *tool.Registry, perms *permission.Checker, workDir string, logger *slog.Logger, model anthropic.Model, todoStore *todo.Store) *Agent

New creates a new Agent with the given client, registry, permission checker, working directory, logger, model, and todo store.

func (*Agent) ContextLimits added in v0.2.0

func (a *Agent) ContextLimits() (available, used int)

ContextLimits returns the context window limits configuration.

func (*Agent) Messages added in v0.2.0

func (a *Agent) Messages() []anthropic.MessageParam

Messages returns a copy of the conversation messages.

func (*Agent) Model added in v0.2.0

func (a *Agent) Model() string

Model returns the current model identifier.

func (*Agent) ModelDisplayName added in v0.1.1

func (a *Agent) ModelDisplayName() string

ModelDisplayName returns a human-readable name for the current model.

func (*Agent) Permissions

func (a *Agent) Permissions() *permission.Checker

Permissions returns the permission checker for this agent.

func (*Agent) SendMessage

func (a *Agent) SendMessage(ctx context.Context, userMsg string) <-chan StreamChunk

SendMessage starts the agentic loop for the given user message. It returns a channel that emits StreamChunks as the response is generated. The channel is closed when the loop completes.

func (*Agent) SetMessages added in v0.2.0

func (a *Agent) SetMessages(messages []anthropic.MessageParam)

SetMessages replaces the conversation messages with the provided slice. This is used to restore a conversation from a saved session.

func (*Agent) SetModel added in v0.2.0

func (a *Agent) SetModel(model string)

SetModel changes the model used for subsequent messages.

func (*Agent) TodoStore added in v0.3.0

func (a *Agent) TodoStore() *todo.Store

TodoStore returns the agent's todo store.

func (*Agent) TokenCount added in v0.2.0

func (a *Agent) TokenCount() int

TokenCount returns the current estimated token count for the conversation.

type ChunkType

type ChunkType int

ChunkType identifies the kind of stream chunk.

const (
	ChunkText ChunkType = iota
	ChunkToolUse
	ChunkToolResult
	ChunkPermissionRequest
	ChunkParallelProgress
	ChunkContextCompacted
	ChunkTodoUpdate
	ChunkDone
	ChunkError
)

type Conversation

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

Conversation manages the message history for an agent session.

func NewConversation

func NewConversation() *Conversation

NewConversation creates a new empty conversation.

func (*Conversation) AddAssistantMessage

func (c *Conversation) AddAssistantMessage(blocks ...anthropic.ContentBlockParamUnion)

AddAssistantMessage appends an assistant message with the given content blocks.

func (*Conversation) AddToolResult

func (c *Conversation) AddToolResult(results ...anthropic.ContentBlockParamUnion)

AddToolResult appends a user message containing tool result blocks. Each tool result is a separate content block within a single user message.

func (*Conversation) AddUserMessage

func (c *Conversation) AddUserMessage(text string)

AddUserMessage appends a user text message to the conversation.

func (*Conversation) Len

func (c *Conversation) Len() int

Len returns the number of messages in the conversation.

func (*Conversation) Messages

func (c *Conversation) Messages() []anthropic.MessageParam

Messages returns the conversation history as API-ready params.

func (*Conversation) SetMessages added in v0.2.0

func (c *Conversation) SetMessages(messages []anthropic.MessageParam)

SetMessages replaces all messages in the conversation. This is used to restore a conversation from a saved session or after compaction.

func (*Conversation) TokenCount added in v0.2.0

func (c *Conversation) TokenCount() int

TokenCount returns the estimated token count of the conversation.

type ModelOption added in v0.2.0

type ModelOption struct {
	ID          string // The model identifier string
	DisplayName string // Human-readable name
}

ModelOption represents an available model choice.

func AvailableModels added in v0.2.0

func AvailableModels() []ModelOption

AvailableModels returns the list of supported models.

type PermissionResponse

type PermissionResponse int

PermissionResponse is the user's answer to a permission request.

const (
	PermissionGranted       PermissionResponse = iota // Allow this once
	PermissionDenied                                  // Deny this once
	PermissionGrantedAlways                           // Allow always for this session
)

type StreamChunk

type StreamChunk struct {
	Type             ChunkType
	Text             string
	ToolName         string
	ToolID           string
	ToolInput        string
	Result           *tool.Result
	Err              error
	ParallelProgress *tool.ProgressUpdate     // For ChunkParallelProgress
	Usage            *Usage                   // For ChunkDone - token usage for this turn
	CompactionInfo   *ctxmgr.CompactionResult // For ChunkContextCompacted
	Todos            []todo.Todo              // For ChunkTodoUpdate
}

StreamChunk is a unit of output from the agent's streaming loop.

type Usage added in v0.2.0

type Usage struct {
	Model        string
	InputTokens  int64
	OutputTokens int64
}

Usage tracks token consumption for a single API turn.

Jump to

Keyboard shortcuts

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