agent

package
v0.310.3 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AgentToolName = "agent"
)

Variables

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

Common errors

View Source
var ErrNoModel = fmt.Errorf("no model configured, please select a model")

ErrNoModel is returned when the agent has no model configured.

Functions

func CoderAgentTools

func CoderAgentTools(
	permissions permission.Service,
	history history.Service,
	lspClients map[string]*lsp.Client,
) []tools.BaseTool

func CoderAgentToolsWithMesnada

func CoderAgentToolsWithMesnada(
	mesnadaOrchestrator *orchestrator.Orchestrator,
	remembrances *rag.RemembrancesService,
	gateway *mcpgateway.Gateway,
	permissions permission.Service,
	history history.Service,
	lspClients map[string]*lsp.Client,
) []tools.BaseTool

func GetActivePersona added in v0.200.0

func GetActivePersona() string

GetActivePersona returns the currently active persona name. An empty string means no persona is active (auto-select or none).

func GetMcpTools

func GetMcpTools(ctx context.Context, permissions permission.Service) []tools.BaseTool

func GetMcpToolsWithGateway added in v0.8.0

func GetMcpToolsWithGateway(ctx context.Context, permissions permission.Service, gw *mcpgateway.Gateway) []tools.BaseTool

GetMcpToolsWithGateway returns MCP-backed tools for the LLM agent. When gw is non-nil (gateway mode), it exposes two proxy tools plus any favorite tools as direct wrappers. When gw is nil it falls back to the standard per-server tool list.

func GetPersonaManager added in v0.200.0

func GetPersonaManager() *persona.Manager

GetPersonaManager returns the global persona manager, or nil if not initialised.

func ListAvailablePersonas added in v0.200.0

func ListAvailablePersonas() []string

ListAvailablePersonas returns the names of all loaded personas. Uses the global persona manager when available; falls back to the selector's manager.

func NewAgentTool

func NewAgentTool(
	Sessions session.Service,
	Messages message.Service,
	LspClients map[string]*lsp.Client,
	skillManager *skills.SkillManager,
) tools.BaseTool

func NewMcpTool

func NewMcpTool(name string, tool mcp.Tool, permissions permission.Service, mcpConfig config.MCPServer) tools.BaseTool

func ResetMcpToolsCache added in v0.310.3

func ResetMcpToolsCache()

func SetActivePersona added in v0.200.0

func SetActivePersona(name string) error

SetActivePersona sets the active persona by name. Pass an empty string to clear the active persona (revert to auto-select or none). Returns an error if the named persona does not exist (and name is non-empty).

func SetContextEnricher added in v0.236.1

func SetContextEnricher(e ContextEnricher)

SetContextEnricher sets the context enricher used to prepend KB/code context to user messages. Pass nil to disable context enrichment.

func SetLuaManager added in v0.8.0

func SetLuaManager(fm *luaengine.FilterManager)

SetLuaManager sets the global Lua filter manager used for MCP tool input/output filtering.

func SetNonInteractiveMode added in v0.291.0

func SetNonInteractiveMode(enabled bool)

SetNonInteractiveMode configures all agents to run autonomously without waiting for user input. Call this before running a session when a prompt is provided via the -p flag or stdin pipe.

func SetPersonaManager added in v0.200.0

func SetPersonaManager(mgr *persona.Manager)

SetPersonaManager sets the global persona manager used for persona listing and manual persona selection. This should be called during app initialisation.

func SetPersonaSelector added in v0.41.0

func SetPersonaSelector(ps *PersonaSelector)

SetPersonaSelector sets the global persona selector used in the main conversation agent.

func TaskAgentTools

func TaskAgentTools(lspClients map[string]*lsp.Client) []tools.BaseTool

Types

type AgentEvent

type AgentEvent struct {
	Type       AgentEventType
	Message    message.Message
	Error      error
	Delta      string
	ToolCall   *message.ToolCall
	ToolResult *message.ToolResult

	// When summarizing
	SessionID string
	Progress  string
	Done      bool

	// Todos is populated when Type == AgentEventTypeTodosUpdated.
	Todos []tools.TodoItem
}

type AgentEventType

type AgentEventType string
const (
	AgentEventTypeError         AgentEventType = "error"
	AgentEventTypeResponse      AgentEventType = "response"
	AgentEventTypeSummarize     AgentEventType = "summarize"
	AgentEventTypeContentDelta  AgentEventType = "content_delta"
	AgentEventTypeThinkingDelta AgentEventType = "thinking_delta"
	AgentEventTypeToolCall      AgentEventType = "tool_call"
	AgentEventTypeToolResult    AgentEventType = "tool_result"
	// AgentEventTypeTodosUpdated is emitted when the TodoWrite tool runs successfully.
	// It carries the current todo list for non-ACP consumers (TUI, WebUI).
	AgentEventTypeTodosUpdated AgentEventType = "todos_updated"
)

type AgentParams

type AgentParams struct {
	Prompt string `json:"prompt"`
}

type ContextEnricher added in v0.236.1

type ContextEnricher interface {
	EnrichContext(ctx context.Context, query string) string
}

ContextEnricher is the interface used by the agent to enrich the user's prompt with context retrieved from the KB and code index before sending it to the LLM. A local interface is used to avoid import cycles between agent and rag packages.

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 PersonaSelector added in v0.41.0

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

PersonaSelector automatically selects and applies a persona for each user prompt. It uses a lite LLM provider (configured via agents["persona-selector"]) to pick the best matching persona from the personas directory, then prepends its content to the user message before it reaches the main conversation model.

func NewPersonaSelector added in v0.41.0

func NewPersonaSelector(personaPath string) (*PersonaSelector, error)

NewPersonaSelector creates a PersonaSelector that loads personas from personaPath and uses the model configured under agents["persona-selector"] to perform selection. Returns an error if the persona-selector agent is not configured or the model is unavailable.

func (*PersonaSelector) SelectAndApply added in v0.41.0

func (ps *PersonaSelector) SelectAndApply(ctx context.Context, userPrompt string) string

SelectAndApply selects the best persona for userPrompt and returns the prompt with the persona content prepended. Kept for backward compatibility; prefer SelectPersonaContent when the content will be injected into the system prompt.

func (*PersonaSelector) SelectPersonaContent added in v0.265.0

func (ps *PersonaSelector) SelectPersonaContent(ctx context.Context, userPrompt string) string

SelectPersonaContent selects the best persona for userPrompt and returns its raw content (the persona instructions). Returns an empty string if no persona matches, the selector is disabled, or an error occurs. The content is intended to be injected into the system prompt rather than prepended to the user message.

type Service

type Service interface {
	pubsub.Suscriber[AgentEvent]
	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
	SetLuaManager(fm *luaengine.FilterManager)
	// GetTools returns the tools available to this agent instance.
	GetTools() []tools.BaseTool
}

func NewAgent

func NewAgent(
	agentName config.AgentName,
	sessions session.Service,
	messages message.Service,
	agentTools []tools.BaseTool,
	skillManager *skills.SkillManager,
) (Service, error)

Jump to

Keyboard shortcuts

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