Documentation
¶
Overview ¶
Package core is the native Go smooth-operator engine — an in-process agentic tool-calling loop over an OpenAI-compatible chat client, with in-memory knowledge grounding. The Go sibling of the Rust reference engine, the C# core, the Python core, and the TypeScript core. See docs/Architecture/Go Core.md.
Index ¶
- Constants
- Variables
- func AppendGrant(path string, query GrantQuery) error
- func LoadProjectContext(workingDir string) (string, bool)
- func ProjectGrantsPath(workspace string) string
- func UserGrantsPath() string
- type AgentOptions
- type AgentRunResponse
- type AutoMode
- type BashDeny
- type BashSection
- type Cast
- type ChatChunk
- type ChatClient
- type ChatMessage
- type ChatRequest
- type ChatResponse
- type Checkpoint
- type CheckpointStore
- type Clearance
- type CostBudget
- type CostTracker
- type DenyPolicy
- type DenyPredicate
- type DenyReason
- type DenyRules
- type Embedder
- type ExtensionHooks
- type FileRef
- type FuncTool
- type GatewayClient
- type GrantKind
- type GrantQuery
- type HashEmbedder
- type HumanApprovalRequest
- type HumanApprovalResponse
- type HumanDecision
- type HumanGate
- type InMemoryCheckpointStore
- type InMemoryKnowledge
- type InMemoryMemory
- type Knowledge
- type KnowledgeHit
- type LexicalReranker
- type LlmProvider
- type Memory
- type MemoryEntry
- type MockLlmProvider
- func (m *MockLlmProvider) CallCount() int
- func (m *MockLlmProvider) Calls() []ChatRequest
- func (m *MockLlmProvider) Chat(_ context.Context, req ChatRequest) (ChatResponse, error)
- func (m *MockLlmProvider) ChatStream(_ context.Context, req ChatRequest) (<-chan ChatChunk, error)
- func (m *MockLlmProvider) LastCall() (ChatRequest, bool)
- func (m *MockLlmProvider) PushError(message string) *MockLlmProvider
- func (m *MockLlmProvider) PushResponse(resp ChatResponse) *MockLlmProvider
- func (m *MockLlmProvider) PushText(content string) *MockLlmProvider
- func (m *MockLlmProvider) PushToolCall(id, name, arguments string) *MockLlmProvider
- type ModelPricing
- type NetworkDeny
- type NetworkSection
- type NodeFn
- type NoopReranker
- type OperatorRole
- type PathsDeny
- type PermissionGate
- type PermissionGrants
- func (g *PermissionGrants) Add(query GrantQuery)
- func (g *PermissionGrants) Clone() *PermissionGrants
- func (g *PermissionGrants) Contains(query GrantQuery) bool
- func (g *PermissionGrants) MatchesBash(command string) bool
- func (g *PermissionGrants) MatchesHost(host string) bool
- func (g *PermissionGrants) MatchesTool(toolName string) bool
- func (g *PermissionGrants) MergeWith(other *PermissionGrants)
- func (g *PermissionGrants) SaveToPath(path string) error
- func (g *PermissionGrants) ToTOMLString() (string, error)
- type Reranker
- type RoleKind
- type Router
- type SharedGrants
- type SmoothAgent
- func (a *SmoothAgent) Run(ctx context.Context, message string, history []ChatMessage) (AgentRunResponse, error)
- func (a *SmoothAgent) RunStream(ctx context.Context, message string, thread *SmoothAgentThread) (*Stream, error)
- func (a *SmoothAgent) RunThread(ctx context.Context, message string, thread *SmoothAgentThread) (AgentRunResponse, error)
- type SmoothAgentThread
- type Stream
- type StreamEvent
- type StreamEventKind
- type StreamingChatClient
- type Tool
- type ToolCall
- type ToolCallDelta
- type ToolHook
- type ToolResult
- type ToolSearch
- func (s *ToolSearch) Description() string
- func (s *ToolSearch) Execute(_ context.Context, args map[string]any) (string, error)
- func (s *ToolSearch) HasDeferred() bool
- func (s *ToolSearch) IsPromoted(name string) bool
- func (s *ToolSearch) Name() string
- func (s *ToolSearch) Parameters() map[string]any
- func (s *ToolSearch) Promote(name string) bool
- func (s *ToolSearch) PromotedTools() []Tool
- func (s *ToolSearch) ToolByName(name string) (Tool, bool)
- type ToolSpec
- type ToolsDeny
- type ToolsSection
- type Usage
- type VectorKnowledge
- type Verdict
- type VerdictKind
- type Workflow
- func (w *Workflow[S]) AddConditionalEdge(from string, router Router[S]) *Workflow[S]
- func (w *Workflow[S]) AddEdge(from, to string) *Workflow[S]
- func (w *Workflow[S]) AddNode(name string, fn NodeFn[S]) *Workflow[S]
- func (w *Workflow[S]) Run(ctx context.Context, initialState S) (S, error)
- func (w *Workflow[S]) SetEnd(from string) *Workflow[S]
- func (w *Workflow[S]) SetEntry(name string) *Workflow[S]
Constants ¶
const END = "__end__"
END is the sentinel a conditional router returns to signal termination.
Variables ¶
var DefaultPricing = map[string]ModelPricing{
"claude-haiku-4-5": {InputPerMTok: 1.0, OutputPerMTok: 5.0},
"claude-sonnet-4-5": {InputPerMTok: 3.0, OutputPerMTok: 15.0},
}
DefaultPricing is approximate (USD / 1M tokens). Override via AgentOptions.Pricing.
Functions ¶
func AppendGrant ¶
func AppendGrant(path string, query GrantQuery) error
AppendGrant loads the grant at path, adds query, and atomically saves. Creates the file if absent. Idempotent for a query that's already stored.
func LoadProjectContext ¶ added in v1.7.12
LoadProjectContext loads the combined project + user context, user-level prepended, with file references in any AGENTS.md / SMOOTH.md resolved inline.
The bool is false only when NEITHER layer found anything — so a workspace with a bare CLAUDE.md and no user-level file still loads context.
func ProjectGrantsPath ¶
ProjectGrantsPath is the project-scope grants file: <workspace>/.smooth/wonk-allow.toml.
func UserGrantsPath ¶
func UserGrantsPath() string
UserGrantsPath is the user-scope grants file: ~/.smooth/wonk-allow.toml. Empty when there is no home dir (minimal CI / broken containers).
Types ¶
type AgentOptions ¶
type AgentOptions struct {
// Extensions wires a SEP extension host into this agent — the Go sibling of
// Rust's `Agent::with_extension_host`. Supply it with
// `extension.NewAgentBridge(host)`. Its tools are merged into the agent's
// tool set, and its hook lanes run at the same points Rust runs them.
// nil (the default) leaves the loop exactly as it was before extensions.
Extensions ExtensionHooks
Instructions string
Model string
MaxIterations int
MaxTokens int
// ModelMaxOutput is the active model's hard output ceiling (its
// max_output_tokens). When set, every request's MaxTokens is clamped to
// min(MaxTokens, *ModelMaxOutput) so a budget/policy MaxTokens (which may be
// tuned high) can never exceed what the model can physically emit — otherwise a
// reasoning model burns its budget on reasoning and returns empty, or the
// upstream 400s (e.g. groq-compound caps output at 8192). nil (the default)
// leaves MaxTokens unclamped. Source it from the gateway's /model/info
// (model_info.max_output_tokens). Mirror of the Rust engine's
// LlmClient.with_model_ceiling (EPIC th-1cc9fa).
ModelMaxOutput *int
Temperature float64
Knowledge Knowledge
KnowledgeTopK int
// Reranker reorders retrieved hits before injection (nil = passthrough).
Reranker Reranker
// KnowledgeCandidateK is the pool size retrieved before reranking; when greater
// than KnowledgeTopK, more docs are fetched, reranked, then trimmed to TopK.
KnowledgeCandidateK int
// Memory, if set, recalls relevant facts into context each turn.
Memory Memory
// MemoryTopK is how many memory entries to recall per turn (0 = default 4).
MemoryTopK int
Tools []Tool
// ParallelToolCalls, when true and an assistant turn returns >=2 tool calls,
// dispatches them concurrently (goroutines + sync.WaitGroup) instead of
// sequentially. Tool-result messages are still appended in the original
// ToolCalls order, so the transcript stays deterministic regardless of
// completion order. Default false preserves the sequential behaviour. Per-tool
// semantics (clearance, human-gate approval, tool_search promotion, JSON
// parsing, error handling) are unchanged — only the dispatch loop runs in parallel.
ParallelToolCalls bool
// DeferredTools are registered but with their schemas HIDDEN from the model.
// When any are present, a built-in tool_search meta-tool is advertised in their
// place; the model calls it to fuzzy-match and promote the ones it needs, which
// then become visible + dispatchable on subsequent turns. Keeps the tool schema
// payload small when there are many rarely-used tools. An unpromoted deferred
// tool is NOT dispatchable.
DeferredTools []Tool
// MaxContextTokens is the approximate token budget for the context window.
// Before each model call, older non-system messages are dropped (sliding
// window) to stay under it. 0 uses the default (8000); negative disables.
MaxContextTokens int
// Budget, if set, stops the turn early once accumulated usage/cost hits it.
Budget *CostBudget
// Pricing overrides the per-model cost table (defaults to DefaultPricing).
Pricing map[string]ModelPricing
// CheckpointStore, with ConversationID, persists/resumes the conversation.
CheckpointStore CheckpointStore
// ConversationID keys the checkpoint store (required to use checkpointing).
ConversationID string
// Clearance, if set, gates which tools may be dispatched. A tool the clearance
// forbids is not executed — a "tool not permitted" result is returned to the
// model instead. Nil allows every tool (the prior behaviour).
Clearance *Clearance
// HumanGate, when set, is asked for approval before running any tool call for
// which RequiresApproval returns true. A denied call is not executed; the model
// is told it was denied and can adapt.
HumanGate HumanGate
// RequiresApproval reports which tool calls need human approval (e.g. writes /
// destructive actions), given the tool name and parsed arguments. nil = none.
// Only consulted when HumanGate is set. Example:
//
// func(name string, _ map[string]any) bool { return name == "delete_record" }
RequiresApproval func(name string, args map[string]any) bool
// PermissionMode, when non-nil, enables the native permission engine (the Go
// port of the Rust PermissionHook — see permission.go / permission_gate.go):
// every tool call is classified by Decide and gated before it runs. A hard
// circuit-breaker (rm -rf /, credential paths, pipe-to-shell, dangerous
// domains, env dumps) is always denied; a mutating/network call Asks (routed
// to HumanGate, or fails closed with no gate); read-only calls Allow. nil (the
// default) disables the engine entirely — dispatch is byte-for-byte unchanged.
// Setting DenyPolicy without PermissionMode enables the engine at
// AutoModeAsk. The HumanGate seam doubles as the Ask approver (an
// ApproveAlways response persists a grant to PermissionGrantsPath).
PermissionMode *AutoMode
// DenyPolicy is a consumer-supplied deny policy (declarative TOML rules +
// predicates) evaluated FIRST on every gated call — a match is a
// circuit-breaker no grant or mode can waive. nil = none. Enables the
// permission engine even when PermissionMode is nil.
DenyPolicy *DenyPolicy
// PermissionGrants is the live allow-list consulted on an Ask before
// prompting; a matching grant auto-approves silently. nil disables persistence.
PermissionGrants *SharedGrants
// PermissionGrantsPath is where an ApproveAlways answer persists a new grant
// (the user-scope wonk-allow.toml). Empty degrades approve-always to approve-once.
PermissionGrantsPath string
// MaxRetries is the number of ADDITIONAL attempts after the first if the model
// call returns a transient error (rate-limit, 5xx, dropped connection). 0 (the
// default) preserves today's behaviour: a single attempt, error returned
// immediately. Only the model call is retried — never tool execution.
MaxRetries int
// RetryBackoff is the base delay for exponential backoff between retries. The
// wait before retry attempt n (1-indexed) is RetryBackoff * 2^(n-1). The zero
// value means no real delay (retries fire immediately) — which is what tests use
// so they don't sleep; production should set a small base such as 200ms.
RetryBackoff time.Duration
// Hooks are ToolHooks run in registration order around every dispatched tool
// call: each PreCall runs before the tool (any error blocks it), each PostCall
// runs after with a mutable *ToolResult it may redact. Nil (the default) → no
// hooks, behaviour unchanged. Mirrors the Rust engine's ToolRegistry hook chain.
Hooks []ToolHook
// Metadata is forwarded verbatim as every model request's top-level
// `metadata` object (LiteLLM spend-log attribution — e.g. an agent slug so
// per-agent LLM spend is queryable at the gateway). A nil or empty map
// sends nothing: the wire stays byte-identical when unset. Mirrors the
// Rust engine's AgentConfig.with_metadata.
Metadata map[string]any
}
AgentOptions configures a SmoothAgent turn. Mirrors the sibling cores' options.
type AgentRunResponse ¶
type AgentRunResponse struct {
Text string
Iterations int
ToolCalls int
Usage Usage
CostUSD float64
// BudgetExceeded is true if the turn stopped because the cost/token budget was hit.
BudgetExceeded bool
}
AgentRunResponse is the result of a turn.
type AutoMode ¶
type AutoMode int
AutoMode is how aggressively the gate enforces. Mirrors smooth's `AutoMode` (a trimmed Claude Code `auto-mode` set). Selected via the SMOOTH_AUTO_MODE env var (see AutoModeFromEnv).
const ( // AutoModeAsk is read-only allow, mutating ask, dangerous deny. Default. AutoModeAsk AutoMode = iota // AutoModeAcceptEdits is like AutoModeAsk but filesystem-edit tools (the // Write category) auto-approve instead of asking. Everything else still // follows the full engine, and the hard circuit-breakers still block. // Mirrors Claude Code's acceptEdits. AutoModeAcceptEdits // AutoModeDenyUnmatched is like AutoModeAsk but never asks — an unmatched // verdict is a deny (fail-closed). The headless / CI posture (Claude Code's // dontAsk). AutoModeDenyUnmatched // AutoModeBypass allows everything except the hard circuit-breakers // (rm -rf /, dangerous domains, credential paths, pipe-to-shell, fork bombs, // env dumps). Escape hatch equivalent to Claude Code's bypassPermissions, // which keeps its circuit-breakers. AutoModeBypass )
func AutoModeFromEnvValue ¶
AutoModeFromEnvValue parses a SMOOTH_AUTO_MODE value. Unknown/empty → AutoModeAsk.
type BashDeny ¶
type BashDeny struct {
DenyPatterns []string `toml:"deny_patterns,omitempty"`
}
BashDeny is `[bash]` — deny bash command prefixes / globs.
type BashSection ¶
type BashSection struct {
AllowPatterns []string `toml:"allow_patterns,omitempty"`
}
BashSection holds command prefixes approved without asking. "cargo " matches `cargo test`, `cargo build`, … — the trailing space guards against `cargonaut`.
type Cast ¶
type Cast struct {
// contains filtered or unexported fields
}
Cast is the registered set of roles a lead can dispatch to. Mirrors the reference engines' Cast.
func (*Cast) Get ¶
func (c *Cast) Get(name string) (OperatorRole, bool)
Get returns the role by name and whether it was found.
func (*Cast) List ¶
func (c *Cast) List() []OperatorRole
List returns all roles in registration order.
func (*Cast) ListVisible ¶
func (c *Cast) ListVisible() []OperatorRole
ListVisible returns the non-hidden roles in registration order.
func (*Cast) Register ¶
func (c *Cast) Register(role OperatorRole) *Cast
Register adds (or replaces) a role and returns the cast for chaining.
func (*Cast) Sidekicks ¶
func (c *Cast) Sidekicks() []OperatorRole
Sidekicks returns the sidekick roles in registration order.
type ChatChunk ¶
type ChatChunk struct {
// ContentDelta is an incremental piece of assistant text ("" when this chunk
// carries no text).
ContentDelta string
// ToolCallDeltas are incremental tool-call fragments in this chunk.
ToolCallDeltas []ToolCallDelta
// Usage, when non-nil, reports cumulative token usage (gateways send it last).
Usage *Usage
// CostUSD, when non-nil, is the gateway's authoritative cost for the whole
// request, read from the response headers before the body was consumed. It
// arrives on the FIRST chunk, not the last.
CostUSD *float64
}
ChatChunk is one streamed chunk from a streaming chat completion — the standard OpenAI streaming chunk shape (the slice the agent reads). Content deltas concatenate into the assistant text; tool-call fragments are assembled by their Index (ID + Function.Name appear when a call first opens, Function.Arguments arrives in fragments). Usage is non-nil on (typically) the final chunk.
type ChatClient ¶
type ChatClient interface {
Chat(ctx context.Context, req ChatRequest) (ChatResponse, error)
}
ChatClient is the minimal OpenAI-compatible surface the agent needs. The GatewayClient implements it against a live endpoint; tests inject a fake.
type ChatMessage ¶
type ChatMessage struct {
Role string
Content string
ToolCalls []ToolCall
ToolCallID string // set on role=="tool" messages
}
ChatMessage is one message in the OpenAI-shaped conversation.
type ChatRequest ¶
type ChatRequest struct {
Model string
Messages []ChatMessage
Tools []ToolSpec
Temperature float64
MaxTokens int
// Metadata is an optional opaque object forwarded as the top-level
// `metadata` field of the OpenAI-compatible request body (LiteLLM records
// it on spend logs, giving per-caller cost attribution at the gateway).
// nil means the field is omitted from the wire entirely; the agent
// normalizes an empty map to nil so unset stays byte-identical. Mirrors
// the Rust engine's ChatRequest.metadata (with_metadata).
Metadata map[string]any
}
ChatRequest is a single model call.
type ChatResponse ¶
type ChatResponse struct {
Content string
ToolCalls []ToolCall
Usage Usage
// GatewayCostUSD is the gateway's AUTHORITATIVE cost for this request, read
// from its response header. nil means "unmeasured" — the caller falls back to
// local ModelPricing. It is deliberately not 0: a real zero and an absent
// header must stay distinct, or a gateway that reports no cost silently pins
// spend at zero.
GatewayCostUSD *float64
}
ChatResponse is the assistant's reply (content and/or tool calls).
func TextResponse ¶
func TextResponse(content string) ChatResponse
TextResponse builds a plain-text ChatResponse (no tool calls). Handy for scripting the mock and for assertions.
func ToolCallResponse ¶
func ToolCallResponse(id, name, arguments string) ChatResponse
ToolCallResponse builds a ChatResponse that requests a single tool call. arguments is the raw JSON-string the model emits for the call's arguments.
func WithUsage ¶
func WithUsage(resp ChatResponse, promptTokens, completionTokens int) ChatResponse
WithUsage returns a copy of resp with the given token usage attached. Handy when scripting the mock so the streaming final chunk / non-streaming Usage is non-zero.
type Checkpoint ¶
type Checkpoint struct {
ConversationID string
Messages []ChatMessage
}
Checkpoint is a saved conversation: its id and the non-system messages so far.
type CheckpointStore ¶
type CheckpointStore interface {
Save(cp Checkpoint)
Load(conversationID string) (Checkpoint, bool)
}
CheckpointStore persists and restores conversations by id.
type Clearance ¶
type Clearance struct {
// contains filtered or unexported fields
}
Clearance is a tool-access policy for a role. A deny always wins; a non-empty AllowTools is a whitelist; empty allow + empty deny means "all tools". DenyEverything blocks every tool regardless of the lists.
func AllowAllClearance ¶
func AllowAllClearance() Clearance
AllowAllClearance permits every tool (the zero-value default).
func AllowClearance ¶
AllowClearance whitelists exactly the named tools.
func DenyClearance ¶
DenyClearance blocks the named tools (everything else allowed).
func NewClearance ¶
NewClearance builds a clearance from explicit allow/deny lists and the deny-everything flag.
type CostBudget ¶
CostBudget is a ceiling for a turn. A zero field means "unset"; the first non-zero limit that is hit stops the turn.
type CostTracker ¶
CostTracker accumulates usage + cost across a turn's model calls.
func (*CostTracker) Exceeds ¶
func (t *CostTracker) Exceeds(b *CostBudget) bool
Exceeds reports whether the accumulated usage/cost has hit the budget.
func (*CostTracker) Record ¶
func (t *CostTracker) Record(model string, u Usage, pricing map[string]ModelPricing)
Record adds a model call's usage (and its cost, if the model is priced).
func (*CostTracker) RecordWithGatewayCost ¶ added in v1.7.10
func (t *CostTracker) RecordWithGatewayCost(model string, u Usage, gatewayCostUSD *float64, pricing map[string]ModelPricing)
RecordWithGatewayCost records usage, preferring the gateway's authoritative per-request cost when it measured one. A nil cost means "unmeasured" and falls back to the local ModelPricing estimate — which is the whole reason the header parser returns nil rather than 0. Aliased models (smooth-*) price at $0 locally, so this is often the only real number available.
type DenyPolicy ¶
type DenyPolicy struct {
// contains filtered or unexported fields
}
DenyPolicy is a consumer-supplied deny policy: declarative rules + predicate checks. Attach to the gate via PermissionGate.DenyPolicy or the agent options. An empty policy is a no-op.
func DenyPolicyFromTOML ¶
func DenyPolicyFromTOML(tomlText string) (*DenyPolicy, error)
DenyPolicyFromTOML builds the declarative half from a TOML string. Predicates are added separately via WithPredicate.
func NewDenyPolicy ¶
func NewDenyPolicy() *DenyPolicy
NewDenyPolicy returns an empty policy — denies nothing (the additive no-op default).
func (*DenyPolicy) Evaluate ¶
Evaluate returns the deny reason for a call, or ("", false) to let it fall through to the rest of the permission engine. Declarative rules are checked first, then predicates; the first match wins.
func (*DenyPolicy) IsEmpty ¶
func (p *DenyPolicy) IsEmpty() bool
IsEmpty reports whether there are no rules and no predicates.
func (*DenyPolicy) WithDeclarative ¶
func (p *DenyPolicy) WithDeclarative(rules DenyRules) *DenyPolicy
WithDeclarative replaces the declarative rules. Chainable.
func (*DenyPolicy) WithPredicate ¶
func (p *DenyPolicy) WithPredicate(predicate DenyPredicate) *DenyPolicy
WithPredicate adds a consumer predicate. Chainable.
type DenyPredicate ¶
type DenyPredicate interface {
// Evaluate returns (reason, true) to deny the call, or (_, false) to let it
// fall through to the rest of the permission engine.
Evaluate(name string, args map[string]any) (DenyReason, bool)
}
DenyPredicate is a consumer-supplied semantic deny check. Runs on every gated tool call; an ok=true return is a hard deny (circuit-breaker tier). Use it for checks the declarative rules can't express from strings alone — resolving an AWS call to its account, a DB URL to writer-vs-replica, etc.
type DenyReason ¶
type DenyReason struct {
Reason string
}
DenyReason is why a DenyPredicate blocks a call. A thin wrapper over string so the predicate contract is explicit and can grow structured fields later.
func NewDenyReason ¶
func NewDenyReason(reason string) DenyReason
NewDenyReason builds a DenyReason.
type DenyRules ¶
type DenyRules struct {
SchemaVersion int `toml:"schema_version"`
Tools ToolsDeny `toml:"tools,omitempty"`
Bash BashDeny `toml:"bash,omitempty"`
Network NetworkDeny `toml:"network,omitempty"`
Paths PathsDeny `toml:"paths,omitempty"`
}
DenyRules is the declarative half of a DenyPolicy: four deny lists from TOML.
func NewDenyRules ¶
func NewDenyRules() DenyRules
NewDenyRules returns empty rules pinned at the current schema version.
func ParseDenyRules ¶
ParseDenyRules parses rules from a TOML string. Missing sections default empty.
func (DenyRules) ToTOMLString ¶
ToTOMLString serializes to TOML.
type ExtensionHooks ¶ added in v1.7.6
type ExtensionHooks interface {
// ExtensionTools are the host's eager tools, already namespaced
// `<extension>.<tool>`. They are merged into the agent's tool set as
// ORDINARY tools, so they are visible to the model, dispatched, and gated by
// exactly the same permission machinery as native tools — no special casing.
ExtensionTools() []Tool
// ExtensionDeferredTools are the host's deferred tools: hidden from the model
// until `tool_search` promotes them.
ExtensionDeferredTools() []Tool
// RunToolCallHook folds the `tool_call` hook chain over one pending call
// BEFORE it executes. Returns whether the call is vetoed (with the reason),
// and the possibly-rewritten arguments to run with.
//
// Rewrites are already scoped by the host's cross-tool guard: an extension
// may only rewrite the arguments of a tool it owns, and may never redirect
// the call to a different tool.
RunToolCallHook(ctx context.Context, tool string, arguments string) (blocked bool, reason string, patched string)
// DispatchEvent fans a turn event out to subscribed extensions. Fire and
// forget: observe events are lossy by contract and never block the turn.
DispatchEvent(event string, payload json.RawMessage)
}
ExtensionHooks is the seam through which a SEP extension host participates in the agent loop — the Go sibling of Rust's `Agent::with_extension_host`.
It is an INTERFACE rather than a concrete `*extension.ExtensionHost` because the dependency runs the other way: `go/core/extension` imports `go/core` (an `ExtensionTool` is a `core.Tool`), so `core` importing `extension` back would be a cycle. Every signature here is expressible in `core` + stdlib alone, and `extension.NewAgentBridge(host)` supplies the implementation.
Nil (the default) means the agent loop behaves exactly as it did before extensions existed — no dispatch, no hook calls, no allocation.
type FileRef ¶ added in v1.7.12
type FileRef struct {
// Label is the display label from the markdown link text.
Label string
// Path is the relative file path (without fragment).
Path string
// Fragment optionally points at a heading within Path.
Fragment *string
// Description is the optional text after the ` — `.
Description *string
}
FileRef is a parsed file reference from the `## File References` section. Fragment and Description are nil when absent (Rust's `Option<String>`).
func ParseFileReferences ¶ added in v1.7.12
ParseFileReferences parses the `## File References` section out of AGENTS.md content. Expects markdown list items like:
- [Label](path.md) — description
- [Label](path.md#fragment) — description
type FuncTool ¶
type FuncTool struct {
ToolName string
Desc string
Params map[string]any
Fn func(ctx context.Context, args map[string]any) (string, error)
}
FuncTool wraps a function as a Tool (the AIFunctionFactory analogue).
func (FuncTool) Description ¶
func (FuncTool) Parameters ¶
type GatewayClient ¶
type GatewayClient struct {
BaseURL string // e.g. https://llm.smoo.ai/v1
APIKey string
HTTPClient *http.Client
}
GatewayClient is an OpenAI-compatible ChatClient over HTTP — the Go analogue of the other cores' OpenAI SDK client. Points at any /chat/completions endpoint (e.g. the SmooAI gateway) with a Bearer API key.
(Phase 0 uses net/http directly, mirroring how the sibling cores' OpenAI SDKs do their own HTTP. Adopting @smooai/fetch's Go client is a tracked follow-up.)
func NewGatewayClient ¶
func NewGatewayClient(baseURL, apiKey string) *GatewayClient
NewGatewayClient builds a client for the given base URL + key.
func (*GatewayClient) Chat ¶
func (g *GatewayClient) Chat(ctx context.Context, req ChatRequest) (ChatResponse, error)
Chat implements ChatClient.
func (*GatewayClient) ChatStream ¶
func (g *GatewayClient) ChatStream(ctx context.Context, req ChatRequest) (<-chan ChatChunk, error)
ChatStream implements StreamingChatClient: it opens an SSE streaming completion and translates each `data: {...}` line into a ChatChunk on the returned channel. Connect-time failures (request build / HTTP / non-2xx) come back as the error; the channel is closed when the SSE stream ends (`data: [DONE]` or EOF).
type GrantQuery ¶
GrantQuery is the kind of resource a grant covers — one of the three grantable Ask shapes. (Deny circuit-breakers are never grantable.)
type HashEmbedder ¶
type HashEmbedder struct {
Dim int
}
HashEmbedder is a deterministic, offline feature-hashing embedder. It hashes each token into one of dim buckets (signed) and L2-normalizes. No learned semantics, but a real vector with cosine geometry — docs sharing tokens land near each other.
func NewHashEmbedder ¶
func NewHashEmbedder(dim int) HashEmbedder
NewHashEmbedder returns a HashEmbedder with the given dimension (default 256).
func (HashEmbedder) Embed ¶
func (e HashEmbedder) Embed(text string) []float64
Embed hashes tokens into a normalized vector.
type HumanApprovalRequest ¶
HumanApprovalRequest is sent before the agent executes a sensitive/write tool. Mirrors the C# HumanApprovalRequest / the Rust engine's HumanRequest::Confirm.
type HumanApprovalResponse ¶
type HumanApprovalResponse struct {
Decision HumanDecision
Reason string
}
HumanApprovalResponse is the answer to a HumanApprovalRequest. Mirrors the C# HumanApprovalResponse.
func ApproveAlways ¶
func ApproveAlways() HumanApprovalResponse
ApproveAlways builds an approval that also persists a permission grant.
func Deny ¶
func Deny(reason string) HumanApprovalResponse
Deny builds a denial carrying a reason the model will see.
func (HumanApprovalResponse) IsApproved ¶
func (r HumanApprovalResponse) IsApproved() bool
IsApproved reports whether the decision lets the tool run (HumanApproved or HumanApprovedAlways).
func (HumanApprovalResponse) IsApprovedAlways ¶
func (r HumanApprovalResponse) IsApprovedAlways() bool
IsApprovedAlways reports whether the human asked to persist a grant.
type HumanDecision ¶
type HumanDecision int
HumanDecision is the human's verdict on a tool call that required approval.
const ( // HumanApproved lets the tool run. HumanApproved HumanDecision = iota // HumanDenied blocks the tool; the reason is fed back to the model. HumanDenied // HumanApprovedAlways lets the tool run AND asks the permission gate to // persist a matching grant so identical future Asks auto-approve without // prompting (see permission_grants.go). Used only by the PermissionGate Ask // flow; the RequiresApproval path treats it exactly like HumanApproved. HumanApprovedAlways )
type HumanGate ¶
type HumanGate func(ctx context.Context, request HumanApprovalRequest) (HumanApprovalResponse, error)
HumanGate is the human-in-the-loop seam: the agent consults it before running any tool that AgentOptions.RequiresApproval flags. The implementation IS the pause point — wire it to a UI awaiting a real person, or decide programmatically. Mirrors the C# IHumanGate (here a func, the idiomatic Go seam).
type InMemoryCheckpointStore ¶
type InMemoryCheckpointStore struct {
// contains filtered or unexported fields
}
InMemoryCheckpointStore is a process-local store backed by a map.
func NewInMemoryCheckpointStore ¶
func NewInMemoryCheckpointStore() *InMemoryCheckpointStore
NewInMemoryCheckpointStore creates an empty in-memory store.
func (*InMemoryCheckpointStore) Load ¶
func (s *InMemoryCheckpointStore) Load(conversationID string) (Checkpoint, bool)
Load returns the checkpoint for an id, and whether one was found.
func (*InMemoryCheckpointStore) Save ¶
func (s *InMemoryCheckpointStore) Save(cp Checkpoint)
Save persists a copy of the checkpoint's messages.
type InMemoryKnowledge ¶
type InMemoryKnowledge struct {
// contains filtered or unexported fields
}
InMemoryKnowledge is a tiny lexical-overlap knowledge base — Phase-0 parity with the reference engines' in-memory lexical store (not a vector store).
func (*InMemoryKnowledge) Ingest ¶
func (k *InMemoryKnowledge) Ingest(content, source string)
Ingest adds a document to the knowledge base.
func (*InMemoryKnowledge) Query ¶
func (k *InMemoryKnowledge) Query(query string, topK int) []KnowledgeHit
Query returns up to topK documents, ranked by token overlap with the query. When nothing overlaps, the first topK documents are returned anyway so the agent still has context to ground (or honestly decline) against.
type InMemoryMemory ¶
type InMemoryMemory struct {
// contains filtered or unexported fields
}
InMemoryMemory is a process-local memory pool with lexical-overlap recall.
func (*InMemoryMemory) Recall ¶
func (m *InMemoryMemory) Recall(query string, topK int) []MemoryEntry
Recall returns up to topK entries that share terms with the query, best first.
func (*InMemoryMemory) Remember ¶
func (m *InMemoryMemory) Remember(text string)
Remember adds a fact (blank entries are ignored).
type Knowledge ¶
type Knowledge interface {
Query(query string, topK int) []KnowledgeHit
}
Knowledge is a retriever: returns the most relevant documents for a query. Both the lexical InMemoryKnowledge and the embedding-backed VectorKnowledge satisfy this, so the agent accepts either.
type KnowledgeHit ¶
KnowledgeHit is one retrieved document with its lexical-overlap score.
type LexicalReranker ¶
type LexicalReranker struct{}
LexicalReranker reorders by query-term coverage normalized by document length: coverage / log2(2 + docTokenCount), so coverage is rewarded but long documents are penalized relative to concise ones with the same coverage. Stable for ties.
func (LexicalReranker) Rerank ¶
func (LexicalReranker) Rerank(query string, hits []KnowledgeHit) []KnowledgeHit
Rerank reorders hits by the normalized-coverage score.
type LlmProvider ¶
type LlmProvider = ChatClient
LlmProvider is the LLM-call seam the agent loop depends on. It is the existing ChatClient interface under a name that names the role — formalizing the seam so the agent loop is unit-testable deterministically, without a live model or network. The GatewayClient already implements it; tests inject a MockLlmProvider.
This keeps backward compatibility: NewSmoothAgent still takes a ChatClient, and any LlmProvider is a ChatClient (and vice versa) since they are the same shape.
type Memory ¶
type Memory interface {
Remember(text string)
Recall(query string, topK int) []MemoryEntry
}
Memory is a pool of remembered facts, recalled by relevance to a query.
type MockLlmProvider ¶
type MockLlmProvider struct {
// contains filtered or unexported fields
}
MockLlmProvider is a deterministic LlmProvider for tests. Script the responses it should return (FIFO), drive your code, then assert on Calls. Build it up fluently with PushText / PushToolCall / PushError.
It replaces the ad-hoc fakeClient the tests rolled by hand, and mirrors the BEHAVIOR of the Rust reference's MockLlmClient (record + replay). It is not safe for concurrent use — a turn drives it serially, which is the intended use.
func NewMockLlmProvider ¶
func NewMockLlmProvider() *MockLlmProvider
NewMockLlmProvider returns an empty mock. Script it with the Push* methods.
func (*MockLlmProvider) CallCount ¶
func (m *MockLlmProvider) CallCount() int
CallCount returns the number of requests received.
func (*MockLlmProvider) Calls ¶
func (m *MockLlmProvider) Calls() []ChatRequest
Calls returns every request the mock has received so far, in order.
func (*MockLlmProvider) Chat ¶
func (m *MockLlmProvider) Chat(_ context.Context, req ChatRequest) (ChatResponse, error)
Chat implements ChatClient / LlmProvider: it records the request, then replays the next scripted outcome. With an empty script it returns a benign empty text response so loops terminate cleanly.
func (*MockLlmProvider) ChatStream ¶
func (m *MockLlmProvider) ChatStream(_ context.Context, req ChatRequest) (<-chan ChatChunk, error)
ChatStream implements StreamingChatClient: it records the request, then replays the SAME next scripted outcome as Chat, but as chunked deltas. Text is split into a few content-delta chunks; each tool call is split into an opening chunk (ID + name + first half of arguments) and a second chunk with the rest of the arguments (exercising the agent's index-keyed accumulator); a final chunk carries usage. A scripted error is returned synchronously (connect-time), mirroring a failed open.
func (*MockLlmProvider) LastCall ¶
func (m *MockLlmProvider) LastCall() (ChatRequest, bool)
LastCall returns the most recent request and true, or a zero request and false if none have been received.
func (*MockLlmProvider) PushError ¶
func (m *MockLlmProvider) PushError(message string) *MockLlmProvider
PushError queues an error to be returned from the next Chat call.
func (*MockLlmProvider) PushResponse ¶
func (m *MockLlmProvider) PushResponse(resp ChatResponse) *MockLlmProvider
PushResponse queues a raw ChatResponse for the next Chat call.
func (*MockLlmProvider) PushText ¶
func (m *MockLlmProvider) PushText(content string) *MockLlmProvider
PushText queues a plain-text response for the next Chat call.
func (*MockLlmProvider) PushToolCall ¶
func (m *MockLlmProvider) PushToolCall(id, name, arguments string) *MockLlmProvider
PushToolCall queues a single-tool-call response for the next Chat call.
type ModelPricing ¶
ModelPricing is USD per 1,000,000 tokens, input and output.
func (ModelPricing) Cost ¶
func (p ModelPricing) Cost(u Usage) float64
Cost converts usage to USD at this pricing.
type NetworkDeny ¶
type NetworkDeny struct {
DenyHosts []string `toml:"deny_hosts,omitempty"`
}
NetworkDeny is `[network]` — deny host suffixes / globs.
type NetworkSection ¶
type NetworkSection struct {
AllowHosts []string `toml:"allow_hosts,omitempty"`
}
NetworkSection holds hosts (or *.suffix globs) approved without asking.
type NodeFn ¶
NodeFn transforms state into a new state. It receives a context so nodes can do async/IO work, and may return an error to abort the run.
type NoopReranker ¶
type NoopReranker struct{}
NoopReranker returns the hits unchanged — the zero-cost default.
func (NoopReranker) Rerank ¶
func (NoopReranker) Rerank(_ string, hits []KnowledgeHit) []KnowledgeHit
Rerank returns hits unchanged.
type OperatorRole ¶
type OperatorRole struct {
Name string
Kind RoleKind
Instructions string
Permissions Clearance
MaxIterations int
// Hidden roles are omitted from ListVisible (still dispatchable by name).
Hidden bool
}
OperatorRole is a named role in the cast — its kind, instructions, tool clearance, and iteration budget. Mirrors the reference engines' OperatorRole.
func NewOperatorRole ¶
func NewOperatorRole(name string, kind RoleKind, instructions string) OperatorRole
NewOperatorRole builds a role with the reference-engine defaults applied (allow-all clearance, 8 iterations).
type PathsDeny ¶
type PathsDeny struct {
Deny []string `toml:"deny,omitempty"`
}
PathsDeny is `[paths]` — deny file paths / globs (Write + Read tools).
type PermissionGate ¶
type PermissionGate struct {
// Mode is how aggressively Decide enforces.
Mode AutoMode
// Grants is the live merged allow-list consulted before prompting on an Ask.
// nil disables persistence — every Ask prompts (approve-once).
Grants *SharedGrants
// PersistPath is where an ApprovedAlways grant is written (the user-scope
// file). Empty means approve-always degrades to approve-once.
PersistPath string
// DenyPolicy is the consumer deny policy, evaluated first. nil = none.
DenyPolicy *DenyPolicy
// Approver routes an Ask verdict to a human. nil fails closed (Ask blocks).
Approver HumanGate
}
PermissionGate enforces the permission engine on a single tool call.
type PermissionGrants ¶
type PermissionGrants struct {
SchemaVersion int `toml:"schema_version"`
Network NetworkSection `toml:"network,omitempty"`
Tools ToolsSection `toml:"tools,omitempty"`
Bash BashSection `toml:"bash,omitempty"`
}
PermissionGrants is the in-memory snapshot of wonk-allow.toml.
func LoadLayeredGrants ¶
func LoadLayeredGrants(userPath, projectPath string) (*PermissionGrants, error)
LoadLayeredGrants loads user + project files and merges them (project last so its schema_version wins; entries union either way). Either path empty is fine; a malformed file present is an error.
func LoadPermissionGrants ¶
func LoadPermissionGrants(path string) (*PermissionGrants, error)
LoadPermissionGrants loads from path. A missing file yields an empty (v1) store — NOT an error. A malformed file surfaces the parse error.
func NewPermissionGrants ¶
func NewPermissionGrants() *PermissionGrants
NewPermissionGrants returns grants pinned at the current schema version.
func ParsePermissionGrants ¶
func ParsePermissionGrants(tomlText string) (*PermissionGrants, error)
ParsePermissionGrants parses grants from a TOML string. Missing sections default to empty.
func (*PermissionGrants) Add ¶
func (g *PermissionGrants) Add(query GrantQuery)
Add adds a grant. Idempotent; keeps each section sorted+unique for stable output.
func (*PermissionGrants) Clone ¶
func (g *PermissionGrants) Clone() *PermissionGrants
Clone returns a deep copy.
func (*PermissionGrants) Contains ¶
func (g *PermissionGrants) Contains(query GrantQuery) bool
Contains reports whether query's exact entry is already stored.
func (*PermissionGrants) MatchesBash ¶
func (g *PermissionGrants) MatchesBash(command string) bool
MatchesBash reports whether command starts with any [bash] allow prefix.
func (*PermissionGrants) MatchesHost ¶
func (g *PermissionGrants) MatchesHost(host string) bool
MatchesHost reports whether host is covered by the [network] allow-list.
func (*PermissionGrants) MatchesTool ¶
func (g *PermissionGrants) MatchesTool(toolName string) bool
MatchesTool reports whether toolName is in the [tools] allow-list (exact match).
func (*PermissionGrants) MergeWith ¶
func (g *PermissionGrants) MergeWith(other *PermissionGrants)
MergeWith unions other into g.
func (*PermissionGrants) SaveToPath ¶
func (g *PermissionGrants) SaveToPath(path string) error
SaveToPath atomically writes g to path (tempfile + rename), creating parent dirs.
func (*PermissionGrants) ToTOMLString ¶
func (g *PermissionGrants) ToTOMLString() (string, error)
ToTOMLString serializes to TOML.
type Reranker ¶
type Reranker interface {
Rerank(query string, hits []KnowledgeHit) []KnowledgeHit
}
Reranker reorders retrieved hits by relevance to the query.
type SharedGrants ¶
type SharedGrants struct {
// contains filtered or unexported fields
}
SharedGrants is a thread-safe, cheaply-shared handle to the live merged grants. Reads take a snapshot; approve-always merges the freshly-persisted grant back in.
func NewSharedGrants ¶
func NewSharedGrants(grants *PermissionGrants) *SharedGrants
NewSharedGrants wraps grants for concurrent access.
func (*SharedGrants) MergeIn ¶
func (s *SharedGrants) MergeIn(other *PermissionGrants)
MergeIn unions other into the live grants.
func (*SharedGrants) Snapshot ¶
func (s *SharedGrants) Snapshot() *PermissionGrants
Snapshot returns a cloned-out copy for lock-free matching.
type SmoothAgent ¶
type SmoothAgent struct {
// contains filtered or unexported fields
}
SmoothAgent is a native, in-process agent.
func NewSmoothAgent ¶
func NewSmoothAgent(client ChatClient, options AgentOptions) *SmoothAgent
NewSmoothAgent constructs an agent over an OpenAI-compatible ChatClient.
func (*SmoothAgent) Run ¶
func (a *SmoothAgent) Run(ctx context.Context, message string, history []ChatMessage) (AgentRunResponse, error)
Run executes a single turn. history is prior conversation messages (multi-turn).
func (*SmoothAgent) RunStream ¶
func (a *SmoothAgent) RunStream(ctx context.Context, message string, thread *SmoothAgentThread) (*Stream, error)
RunStream streams a single turn, delivering incremental StreamEvents on the returned channel. It drives the SAME agentic loop as Run (system/knowledge/memory build, seed messages, per-iteration compaction, cost tracking, budget early-stop, deferred-tool specs, clearance + human-gate on dispatch, checkpoint/thread persistence on exit) — but calls the model in STREAMING mode and emits events as work happens:
- a StreamText event per non-empty content delta as it streams in;
- a StreamToolCall event per requested tool call, after that iteration's model stream ends, BEFORE the call is dispatched;
- a StreamToolResult event per tool, after it finishes (in original call order even when ParallelToolCalls runs them concurrently);
- exactly one terminal StreamDone event carrying the same AgentRunResponse Run would return for the same script.
Error contract (idiomatic Go): the client must implement StreamingChatClient — if it does not, RunStream returns a nil channel and a non-nil error synchronously and runs nothing. Once the turn is running, a model-call error aborts it: the channel is closed WITHOUT a StreamDone and the error is stored, retrievable via the returned *Stream's Err() after the channel drains. So a caller ranges the channel to completion, then checks Err(); a clean turn ends with a StreamDone and Err()==nil.
NOTE: retry-with-backoff (MaxRetries/RetryBackoff) is intentionally NOT applied to the streaming model call — re-running it after a mid-stream failure would re-emit already-yielded chunks. Retry stays scoped to non-streaming Run (see callModel); this mirrors the C# RunStreamingAsync decision.
func (*SmoothAgent) RunThread ¶
func (a *SmoothAgent) RunThread(ctx context.Context, message string, thread *SmoothAgentThread) (AgentRunResponse, error)
RunThread executes a single turn carried by a SmoothAgentThread: the turn is seeded from the thread's messages, and this turn's new user + assistant (+ tool) messages are appended back to the thread before returning. The thread takes precedence over any history as the prior context. Run (single-shot/history) keeps working unchanged.
type SmoothAgentThread ¶
type SmoothAgentThread struct {
// ID is the stable id for this conversation (the key checkpoints store under).
ID string
// contains filtered or unexported fields
}
SmoothAgentThread is a conversation thread: a stable id plus the ordered non-system messages so far.
func NewThread ¶
func NewThread() *SmoothAgentThread
NewThread creates a fresh thread with an auto-generated id.
func NewThreadWithID ¶
func NewThreadWithID(id string) *SmoothAgentThread
NewThreadWithID resumes a thread under a known id (e.g. one recovered from a checkpoint). An empty id falls back to a fresh auto-generated one.
func (*SmoothAgentThread) Add ¶
func (t *SmoothAgentThread) Add(m ChatMessage)
Add appends one message, skipping any system message (rebuilt per-run).
func (*SmoothAgentThread) Extend ¶
func (t *SmoothAgentThread) Extend(msgs []ChatMessage)
Extend appends several messages, skipping any system messages.
func (*SmoothAgentThread) Len ¶
func (t *SmoothAgentThread) Len() int
Len returns the number of messages currently in the thread.
func (*SmoothAgentThread) Messages ¶
func (t *SmoothAgentThread) Messages() []ChatMessage
Messages returns the accumulated history, oldest first (no system prompt).
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
Stream is the handle RunStream returns: range Events() to consume the turn's StreamEvents, then call Err() (after the channel drains) to see whether the turn aborted with a model error.
func (*Stream) Err ¶
Err returns the error that aborted the turn, or nil if it completed cleanly. Call it only after Events() has been fully drained (the channel closed).
func (*Stream) Events ¶
func (s *Stream) Events() <-chan StreamEvent
Events returns the channel of streamed events. It is closed when the turn ends.
type StreamEvent ¶
type StreamEvent struct {
Kind StreamEventKind
Text string // StreamText
Name string // StreamToolCall / StreamToolResult
Arguments string // StreamToolCall
Result string // StreamToolResult
// Details carries the structured, UI-facing payload a PostCall hook
// attached to the ToolResult (nil when none) — forwarded verbatim and
// un-truncated on StreamToolResult, never shown to the model. Mirrors the
// Rust engine's AgentEvent::ToolCallComplete.details.
Details any // StreamToolResult
Response AgentRunResponse // StreamDone
}
StreamEvent is one event from RunStream. The Kind field selects which payload fields are populated, mirroring the C# RunStreamingAsync update sequence and the Rust reference engine's event stream:
- StreamText: Text holds the content delta.
- StreamToolCall: Name + Arguments hold the requested call.
- StreamToolResult: Name + Result hold a finished tool's result.
- StreamDone: Response holds the final AgentRunResponse (the same value Run would return for the same script). Exactly one StreamDone is emitted, last, UNLESS the turn ends in an error (see RunStream's error contract).
type StreamEventKind ¶
type StreamEventKind int
StreamEventKind tags a StreamEvent.
const ( // StreamText is an incremental assistant content delta as it streams in. StreamText StreamEventKind = iota // StreamToolCall is a tool call the model requested, emitted once before dispatch. StreamToolCall // StreamToolResult is a tool's result, emitted after it finishes. StreamToolResult // StreamDone is the single terminal event, carrying the final AgentRunResponse. StreamDone )
type StreamingChatClient ¶
type StreamingChatClient interface {
ChatClient
ChatStream(ctx context.Context, req ChatRequest) (<-chan ChatChunk, error)
}
StreamingChatClient is the OPTIONAL streaming surface. A ChatClient that also implements it can drive RunStream; the GatewayClient and MockLlmProvider both do. ChatStream opens a streaming model call and returns a receive-only channel of chunks. The channel is closed when the stream ends; any error is delivered via the returned error (for connect-time failures) or — for a mid-stream failure — stored and reported as documented by the implementation. Production wires this to the OpenAI `create(..., stream=True)` surface.
type Tool ¶
type Tool interface {
Name() string
Description() string
Parameters() map[string]any
Execute(ctx context.Context, args map[string]any) (string, error)
}
Tool is a callable the agent may invoke.
func DelegateTool ¶
func DelegateTool(name, description string, child *SmoothAgent) Tool
DelegateTool builds a Tool that delegates a subtask to a child SmoothAgent.
A sub-agent is just a tool backed by another agent: the model calls this tool with a "task" argument, the child agent runs that task, and the child's final reply becomes the tool result — composing with the existing tool loop, no special wiring. The child can have its own instructions, tools, knowledge, etc.
type ToolCallDelta ¶
type ToolCallDelta struct {
Index int // which tool call this fragment belongs to
ID string // set when the call first opens ("" in later fragments)
Name string // set when the call first opens ("" in later fragments)
ArgsFragment string // a fragment of the JSON arguments to append
}
ToolCallDelta is one tool-call fragment within a streamed chunk.
type ToolHook ¶ added in v1.7.1
type ToolHook interface {
// PreCall runs before a tool executes. Returning a non-nil error blocks the
// call: the tool never runs and the model is told it was blocked.
PreCall(ctx context.Context, call ToolCall) error
// PostCall runs after a tool executes, with a mutable *ToolResult it may
// rewrite (the redaction seam). A returned error is ignored — the
// (possibly redacted) result still reaches the model — matching the Rust
// engine, where a post-hook failure is logged, not surfaced.
PostCall(ctx context.Context, call ToolCall, result *ToolResult) error
}
ToolHook observes and can gate/redact tool calls, mirroring the Rust engine's ToolHook lifecycle (pre_call / post_call). Hooks are registered via AgentOptions.Hooks and run in registration order around every dispatched tool call. A hook must be safe for concurrent use: with ParallelToolCalls the engine may run PreCall/PostCall from multiple goroutines at once.
type ToolResult ¶ added in v1.7.1
type ToolResult struct {
// ToolCallID is the id of the ToolCall this result answers.
ToolCallID string
// Content is the text the model sees. A PostCall hook may mutate it.
Content string
// IsError is true when the tool failed (or a PreCall hook blocked it).
IsError bool
// Details is optional structured, UI-facing data (diffs, tables, trace
// ids) a PostCall hook may attach. It is forwarded verbatim on the
// stream's StreamToolResult event and never reaches the model. Mirrors
// the Rust engine's ToolResult.details.
Details any
}
ToolResult is the outcome of a single tool call. It is handed to ToolHook.PostCall as a mutable pointer so a hook can rewrite Content before it reaches the model — the redaction seam (e.g. scrubbing a leaked secret from a tool's output). Mirrors the Rust engine's ToolResult.
type ToolSearch ¶
type ToolSearch struct {
// contains filtered or unexported fields
}
ToolSearch drives deferred-tool promotion for one agent run. It implements Tool so the agent can advertise + dispatch it like any other tool. It holds the deferred tools (by name) and the mutable set of promoted names; the agent consults PromotedTools each iteration to decide which deferred schemas are now visible/dispatchable.
func NewToolSearch ¶
func NewToolSearch(deferred []Tool) *ToolSearch
NewToolSearch builds a ToolSearch over the given deferred tools.
func (*ToolSearch) Description ¶
func (s *ToolSearch) Description() string
func (*ToolSearch) Execute ¶
Execute fuzzy-matches the query, promotes matches, and returns their schemas as JSON.
func (*ToolSearch) HasDeferred ¶
func (s *ToolSearch) HasDeferred() bool
HasDeferred reports whether any tool was registered deferred (the meta-tool is advertised only then).
func (*ToolSearch) IsPromoted ¶
func (s *ToolSearch) IsPromoted(name string) bool
IsPromoted reports whether a deferred tool has been promoted and is now dispatchable.
func (*ToolSearch) Name ¶
func (s *ToolSearch) Name() string
func (*ToolSearch) Parameters ¶
func (s *ToolSearch) Parameters() map[string]any
func (*ToolSearch) Promote ¶
func (s *ToolSearch) Promote(name string) bool
Promote marks a deferred tool promoted. Returns false if no such deferred tool.
func (*ToolSearch) PromotedTools ¶
func (s *ToolSearch) PromotedTools() []Tool
PromotedTools returns the deferred tools that have been promoted — their schemas join the visible set. Returned in registration order for determinism.
func (*ToolSearch) ToolByName ¶
func (s *ToolSearch) ToolByName(name string) (Tool, bool)
ToolByName resolves a promoted deferred tool for dispatch. Unpromoted deferred tools are invisible (returns nil, false).
type ToolsDeny ¶
type ToolsDeny struct {
Deny []string `toml:"deny,omitempty"`
}
ToolsDeny is `[tools]` — deny by tool name / glob.
type ToolsSection ¶
type ToolsSection struct {
Allow []string `toml:"allow,omitempty"`
}
ToolsSection holds tool names approved without asking. Exact match only.
type VectorKnowledge ¶
type VectorKnowledge struct {
// contains filtered or unexported fields
}
VectorKnowledge is an embedding-backed knowledge store with cosine retrieval.
func NewVectorKnowledge ¶
func NewVectorKnowledge(embedder Embedder) *VectorKnowledge
NewVectorKnowledge constructs a store with the given embedder (default HashEmbedder).
func (*VectorKnowledge) Ingest ¶
func (v *VectorKnowledge) Ingest(content, source string)
Ingest embeds and stores a document.
func (*VectorKnowledge) Query ¶
func (v *VectorKnowledge) Query(query string, topK int) []KnowledgeHit
Query embeds the query and returns up to topK docs by cosine similarity.
type Verdict ¶
type Verdict struct {
Kind VerdictKind
Reason string
}
Verdict is the pure result returned by Decide. Reason carries a human/LLM-readable explanation for Deny/Ask (empty for Allow).
type VerdictKind ¶
type VerdictKind int
VerdictKind tags a Verdict.
const ( // VerdictAllow lets the call through. VerdictAllow VerdictKind = iota // VerdictDeny blocks the call outright. VerdictDeny // VerdictAsk pauses to ask a human. With no approver wired, the gate treats // this as fail-closed. VerdictAsk )
type Workflow ¶
type Workflow[S any] struct { // contains filtered or unexported fields }
Workflow is a typed workflow graph: named nodes connected by static/conditional edges. Build with AddNode, AddEdge / AddConditionalEdge, SetEntry, and SetEnd; the builder methods return the receiver so they chain. Run executes the graph.
func NewWorkflow ¶
NewWorkflow creates an empty workflow with the given max-steps cap (use a value <= 0 for the default of 100).
func (*Workflow[S]) AddConditionalEdge ¶
AddConditionalEdge adds a conditional edge whose router picks the next node at runtime. The router returns the target node name, or END to terminate.
func (*Workflow[S]) Run ¶
Run executes the workflow from the entry node, returning the final state.
It returns an error if no entry node was set, a referenced node does not exist, a node fails, or the maxSteps cap is exceeded (e.g. an unbroken cycle).
