Documentation
¶
Index ¶
- Constants
- func AddInternalService(reg Registry, s svc.Service) error
- func BestPathAllowed(name string) bool
- func InjectVirtualAgentTools(reg Registry, agents []*agent.Agent, domain string)
- func IsPolicyError(err error) bool
- func NormalizeMode(mode string) string
- func ResolvedToolAllowed(ctx context.Context, name string) (bool, bool)
- func RewriteContainerDataSourceRefs(c types.Container, nameMap map[string]string) types.Container
- func ValidateExecution(ctx context.Context, p *Policy, name string, args map[string]interface{}) error
- func WithPolicy(ctx context.Context, p *Policy) context.Context
- func WithResolvedToolDefinitions(ctx context.Context, defs []*llm.ToolDefinition) context.Context
- func WithResolvedToolNames(ctx context.Context, names []string) context.Context
- type ActivationSpec
- type AskFunc
- type AsyncResolver
- type ContextMatcher
- type DataFeed
- type DataSource
- type DataSources
- type Feed
- type FeedSpec
- type FeedSpecs
- type Handler
- type MatchSpec
- type Policy
- type PolicyError
- type Registry
- type Source
- type TimeoutResolver
Constants ¶
const ( ModeAsk = "ask" // ask user for every tool call ModeAuto = "auto" // execute automatically ModeDeny = "deny" // refuse tool execution ModeBestPath = "best_path" // auto-approve safe tools, block risky/destructive tools )
Mode constants for tool execution behaviour.
Variables ¶
This section is empty.
Functions ¶
func AddInternalService ¶
AddInternalService attempts to register a service as an internal MCP client on the default registry.
func BestPathAllowed ¶
BestPathAllowed returns true when the tool appears safe for automatic execution under ModeBestPath. Internal tools remain always allowed.
func InjectVirtualAgentTools ¶
InjectVirtualAgentTools exposes agents as virtual tools when supported by the registry implementation.
func IsPolicyError ¶
IsPolicyError reports whether err is a policy denial/rejection.
func NormalizeMode ¶
NormalizeMode converts aliases to canonical policy modes.
func ResolvedToolAllowed ¶ added in v0.1.8
ResolvedToolAllowed reports whether name was exposed in the resolved tool signatures for this turn. The second return value is false when no resolved scope was recorded on the context.
func RewriteContainerDataSourceRefs ¶
RewriteContainerDataSourceRefs returns a copy of the container with every dataSourceRef rewritten according to the provided name mapping. Keys are original names; values are transformed names.
func ValidateExecution ¶
func ValidateExecution(ctx context.Context, p *Policy, name string, args map[string]interface{}) error
ValidateExecution checks whether a tool execution is permitted by policy. Returns nil when allowed; otherwise an explanatory error.
func WithPolicy ¶
WithPolicy attaches policy to context.
func WithResolvedToolDefinitions ¶ added in v0.1.8
WithResolvedToolDefinitions records the concrete tool definitions exposed to the model for the current turn. An empty definition list is still a scoped turn: no model-emitted tool calls are executable.
Types ¶
type ActivationSpec ¶
type ActivationSpec struct {
// Kind selects the activation mode: "history" or "tool_call".
Kind string `yaml:"kind,omitempty" json:"kind,omitempty"`
// Scope controls how many recorded calls are considered when kind==history:
// - "last" (default): only the most recent matching call is used
// - "all": aggregate data from all matching calls in the turn
Scope string `yaml:"scope,omitempty" json:"scope,omitempty"`
// Optional explicit tool to invoke when kind==tool_call. When omitted,
// match.service/method may be used as a fallback by the consumer.
Service string `yaml:"service,omitempty" json:"service,omitempty"`
Method string `yaml:"method,omitempty" json:"method,omitempty"`
Args map[string]interface{} `yaml:"args,omitempty" json:"args,omitempty"`
}
type AskFunc ¶
AskFunc is invoked when policy.Mode==ModeAsk. It should return true to approve the call, false to reject. It can optionally mutate the policy (for example to switch to auto mode after user confirmation).
type AsyncResolver ¶ added in v0.1.7
type ContextMatcher ¶
type ContextMatcher interface {
MatchDefinitionWithContext(ctx context.Context, pattern string) []*llm.ToolDefinition
}
ContextMatcher is an optional extension for registries that can evaluate tool pattern matches using request-scoped context.
type DataFeed ¶
type DataFeed struct {
Name string `json:"name" yaml:"name"`
Data interface{} `json:"data" yaml:"data"`
RawSelector string `json:"rawSelector" yaml:"rawSelector"`
}
DataFeed carries a resolved value and the raw selector used to obtain it. The type of Data is intentionally interface{} to support both object and collection values (e.g., a map with explanation/steps or a []map rows list).
type DataSource ¶
type DataSource struct {
types.DataSource `yaml:",inline"`
Source string `json:"source" yaml:"source"`
Name string `json:"name" yaml:"name"`
}
func (*DataSource) HasSource ¶
func (d *DataSource) HasSource() bool
type DataSources ¶
type DataSources map[string]*DataSource
func (DataSources) FeedDataSource ¶
func (s DataSources) FeedDataSource() (*DataSource, error)
func (DataSources) Normalize ¶
func (s DataSources) Normalize() map[string]*types.DataSource
Normalize returns normalized datasourcse
func (DataSources) Transform ¶
func (s DataSources) Transform(hash string) (map[string]*types.DataSource, map[string]string)
Transform returns a normalized map of DataSources with keys suffixed by the provided hash, and a mapping from original name -> transformed name. Any internal DataSourceRef fields that reference other data sources are also rewritten using the mapping.
type Feed ¶
type Feed struct {
ID string `json:"id" yaml:"id"`
// Data holds resolved data blocks keyed by data-source or container name.
Data DataFeed `json:"dataFeed" yaml:"dataFeed"`
// UI carries a renderable container definition for Forge-based UIs.
UI *types.Container `json:"ui" yaml:"ui"`
// DataSources defines UI data sources
DataSources map[string]*types.DataSource `yaml:"dataSources,omitempty" json:"dataSources,omitempty"`
Invoked bool `json:"-" yaml:"-"`
}
Feed describes a single matched rule and its extracted data. It is used as the payload for tool feeds rendered by the UI.
type FeedSpec ¶
type FeedSpec struct {
ID string `yaml:"id,omitempty" json:"id,omitempty"`
Title string `yaml:"title,omitempty" json:"title,omitempty"`
Priority int `yaml:"priority,omitempty" json:"priority,omitempty"`
Match MatchSpec `yaml:"match" json:"match"`
Activation ActivationSpec `yaml:"activation" json:"activation"`
DataSources DataSources `yaml:"dataSource,omitempty" json:"dataSource,omitempty"`
UI types.Container `yaml:"ui" json:"ui"`
}
func (*FeedSpec) InvokeServiceMethod ¶
InvokeServiceMethod returns the effective (service, method) to invoke for this spec, preferring Activation overrides and falling back to Match when empty.
func (*FeedSpec) ShallInvokeTool ¶
ShallInvokeTool indicates whether this spec should trigger a direct tool invocation.
func (*FeedSpec) ShallUseHistory ¶
ShallUseHistory indicates whether this spec should evaluate history (default when kind is empty) or explicitly when kind==history.
type FeedSpecs ¶
type FeedSpecs []*FeedSpec
FeedSpecs is a convenience slice alias for helpers.
type MatchSpec ¶
type MatchSpec struct {
Service string `yaml:"service,omitempty" json:"service,omitempty"`
Method string `yaml:"method,omitempty" json:"method,omitempty"`
}
type Policy ¶
type Policy struct {
Mode string // ask, auto or deny
AllowList []string // optional set of allowed tools (empty => all)
BlockList []string // optional set of blocked tools
Ask AskFunc // optional callback when Mode==ask
}
Policy controls runtime behaviour of tool execution.
func FromContext ¶
FromContext retrieves policy from context; may be nil.
type PolicyError ¶
type PolicyError struct {
// contains filtered or unexported fields
}
PolicyError represents a tool execution rejection caused by approval policy.
func (*PolicyError) Error ¶
func (e *PolicyError) Error() string
type Registry ¶
type Registry interface {
// Definitions returns the merged list of available tool definitions.
Definitions() []llm.ToolDefinition
//MatchDefinition matches tool definition based on pattern
MatchDefinition(pattern string) []*llm.ToolDefinition
// GetDefinition fetches the definition for the given tool name. The second
// result value indicates whether the definition exists.
GetDefinition(name string) (*llm.ToolDefinition, bool)
// MustHaveTools converts a set of patterns into the LLM toolkit slice used by
// generation prompts.
MustHaveTools(patterns []string) ([]llm.Tool, error)
// Execute invokes the given tool with the supplied arguments and returns
// its textual result.
Execute(ctx context.Context, name string, args map[string]interface{}) (string, error)
// SetDebugLogger attaches a writer that receives every executed tool call
// for debugging.
SetDebugLogger(w io.Writer)
// Initialize allows registry implementations to perform optional
// one-time discovery or warm-up (e.g., preload MCP servers/tools).
// Implementations should be idempotent. Callers may safely ignore it.
Initialize(ctx context.Context)
}
Registry defines the minimal interface required by the rest of the code-base. Previous consumers used a concrete *Registry struct; moving to an interface allows alternative implementations (remote catalogues, mocks, etc.) while retaining backward-compatibility.
func NewDefaultRegistry ¶
NewDefaultRegistry constructs the default MCP-backed tool registry with built-ins.
func WithConversation ¶
WithConversation returns a Registry that guarantees ctx carries convID for every Execute call. All other methods delegate to the underlying registry.
type Source ¶
type Source struct {
Service string `json:"service" yaml:"service"`
Method string `json:"method" yaml:"method"`
}
Source identifies the tool that produced the output observed by the rule.
type TimeoutResolver ¶
TimeoutResolver may be implemented by registries that can suggest per-tool execution timeouts. The returned duration should be >0 to take effect; the boolean indicates whether a suggestion is available for the given name.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
adapter
|
|
|
system/async
Package async provides the system/async tool service.
|
Package async provides the system/async tool service. |