Versions in this module Expand all Collapse all v0 v0.2.3 Apr 3, 2026 v0.2.2 Apr 3, 2026 v0.2.1 Apr 3, 2026 v0.2.0 Apr 3, 2026 Changes in this version + var ErrBusy = errors.New("agent is busy") + var ErrInvalidState = errors.New("invalid agent state transition") + var ErrQueueFull = errors.New("agent control queue is full") + var ErrStopped = errors.New("agent is stopped") + func RegisterDriver(name string, factory DriverFactory) error + func RegisteredDrivers() []string + type Agent struct + func New(driver AgentDriver) *Agent + func (a *Agent) Abort(reason string) error + func (a *Agent) AppendConversation(msg AgentMessage) error + func (a *Agent) Continue(ctx context.Context) error + func (a *Agent) ControlQueue() *ControlQueue + func (a *Agent) ConversationLen() int + func (a *Agent) FollowUp(message string) error + func (a *Agent) MarkTurnCompleted() + func (a *Agent) MarkTurnStarted() + func (a *Agent) Prompt(ctx context.Context, prompt string) error + func (a *Agent) RecordError() + func (a *Agent) RecordToolFinished() + func (a *Agent) RecordToolStarted() + func (a *Agent) Session() *Session + func (a *Agent) SetSession(session *Session) + func (a *Agent) Start(ctx context.Context, session *Session, prompt string) error + func (a *Agent) State() AgentState + func (a *Agent) Steer(message string) error + func (a *Agent) Stop(ctx context.Context) error + func (a *Agent) Subscribe(fn func(AgentEvent)) (unsubscribe func()) + func (a *Agent) Transition(to AgentState) error + type AgentDriver interface + Resume func(ctx context.Context, session *Session) error + Start func(ctx context.Context, session *Session, prompt string) error + Stop func(ctx context.Context) error + Subscribe func(fn func(AgentEvent)) (unsubscribe func()) + func NewDriver(name string, cfg DriverConfig) (AgentDriver, error) + type AgentEvent struct + Assistant *ai.AssistantMessage + At time.Time + ControlMessage string + Delta string + DriverSessionID string + Error error + ErrorMessage string + Message *AgentMessage + Metadata map[string]any + SessionID string + State AgentState + ToolCallID string + ToolName string + ToolResult *AgentToolResult + Turn int + Type AgentEventType + type AgentEventType string + const EventAborted + const EventAgentMessageCompleted + const EventAgentMessageDelta + const EventDriverError + const EventFollowUpEnqueued + const EventProviderError + const EventSessionEnded + const EventSessionStarted + const EventStateChange + const EventSteeringApplied + const EventTerminalToolCompleted + const EventThinkingDelta + const EventToolCompleted + const EventToolError + const EventToolStarted + const EventToolUpdate + const EventTurnCompleted + const EventTurnStarted + type AgentLoopService struct + func NewAgentLoopService(publisher EventPublisher, opts ...ServiceOption) *AgentLoopService + func (s *AgentLoopService) Abort(ctx context.Context, req *agentapi.AbortRequest) (*agentapi.AbortResponse, error) + func (s *AgentLoopService) Close() error + func (s *AgentLoopService) Continue(ctx context.Context, req *agentapi.ContinueRequest) (agentapi.EventReceiver, error) + func (s *AgentLoopService) CreateSession(ctx context.Context, req *agentapi.CreateAgentSessionRequest) (*agentapi.CreateAgentSessionResponse, error) + func (s *AgentLoopService) DestroySession(ctx context.Context, req *agentapi.DestroyAgentSessionRequest) (*agentapi.DestroyAgentSessionResponse, error) + func (s *AgentLoopService) FollowUp(ctx context.Context, req *agentapi.FollowUpRequest) (*agentapi.FollowUpResponse, error) + func (s *AgentLoopService) GetSession(ctx context.Context, req *agentapi.GetAgentSessionRequest) (*agentapi.GetAgentSessionResponse, error) + func (s *AgentLoopService) ListSessions(ctx context.Context, req *agentapi.ListAgentSessionsRequest) (*agentapi.ListAgentSessionsResponse, error) + func (s *AgentLoopService) ResumeSession(ctx context.Context, req *agentapi.ResumeSessionRequest) (*agentapi.ResumeSessionResponse, error) + func (s *AgentLoopService) SendMessage(ctx context.Context, req *agentapi.SendMessageRequest) (agentapi.EventReceiver, error) + func (s *AgentLoopService) SetDriverFactory(factory func(name string, cfg DriverConfig) (AgentDriver, error)) + func (s *AgentLoopService) Steer(ctx context.Context, req *agentapi.SteerRequest) (*agentapi.SteerResponse, error) + func (s *AgentLoopService) SubscribeEvents(ctx context.Context, req *agentapi.SubscribeEventsRequest) (agentapi.EventReceiver, error) + type AgentMessage struct + CreatedAt time.Time + Message ai.Message + Turn int + type AgentState string + const StateExited + const StateIdle + const StateStreaming + const StateToolExecution + const StateWaitingFollowUp + type AgentTool struct + Execute func(ctx context.Context, toolCallID string, params map[string]any, ...) (AgentToolResult, error) + Label string + Terminal bool + type AgentToolResult struct + Content []ai.ContentBlock + ExitCode *int + IsError bool + Metadata map[string]any + SnapshotID string + type BusyError struct + State AgentState + func (BusyError) Unwrap() error + func (e BusyError) Error() string + type ControlCommand struct + CreatedAt time.Time + Message string + Type ControlCommandType + type ControlCommandType string + const ControlAbort + const ControlFollowUp + const ControlSteer + type ControlQueue struct + func NewControlQueue(buffer int) *ControlQueue + func (q *ControlQueue) C() <-chan ControlCommand + func (q *ControlQueue) Close() + func (q *ControlQueue) Drain() []ControlCommand + func (q *ControlQueue) Enqueue(cmd ControlCommand) error + func (q *ControlQueue) EnqueueAbort(message string) error + func (q *ControlQueue) EnqueueFollowUp(message string) error + func (q *ControlQueue) EnqueueSteer(message string) error + type DriverConfig struct + EnvironmentTools func() []AgentTool + Metadata map[string]any + Model ai.Model + Options ai.SimpleStreamOptions + SystemPrompt string + Tools []AgentTool + type DriverFactory func(cfg DriverConfig) (AgentDriver, error) + type EventPublisher interface + Publish func(sessionID string, event AgentEvent) + type InvalidStateError struct + From AgentState + To AgentState + func (InvalidStateError) Unwrap() error + func (e InvalidStateError) Error() string + type NativeDriver struct + func NewNativeDriver(cfg DriverConfig) *NativeDriver + func (d *NativeDriver) Resume(ctx context.Context, session *Session) error + func (d *NativeDriver) Start(ctx context.Context, session *Session, prompt string) error + func (d *NativeDriver) Stop(ctx context.Context) error + func (d *NativeDriver) Subscribe(fn func(AgentEvent)) func() + type ServiceCode string + const CodeAlreadyExists + const CodeCanceled + const CodeDeadlineExceeded + const CodeFailedPrecondition + const CodeInternal + const CodeInvalidArgument + const CodeNotFound + const CodeResourceExhausted + const CodeUnavailable + type ServiceError struct + Cause error + Code ServiceCode + Message string + func (e *ServiceError) Error() string + func (e *ServiceError) Unwrap() error + type ServiceOption func(*AgentLoopService) + func WithCloseDrainTimeout(d time.Duration) ServiceOption + func WithMaxSessions(n int) ServiceOption + func WithToolCatalogFactory(factory ToolCatalogFactory) ServiceOption + type Session struct + ConversationLog []AgentMessage + DriverSessionID string + ID string + Metrics SessionMetrics + StateHistory []AgentState + func (s *Session) Clone() *Session + type SessionMetrics struct + Errors uint64 + MessagesAppended uint64 + ToolCallsFinished uint64 + ToolCallsStarted uint64 + TurnsCompleted uint64 + TurnsStarted uint64 + type StoppedError struct + func (StoppedError) Error() string + func (StoppedError) Unwrap() error + type TermmuxDriverAdapter struct + func NewTermmuxDriverAdapter(session *termmux.Session) *TermmuxDriverAdapter + func (a *TermmuxDriverAdapter) IsPaused() bool + func (a *TermmuxDriverAdapter) Pause(ctx context.Context) error + func (a *TermmuxDriverAdapter) Resume(ctx context.Context, session *Session) error + func (a *TermmuxDriverAdapter) Start(ctx context.Context, session *Session, prompt string) error + func (a *TermmuxDriverAdapter) Stop(ctx context.Context) error + func (a *TermmuxDriverAdapter) Subscribe(fn func(AgentEvent)) (unsubscribe func()) + func (a *TermmuxDriverAdapter) Unpause(ctx context.Context) error + type ToolCatalogFactory func(cfg agentapi.SessionConfig) ([]AgentTool, error)