agent

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package agent defines the interface every coding agent backend implements.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent interface {
	Caps() Caps
	// Models lists models to offer in the picker for this conversation.
	Models(conv string) []string
	// Run executes one user turn. Cancelling ctx stops it.
	Run(ctx context.Context, req Request, h Handler) (Result, error)
	// Close stops any background processes.
	Close()
}

type Block

type Block struct {
	Text     string
	Image    []byte
	MimeType string
}

Block is one piece of the user's prompt: text or an image.

func (Block) IsImage

func (b Block) IsImage() bool

type Caps

type Caps struct {
	Images      bool // accepts image blocks
	Resume      bool // can continue a previous session
	DenyMessage bool // a deny can carry the user's reason back to the agent
	Modes       []Mode
}

type Decision

type Decision struct {
	OptionID string
	Message  string
}

Decision answers a Permission. Message is the user's reason for denying, if they typed one.

type Handler

type Handler interface {
	Session(id string)
	Text(text string) // a complete block of assistant text (Markdown)
	Tool(title string, kind Kind)
	Permission(ctx context.Context, p Permission) Decision
}

Handler receives what the agent does during a turn.

type Kind

type Kind string

Kind classifies a tool call. The values match ACP's ToolKind.

const (
	KindRead    Kind = "read"
	KindEdit    Kind = "edit"
	KindDelete  Kind = "delete"
	KindMove    Kind = "move"
	KindSearch  Kind = "search"
	KindExecute Kind = "execute"
	KindThink   Kind = "think"
	KindFetch   Kind = "fetch"
	KindOther   Kind = "other"
)

type MCPServer

type MCPServer struct {
	Name    string
	URL     string
	Headers map[string]string
}

MCPServer is an HTTP MCP server the agent should connect to. pocketagent uses it to give agents a send_file tool (and, for Claude, approvals).

type Mode

type Mode string

Mode is the permission preset for a conversation.

const (
	ModeAsk   Mode = "ask"   // ask before anything not in auto_allow
	ModeEdits Mode = "edits" // file edits allowed, commands still ask
	ModePlan  Mode = "plan"  // read-only planning, if the agent supports it
	ModeYolo  Mode = "yolo"  // allow everything
)

type Option

type Option struct {
	ID    string
	Label string
	Kind  OptionKind
}

func DefaultOptions

func DefaultOptions() []Option

DefaultOptions is used when an agent does not offer its own choices.

type OptionKind

type OptionKind string
const (
	AllowOnce    OptionKind = "allow_once"
	AllowAlways  OptionKind = "allow_always"
	RejectOnce   OptionKind = "reject_once"
	RejectAlways OptionKind = "reject_always"
)

func (OptionKind) Allows

func (k OptionKind) Allows() bool

type Permission

type Permission struct {
	Tool    string // display name, e.g. "Bash"
	Key     string // "always allow" memory key; empty when the agent remembers itself
	Kind    Kind
	Title   string
	Detail  string // plain text: the command, diff or arguments
	Options []Option
}

Permission is a request to run a tool call.

type Request

type Request struct {
	Conv        string // conversation key; stable per chat/topic
	SessionID   string // resume this session if set
	Cwd         string
	Model       string
	Mode        Mode
	Prompt      []Block
	AlwaysAllow []string // tool keys the user chose "always allow" for
	MCP         *MCPServer
}

type Result

type Result struct {
	SessionID      string
	CostUSD        float64 // cost of this turn, if the agent reports it
	SessionCostUSD float64 // cumulative session cost, for agents that report that instead
	StopReason     string
	FinalText      string // the last reply, if not already sent via Handler.Text
}

Directories

Path Synopsis
Package acp drives any agent that speaks the Agent Client Protocol (Gemini CLI, Claude Code and Codex via adapters, Kiro, Goose, Copilot, OpenCode, ...).
Package acp drives any agent that speaks the Agent Client Protocol (Gemini CLI, Claude Code and Codex via adapters, Kiro, Goose, Copilot, OpenCode, ...).
Package claude runs the Claude Code CLI headless with stream-json I/O. Approvals arrive through the pocketagent MCP bridge, which Claude Code calls as its --permission-prompt-tool.
Package claude runs the Claude Code CLI headless with stream-json I/O. Approvals arrive through the pocketagent MCP bridge, which Claude Code calls as its --permission-prompt-tool.
Package command wraps any CLI that takes a prompt and prints a reply, configured as an argv template.
Package command wraps any CLI that takes a prompt and prints a reply, configured as an argv template.

Jump to

Keyboard shortcuts

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