Documentation
¶
Index ¶
- func InjectDueReminders(provider agentdomain.SystemReminderProvider, q agentdomain.ReminderQuery, ...)
- func NewAgentStateMachine() states.AgentStateMachine
- func RunCommandHooks(ctx context.Context, cfg *config.Config, ...)
- type AgentServiceImpl
- func (s *AgentServiceImpl) BuildSystemPrompt() string
- func (s *AgentServiceImpl) CancelRequest(requestID string) error
- func (s *AgentServiceImpl) GetMetrics(requestID string) *agentdomain.ChatMetrics
- func (s *AgentServiceImpl) GetReasoningEffort() string
- func (s *AgentServiceImpl) Run(ctx context.Context, req *agentdomain.AgentRequest) (*agentdomain.ChatSyncResponse, error)
- func (s *AgentServiceImpl) RunStreaming(ctx context.Context, req *agentdomain.AgentRequest, ...) (*agentdomain.ChatSyncResponse, error)
- func (s *AgentServiceImpl) RunWithStream(ctx context.Context, req *agentdomain.AgentRequest) (<-chan agentdomain.ChatEvent, error)
- func (s *AgentServiceImpl) SetMemoryBackend(backend memory.MemoryBackend)
- func (s *AgentServiceImpl) SetReasoningEffort(effort string) error
- func (s *AgentServiceImpl) SetTelemetryRecorder(rec *telemetry.Recorder)
- func (s *AgentServiceImpl) SystemPromptSections() []PromptSection
- func (s *AgentServiceImpl) VolatileTailText() (string, bool)
- type AgentStateMachineImpl
- func (sm *AgentStateMachineImpl) CanTransition(ctx *states.AgentContext, targetState states.AgentExecutionState) bool
- func (sm *AgentStateMachineImpl) GetCurrentState() states.AgentExecutionState
- func (sm *AgentStateMachineImpl) GetPreviousState() states.AgentExecutionState
- func (sm *AgentStateMachineImpl) GetValidTransitions(ctx *states.AgentContext) []states.AgentExecutionState
- func (sm *AgentStateMachineImpl) Reset()
- func (sm *AgentStateMachineImpl) Transition(ctx *states.AgentContext, targetState states.AgentExecutionState) error
- type EventDrivenAgent
- type IndexedToolResult
- type LLMToolService
- func (s *LLMToolService) ExecuteTool(ctx context.Context, toolCall sdk.ChatCompletionMessageToolCallFunction) (*agentdomain.ToolExecutionResult, error)
- func (s *LLMToolService) ExecuteToolDirect(ctx context.Context, toolCall sdk.ChatCompletionMessageToolCallFunction) (*agentdomain.ToolExecutionResult, error)
- func (s *LLMToolService) GetA2ATaskTracker() agentdomain.A2ATaskTracker
- func (s *LLMToolService) GetTool(name string) (agentdomain.Tool, error)
- func (s *LLMToolService) IsToolEnabled(name string) bool
- func (s *LLMToolService) ListAvailableTools() []string
- func (s *LLMToolService) ListTools() []sdk.ChatCompletionTool
- func (s *LLMToolService) ListToolsForMode(mode agentdomain.AgentMode) []sdk.ChatCompletionTool
- func (s *LLMToolService) SetCurrentModelFn(fn func() string)
- func (s *LLMToolService) ValidateTool(name string, args map[string]any) error
- type NoOpToolService
- func (s *NoOpToolService) ExecuteTool(ctx context.Context, toolCall sdk.ChatCompletionMessageToolCallFunction) (*agentdomain.ToolExecutionResult, error)
- func (s *NoOpToolService) ExecuteToolDirect(ctx context.Context, toolCall sdk.ChatCompletionMessageToolCallFunction) (*agentdomain.ToolExecutionResult, error)
- func (s *NoOpToolService) GetA2ATaskTracker() agentdomain.A2ATaskTracker
- func (s *NoOpToolService) GetTool(name string) (agentdomain.Tool, error)
- func (s *NoOpToolService) IsToolEnabled(name string) bool
- func (s *NoOpToolService) ListAvailableTools() []string
- func (s *NoOpToolService) ListTools() []sdk.ChatCompletionTool
- func (s *NoOpToolService) ListToolsForMode(mode agentdomain.AgentMode) []sdk.ChatCompletionTool
- func (s *NoOpToolService) ValidateTool(name string, args map[string]any) error
- type PromptSection
- type StandardApprovalPolicy
- type StateTransition
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InjectDueReminders ¶ added in v0.163.0
func InjectDueReminders(provider agentdomain.SystemReminderProvider, q agentdomain.ReminderQuery, deliver func(agentdomain.SystemReminder))
InjectDueReminders is the single reminder-injection seam shared by the chat (AgentServiceImpl) and headless (AgentSession) loops: it resolves the reminders due for q, delivers each via the caller-owned deliver callback (the two loops hold different conversation representations), logs it, emits the tagged system_reminder stream event, and marks the name in q.Fired. Callers own provider resolution, the awaiting-tool-results guard, query construction, and locking.
func NewAgentStateMachine ¶
func NewAgentStateMachine() states.AgentStateMachine
NewAgentStateMachine creates a new agent state machine
func RunCommandHooks ¶ added in v0.125.0
func RunCommandHooks(ctx context.Context, cfg *config.Config, provider agentdomain.HookCommandProvider, modeKey string, hook agentdomain.HookPoint, turn int, sessionID string)
RunCommandHooks is the single chokepoint both agents use to run command hooks. It asks the provider which commands are attached to hook, gates each on the per-mode bash allow-list - the SAME matcher a model-proposed bash command faces, so command hooks open no new bypass of the secure-by-default model - and runs the allowed ones fire-and-observe. Off-list commands are skipped and reported with the rejection hint (the user authorizes a command by allow-listing it, e.g. tools.bash.mode.*.allow or INFER_TOOLS_BASH_ALLOW_APPEND).
Both the event-driven chat agent and the headless `infer headless` loop call this from their dispatchHooks seam so the gate and observability cannot drift apart. cfg supplies the allow-list and the fallback provider; modeKey is the resolved per-mode allow-list key (standard/plan/auto); sessionID and turn populate the command's stdin JSON context. Commands run synchronously; their output is emitted as a hook_command stream event and logged, never fed back into the conversation or used to alter the loop (that feedback is a later iteration).
Types ¶
type AgentServiceImpl ¶
type AgentServiceImpl struct {
// contains filtered or unexported fields
}
AgentServiceImpl implements the AgentService interface with direct chat functionality
func NewAgent ¶
func NewAgent( client sdk.Client, toolService agentdomain.ToolService, cfg *config.Config, conversationRepo convdomain.ConversationRepository, a2aAgentService agentapp.A2AAgentService, skillsService agentdomain.SkillsService, messageQueue convdomain.MessageQueue, stateManager stateManager, timeoutSeconds int, optimizer convdomain.ConversationOptimizer, bgRegistry scheddomain.BackgroundTaskRegistry, rolloverManager *conv.SessionRolloverManager, ) *AgentServiceImpl
func (*AgentServiceImpl) BuildSystemPrompt ¶ added in v0.117.0
func (s *AgentServiceImpl) BuildSystemPrompt() string
BuildSystemPrompt assembles the static system prompt sent as message[0] (base prompt + custom instructions + AGENTS.md + plugins + static context). It is deliberately byte-identical across turns within a session so local LLM servers get KV-cache prefix hits; volatile context (git, tree, memory, active skill, date) rides in volatileTailMessage instead. Returns "" when no base prompt is configured for the current mode.
func (*AgentServiceImpl) CancelRequest ¶
func (s *AgentServiceImpl) CancelRequest(requestID string) error
CancelRequest cancels an active request. Safe to call multiple times for the same requestID - subsequent calls are no-ops via sync.Once on the underlying sessionCancel. Returns nil even when the request is unknown, so the UI can fire it on every Esc press without surfacing spurious errors after the session has already torn down. The agent loop publishes ChatCompleteEvent{Cancelled:true} as the single cancel-completion signal; no separate CancelledEvent broadcast is needed.
func (*AgentServiceImpl) GetMetrics ¶
func (s *AgentServiceImpl) GetMetrics(requestID string) *agentdomain.ChatMetrics
GetMetrics returns metrics for a completed request
func (*AgentServiceImpl) GetReasoningEffort ¶ added in v0.154.0
func (s *AgentServiceImpl) GetReasoningEffort() string
GetReasoningEffort returns the effort level currently applied to requests ("" = provider default).
func (*AgentServiceImpl) Run ¶
func (s *AgentServiceImpl) Run(ctx context.Context, req *agentdomain.AgentRequest) (*agentdomain.ChatSyncResponse, error)
func (*AgentServiceImpl) RunStreaming ¶ added in v0.165.0
func (s *AgentServiceImpl) RunStreaming( ctx context.Context, req *agentdomain.AgentRequest, onDelta func(content, reasoning string, toolCalls []sdk.ChatCompletionMessageToolCallChunk), ) (*agentdomain.ChatSyncResponse, error)
RunStreaming executes a single model turn with streaming, invoking onDelta for each content/reasoning/tool-call delta as it arrives, and returns the same assembled ChatSyncResponse as Run. It is the streaming counterpart of Run for callers that own their own agentic loop (the headless AG-UI agent) and want token-level output without adopting the full EventDrivenAgent. onDelta may be nil.
func (*AgentServiceImpl) RunWithStream ¶
func (s *AgentServiceImpl) RunWithStream(ctx context.Context, req *agentdomain.AgentRequest) (<-chan agentdomain.ChatEvent, error)
RunWithStream executes an agent task with streaming (for interactive chat)
func (*AgentServiceImpl) SetMemoryBackend ¶ added in v0.127.0
func (s *AgentServiceImpl) SetMemoryBackend(backend memory.MemoryBackend)
SetMemoryBackend wires the memory sync backend so the chat agent pulls memory once at session start (SyncIn on HookPreSession). SyncOut is driven by the Memory tool on write/delete, not here - chat fires HookPostSession after every message, so pushing there would commit-storm. A nil backend disables sync.
func (*AgentServiceImpl) SetReasoningEffort ¶ added in v0.154.0
func (s *AgentServiceImpl) SetReasoningEffort(effort string) error
SetReasoningEffort updates the reasoning effort applied to subsequent requests. An empty string resets to the provider default.
func (*AgentServiceImpl) SetTelemetryRecorder ¶ added in v0.145.0
func (s *AgentServiceImpl) SetTelemetryRecorder(rec *telemetry.Recorder)
SetTelemetryRecorder wires the telemetry recorder so per-request token usage is tapped in storeIterationMetrics. A nil recorder disables recording.
func (*AgentServiceImpl) SystemPromptSections ¶ added in v0.140.0
func (s *AgentServiceImpl) SystemPromptSections() []PromptSection
SystemPromptSections returns the labeled parts of the prompt context a fresh session (turn 0) would send — the static system prompt sections followed by the Volatile-marked tail sections — with empty parts omitted. Exposed for the `infer debug agent system_prompt --tokens` breakdown.
func (*AgentServiceImpl) VolatileTailText ¶ added in v0.151.0
func (s *AgentServiceImpl) VolatileTailText() (string, bool)
VolatileTailText renders the volatile-context tail a fresh session (turn 0) would send as a hidden per-request <system-reminder> user message; ok=false means no tail is sent. Exposed for the `infer debug agent system_prompt` command via type assertion, alongside SystemPromptSections.
type AgentStateMachineImpl ¶
type AgentStateMachineImpl struct {
// contains filtered or unexported fields
}
AgentStateMachineImpl implements the AgentStateMachine interface.
The state machine manages the agent's execution flow through the following states:
State Flow:
Idle → CheckingQueue → StreamingLLM → PostStream → EvaluatingTools → ApprovingTools/BlockingTools/ExecutingTools → PostToolExecution → CheckingQueue (loop) → Completing → Idle
State Descriptions:
- Idle: Agent is not executing, waiting for work
- CheckingQueue: Checking if there are queued messages or if completion criteria are met
- StreamingLLM: Streaming responses from the LLM
- PostStream: Processing LLM response, checking for tool calls or completion
- EvaluatingTools: Determining if tool calls need approval
- ApprovingTools: Waiting for user approval of tool calls (only in chat mode)
- BlockingTools: Approval required but undeliverable (approval_behaviour=block); gated tools are rejected with a reason
- ExecutingTools: Executing approved or auto-approved tool calls
- PostToolExecution: Processing tool results, checking for completion or continuing
- Completing: Finalizing the agent execution
- Error: An error occurred during execution
- Cancelled: User cancelled the execution
- Stopped: Tool execution indicated stop (user rejection or error)
Thread Safety:
All state transitions are protected by a read-write mutex to ensure thread-safe access.
func (*AgentStateMachineImpl) CanTransition ¶
func (sm *AgentStateMachineImpl) CanTransition(ctx *states.AgentContext, targetState states.AgentExecutionState) bool
CanTransition checks if a transition from current state to target state is valid This is useful for checking before attempting a transition
func (*AgentStateMachineImpl) GetCurrentState ¶
func (sm *AgentStateMachineImpl) GetCurrentState() states.AgentExecutionState
GetCurrentState returns the current state (thread-safe)
func (*AgentStateMachineImpl) GetPreviousState ¶
func (sm *AgentStateMachineImpl) GetPreviousState() states.AgentExecutionState
GetPreviousState returns the previous state (thread-safe)
func (*AgentStateMachineImpl) GetValidTransitions ¶
func (sm *AgentStateMachineImpl) GetValidTransitions(ctx *states.AgentContext) []states.AgentExecutionState
GetValidTransitions returns all valid transitions from the current state
func (*AgentStateMachineImpl) Reset ¶
func (sm *AgentStateMachineImpl) Reset()
Reset resets the state machine to idle
func (*AgentStateMachineImpl) Transition ¶
func (sm *AgentStateMachineImpl) Transition(ctx *states.AgentContext, targetState states.AgentExecutionState) error
Transition attempts to transition to the target state
type EventDrivenAgent ¶
type EventDrivenAgent struct {
// contains filtered or unexported fields
}
EventDrivenAgent manages agent execution using event-driven state machine
func NewEventDrivenAgent ¶
func NewEventDrivenAgent( service *AgentServiceImpl, cfg *config.AgentConfig, ctx context.Context, req *agentdomain.AgentRequest, conversation *[]sdk.Message, eventPublisher *eventPublisher, cancelChan <-chan struct{}, provider string, model string, registry scheddomain.BackgroundTaskRegistry, ) *EventDrivenAgent
NewEventDrivenAgent creates a new event-driven agent
func (*EventDrivenAgent) Start ¶
func (a *EventDrivenAgent) Start()
Start begins the event-driven agent execution. The state machine already begins in Idle, so seeding a MessageReceivedEvent drives the first transition (Idle -> CheckingQueue) via the Idle state handler.
func (*EventDrivenAgent) Wait ¶
func (a *EventDrivenAgent) Wait()
Wait waits for the agent to complete
type IndexedToolResult ¶
type IndexedToolResult struct {
Index int
Result convdomain.ConversationEntry
}
type LLMToolService ¶ added in v0.178.1
type LLMToolService struct {
// contains filtered or unexported fields
}
LLMToolService implements ToolService with the new tools package architecture
func NewLLMToolServiceWithRegistry ¶ added in v0.178.1
func NewLLMToolServiceWithRegistry(cfg *config.Config, registry *tools.Registry) *LLMToolService
NewLLMToolServiceWithRegistry creates a new LLM tool service with an existing registry
func (*LLMToolService) ExecuteTool ¶ added in v0.178.1
func (s *LLMToolService) ExecuteTool(ctx context.Context, toolCall sdk.ChatCompletionMessageToolCallFunction) (*agentdomain.ToolExecutionResult, error)
ExecuteTool executes a tool with the given arguments
func (*LLMToolService) ExecuteToolDirect ¶ added in v0.178.1
func (s *LLMToolService) ExecuteToolDirect(ctx context.Context, toolCall sdk.ChatCompletionMessageToolCallFunction) (*agentdomain.ToolExecutionResult, error)
ExecuteToolDirect executes a tool directly without checking if it's enabled Used for user-initiated commands where the user explicitly wants to run the tool
func (*LLMToolService) GetA2ATaskTracker ¶ added in v0.178.1
func (s *LLMToolService) GetA2ATaskTracker() agentdomain.A2ATaskTracker
func (*LLMToolService) GetTool ¶ added in v0.178.1
func (s *LLMToolService) GetTool(name string) (agentdomain.Tool, error)
func (*LLMToolService) IsToolEnabled ¶ added in v0.178.1
func (s *LLMToolService) IsToolEnabled(name string) bool
IsToolEnabled checks if a tool is enabled
func (*LLMToolService) ListAvailableTools ¶ added in v0.178.1
func (s *LLMToolService) ListAvailableTools() []string
ListAvailableTools returns names of all enabled tools
func (*LLMToolService) ListTools ¶ added in v0.178.1
func (s *LLMToolService) ListTools() []sdk.ChatCompletionTool
ListTools returns definitions for all enabled tools
func (*LLMToolService) ListToolsForMode ¶ added in v0.178.1
func (s *LLMToolService) ListToolsForMode(mode agentdomain.AgentMode) []sdk.ChatCompletionTool
ListToolsForMode returns definitions for enabled tools filtered by agent mode
func (*LLMToolService) SetCurrentModelFn ¶ added in v0.178.1
func (s *LLMToolService) SetCurrentModelFn(fn func() string)
SetCurrentModelFn wires the current-model accessor used for per-model tool filtering (e.g. hiding ImageDecode from vision-capable models).
func (*LLMToolService) ValidateTool ¶ added in v0.178.1
func (s *LLMToolService) ValidateTool(name string, args map[string]any) error
ValidateTool validates tool arguments
type NoOpToolService ¶ added in v0.178.1
type NoOpToolService struct{}
NoOpToolService implements ToolService as a no-op (when tools are disabled)
func NewNoOpToolService ¶ added in v0.178.1
func NewNoOpToolService() *NoOpToolService
NewNoOpToolService creates a new no-op tool service
func (*NoOpToolService) ExecuteTool ¶ added in v0.178.1
func (s *NoOpToolService) ExecuteTool(ctx context.Context, toolCall sdk.ChatCompletionMessageToolCallFunction) (*agentdomain.ToolExecutionResult, error)
func (*NoOpToolService) ExecuteToolDirect ¶ added in v0.178.1
func (s *NoOpToolService) ExecuteToolDirect(ctx context.Context, toolCall sdk.ChatCompletionMessageToolCallFunction) (*agentdomain.ToolExecutionResult, error)
func (*NoOpToolService) GetA2ATaskTracker ¶ added in v0.178.1
func (s *NoOpToolService) GetA2ATaskTracker() agentdomain.A2ATaskTracker
func (*NoOpToolService) GetTool ¶ added in v0.178.1
func (s *NoOpToolService) GetTool(name string) (agentdomain.Tool, error)
func (*NoOpToolService) IsToolEnabled ¶ added in v0.178.1
func (s *NoOpToolService) IsToolEnabled(name string) bool
func (*NoOpToolService) ListAvailableTools ¶ added in v0.178.1
func (s *NoOpToolService) ListAvailableTools() []string
func (*NoOpToolService) ListTools ¶ added in v0.178.1
func (s *NoOpToolService) ListTools() []sdk.ChatCompletionTool
func (*NoOpToolService) ListToolsForMode ¶ added in v0.178.1
func (s *NoOpToolService) ListToolsForMode(mode agentdomain.AgentMode) []sdk.ChatCompletionTool
func (*NoOpToolService) ValidateTool ¶ added in v0.178.1
func (s *NoOpToolService) ValidateTool(name string, args map[string]any) error
type PromptSection ¶ added in v0.140.0
PromptSection is one labeled part of the assembled prompt context, exposed for diagnostics (e.g. per-section token estimates in `infer debug`). Text is the raw part as it appears in the prompt, including any separator prefix. Volatile marks sections delivered via the per-request tail message rather than the static system prompt.
type StandardApprovalPolicy ¶ added in v0.178.1
type StandardApprovalPolicy struct {
// contains filtered or unexported fields
}
StandardApprovalPolicy implements the default approval policy with the following rules:
- Computer use tools (mouse, keyboard) always bypass approval (background execution)
- Auto-accept mode bypasses all approval 2.5. ReadOnly mode (Explore-like subagent) bypasses approval; its toolset is read-only by construction so nothing it can call mutates
- Non-chat (headless agent) mode bypasses approval; there the Bash tool's own per-mode gate (executeBash) decides what runs
- Bash commands are governed by the per-mode allow-list (config.IsBashCommandAllowed): reached only in chat, non-auto mode, so allowed commands bypass approval and anything off-list prompts the user
- Other tools check configuration (per-tool or global require_approval setting)
func NewStandardApprovalPolicy ¶ added in v0.178.1
func NewStandardApprovalPolicy(cfg *config.Config, stateManager agentdomain.AgentModeManager) *StandardApprovalPolicy
NewStandardApprovalPolicy creates a new standard approval policy
func (*StandardApprovalPolicy) ShouldRequireApproval ¶ added in v0.178.1
func (p *StandardApprovalPolicy) ShouldRequireApproval( ctx context.Context, toolCall *sdk.ChatCompletionMessageToolCall, isChatMode bool, ) bool
ShouldRequireApproval implements the approval decision logic
type StateTransition ¶
type StateTransition struct {
// contains filtered or unexported fields
}
StateTransition represents a state transition with guard and action
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package application holds agent-context orchestration contracts that touch external A2A (adk) types; they are deliberately outside the pure domain.
|
Package application holds agent-context orchestration contracts that touch external A2A (adk) types; they are deliberately outside the pure domain. |
|
agentrunner
Package agentrunner centralizes spawning `infer headless` as a subprocess and streaming its stdout.
|
Package agentrunner centralizes spawning `infer headless` as a subprocess and streaming its stdout. |