agent

package
v1.9.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	AutoCompactionThreshold = 0.95
)
View Source
const (
	TaskToolName = "task"
)

Variables

View Source
var (
	ErrRequestCancelled = errors.New("request cancelled by user")
	ErrSessionBusy      = errors.New("session is currently processing another request")

	//go:embed prompts/*.md
	AgentPrompts embed.FS
)

Common errors

Functions

func NewAgentTool

func NewAgentTool(
	sessions session.Service,
	permissions permission.Service,
	reg agentregistry.Registry,
	factory AgentFactory,
) tools.BaseTool

func NewToolSet

func NewToolSet(
	ctx context.Context,
	info *agentregistry.AgentInfo,
	reg agentregistry.Registry,
	permissions permission.Service,
	historyService history.Service,
	lspService lsp.LspService,
	sessions session.Service,
	messages message.Service,
	mcpRegistry MCPRegistry,
	factory AgentFactory,
) <-chan tools.BaseTool

NewToolSet dynamically builds the tool slice for an agent based on its registry info. Only tools that pass registry.IsToolEnabled are included.

Types

type AgentEvent

type AgentEvent struct {
	Type    AgentEventType
	Message message.Message
	Error   error

	// When has structured output
	StructOutput *message.ToolResult

	// When summarizing
	SessionID string
	Progress  string
	Done      bool

	// FlowStepID is set when event originates from a Flow step
	FlowStepID string
}

type AgentEventType

type AgentEventType string
const (
	AgentEventTypeError     AgentEventType = "error"
	AgentEventTypeResponse  AgentEventType = "response"
	AgentEventTypeSummarize AgentEventType = "summarize"
)

type AgentFactory added in v1.7.0

type AgentFactory interface {
	NewAgent(ctx context.Context, agentID string, outputSchema map[string]any, stepID string) (Service, error)
	InitPrimaryAgents(ctx context.Context, outputSchema map[string]any) ([]Service, error)
}

AgentFactory creates agent instances with optional output schema overrides. Agents are cached by stepID for flow step reuse. Primary agents (created without a stepID) are tracked for reuse when no schema override is needed.

func NewAgentFactory added in v1.7.0

func NewAgentFactory(
	sessions session.Service,
	messages message.Service,
	permissions permission.Service,
	history history.Service,
	lspService lsp.LspService,
	registry agentregistry.Registry,
	mcpRegistry MCPRegistry,
) AgentFactory

type AgentParams deprecated

type AgentParams = TaskParams

Deprecated: use TaskParams instead

type MCPClient

type MCPClient interface {
	Initialize(
		ctx context.Context,
		request mcp.InitializeRequest,
	) (*mcp.InitializeResult, error)
	ListTools(ctx context.Context, request mcp.ListToolsRequest) (*mcp.ListToolsResult, error)
	CallTool(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error)
	Close() error
}

type MCPRegistry

type MCPRegistry interface {
	// GetTools return tools matching filter, if registry is not loaded it will begin loading
	LoadTools(ctx context.Context, filter *MCPRegistryFiler) <-chan tools.BaseTool
	// StartClient starts a new MCPClient, caller have to properly close when done
	StartClient(ctx context.Context, name string) (c *client.Client, err error)
}

func NewMCPRegistry

func NewMCPRegistry(permissions permission.Service, agentRegistry agentregistry.Registry) MCPRegistry

type MCPRegistryFiler

type MCPRegistryFiler struct {
	ToolNames   []string
	ServerNames []string
}

type Service

type Service interface {
	pubsub.Subscriber[AgentEvent]
	AgentID() config.AgentName
	Model() models.Model
	Run(ctx context.Context, sessionID string, content string, attachments ...message.Attachment) (<-chan AgentEvent, error)
	Cancel(sessionID string)
	IsSessionBusy(sessionID string) bool
	IsBusy() bool
	Update(agentName config.AgentName, modelID models.ModelID) (models.Model, error)
	Summarize(ctx context.Context, sessionID string) error
}

type TaskParams

type TaskParams struct {
	Prompt       string `json:"prompt"`
	SubagentType string `json:"subagent_type"`
	TaskID       string `json:"task_id,omitempty"`
	TaskTitle    string `json:"task_title,omitempty"`
}

type TaskResponseMetadata added in v1.3.0

type TaskResponseMetadata struct {
	TaskID         string `json:"task_id"`
	SubagentType   string `json:"subagent_type"`
	SubagentName   string `json:"subagent_name"`
	IsResumed      bool   `json:"is_resumed"`
	IsStructOutput bool   `json:"is_struct_output"`
}

Jump to

Keyboard shortcuts

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