loop

package
v0.228.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

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

Agent implements the AgentService interface with direct chat functionality

func NewAgent

func NewAgent(
	client sdk.Client,
	toolService agentdomain.ToolService,
	approvalPolicy agentdomain.ApprovalPolicy,
	cfg *config.Config,
	conversationRepo convdomain.ConversationRepository,
	a2aAgents func() string,
	skillsService agentdomain.SkillsService,
	messageQueue convdomain.MessageQueue,
	stateManager stateStore,
	optimizer convdomain.ConversationOptimizer,
	bgRegistry scheddomain.BackgroundTaskRegistry,
	rolloverManager convdomain.SessionRollover,
	tokenizer usageEstimator,
	hookProvider agentdomain.HookCommandProvider,
	pluginInstructions func() string,
) *Agent

func (*Agent) BuildSystemPrompt

func (s *Agent) 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 and agent-mode switches so LLM servers get KV-cache prefix hits; volatile context rides in volatileTailMessage and per-mode behaviour in the mode-change reminder. Returns "" when unset.

func (*Agent) CancelRequest

func (s *Agent) CancelRequest(requestID string) error

CancelRequest cancels an active request. Safe to call repeatedly - no-ops via sync.Once on the underlying sessionCancel - and returns nil even for an unknown requestID, so the UI can fire it on every Esc press without spurious errors after teardown. The agent loop publishes ChatCompleteEvent{Cancelled:true} as the single cancel-completion signal.

func (*Agent) GetMetrics

func (s *Agent) GetMetrics(requestID string) *agentdomain.ChatMetrics

GetMetrics returns metrics for a completed request

func (*Agent) GetReasoningEffort

func (s *Agent) GetReasoningEffort() string

GetReasoningEffort returns the effort level currently applied to requests ("" = provider default).

func (*Agent) RunWithStream

func (s *Agent) RunWithStream(ctx context.Context, req *agentdomain.AgentRequest) (<-chan agentdomain.ChatEvent, error)

RunWithStream executes an agent task with streaming (for interactive chat)

func (*Agent) SetCurrentModelFn

func (s *Agent) SetCurrentModelFn(fn func() string)

SetCurrentModelFn wires the session's current-model accessor so the judge follows a model picked at runtime, not only the configured agent.model.

func (*Agent) SetMemoryBackend

func (s *Agent) 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 (*Agent) SetReasoningEffort

func (s *Agent) SetReasoningEffort(effort string) error

SetReasoningEffort updates the reasoning effort applied to subsequent requests. An empty string resets to the provider default.

func (*Agent) SetTelemetryRecorder

func (s *Agent) SetTelemetryRecorder(rec *telemetry.Recorder)

SetTelemetryRecorder wires the telemetry recorder so per-request token usage is tapped in storeIterationMetrics. A nil recorder disables recording.

func (*Agent) SystemPromptSections

func (s *Agent) 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 (*Agent) VolatileTailText

func (s *Agent) 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, alongside SystemPromptSections.

type ApprovalTools

type ApprovalTools interface {
	agentdomain.ToolManifestLookup
	GetTool(name string) (agentdomain.Tool, error)
}

ApprovalTools is what the approval policy needs to know about the tools: a tool's manifest, and the tool itself when it approves per call. The registry and the tool service both satisfy it.

type JudgeApprover

type JudgeApprover interface {
	Judge(ctx context.Context, in agentdomain.JudgeInput) (agentdomain.JudgeVerdict, error)
}

JudgeApprover decides one pending tool call by asking a small LLM whether it serves the user's intent and is safe. The judge is the approver selected by approval_behaviour "judge" / agent mode auto-with-judge: it is always reachable, so headless and CI get a real approver instead of blocking.

type LLMJudge

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

LLMJudge implements JudgeApprover with one no-tools GenerateContent call (same shape as GenerateLLMSummary: direct client call, SkipMCP, its own timeout, bounded max_tokens). The judge.yaml on_error policy decides what a failed call means: deny (default) fails closed with a distinguishable reason - the same default as the no-approver block path - allow approves.

func NewLLMJudge

func NewLLMJudge(client sdk.Client, cfg *config.Config) *LLMJudge

NewLLMJudge creates the judge approver. Config validation fails fast at startup when no model is resolvable, so an empty model here is a hard error. judge.gateway_url gives the judge its own client (same API key and timeout as the agent's) so it can answer from a different gateway than the driver.

func (*LLMJudge) Judge

Judge decides one pending tool call: does it serve the user's intent and is it safe to run? The verdict contract is enforced by agentdomain.ParseJudgeVerdict.

type PromptSection

type PromptSection struct {
	Name     string
	Text     string
	Volatile bool
}

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

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

StandardApprovalPolicy implements the default approval policy with the following rules:

  1. A tool that approves per call (agentdomain.CallApprover) decides for itself, ahead of the agent mode
  2. 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. Neither needs a call the mode does not make available: execution rejects it
  3. Non-chat (headless agent) mode bypasses approval; there the Bash tool's own per-mode gate (executeBash) decides what runs
  4. Bash commands are governed by the per-mode allow-list (sandbox.IsBashCommandAllowed): reached only in chat, non-auto mode, so allowed commands bypass approval and anything off-list prompts the user
  5. Other tools follow their own require_approval setting, then their manifest's default, then the global require_approval setting

func NewStandardApprovalPolicy

func NewStandardApprovalPolicy(cfg *config.Config, stateManager agentdomain.AgentModeState, tools ApprovalTools) *StandardApprovalPolicy

NewStandardApprovalPolicy creates a new standard approval policy. tools resolves each tool's manifest for its plan-mode and approval defaults; with nil every tool gets the default policy.

func (*StandardApprovalPolicy) ShouldRequireApproval

func (p *StandardApprovalPolicy) ShouldRequireApproval(
	ctx context.Context,
	toolCall *sdk.ChatCompletionMessageToolCall,
	isChatMode bool,
) bool

ShouldRequireApproval implements the approval decision logic

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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