Documentation
¶
Overview ¶
Package toolregistry defines the canonical wire protocol and stream naming helpers used by the tool registry gateway and tool providers/consumers.
Package toolregistry defines the canonical wire protocol and stream naming helpers used by the tool registry gateway and tool providers/consumers.
This file defines the context plumbing used by providers to expose an output-delta publisher to tool implementations. Tools may use it to emit best-effort output fragments while running; the canonical tool result is still delivered via ToolResultMessage.
Index ¶
- Constants
- func ExtractTraceContext(ctx context.Context, traceParent, traceState, baggage string) context.Context
- func InjectTraceContext(ctx context.Context) (traceParent, traceState, baggage string)
- func ResultStreamID(toolUseID string) string
- func ToolsetStreamID(toolset string) string
- func ValidationIssues(err error) []*tools.FieldIssue
- func WithOutputDeltaPublisher(ctx context.Context, pub OutputDeltaPublisher) context.Context
- type OutputDeltaPublisher
- type ServerDataItem
- type ToolCallMessage
- type ToolCallMessageType
- type ToolCallMeta
- type ToolError
- type ToolOutputDeltaMessage
- type ToolResultMessage
- func NewToolResultErrorMessage(toolUseID, code, message string) ToolResultMessage
- func NewToolResultErrorMessageWithIssues(toolUseID, code, message string, issues []*tools.FieldIssue) ToolResultMessage
- func NewToolResultMessage(toolUseID string, result json.RawMessage) ToolResultMessage
- func NewToolResultMessageWithServerData(toolUseID string, result json.RawMessage, serverData []*ServerDataItem) ToolResultMessage
Constants ¶
const ( // MessageTypeCall indicates a tool invocation message on a toolset stream. MessageTypeCall ToolCallMessageType = "call" // MessageTypePing indicates a health ping message on a toolset stream. MessageTypePing ToolCallMessageType = "ping" // ResultEventKey is the Pulse event name used to publish canonical tool result // envelopes to a per-call result stream. ResultEventKey = "result" // OutputDeltaEventKey is the Pulse event name used to publish best-effort tool // output delta messages to a per-call result stream. OutputDeltaEventKey = "output_delta" )
Variables ¶
This section is empty.
Functions ¶
func ExtractTraceContext ¶
func ExtractTraceContext(ctx context.Context, traceParent, traceState, baggage string) context.Context
ExtractTraceContext returns a context that carries the W3C Trace Context represented by traceParent and traceState. Empty values are allowed and will yield the input ctx unchanged.
func InjectTraceContext ¶
InjectTraceContext encodes the trace context in ctx as W3C Trace Context header values. If ctx does not contain a valid trace context, it returns empty strings.
func ResultStreamID ¶
ResultStreamID returns the deterministic Pulse stream identifier used for publishing a single tool result message for the given tool use identifier.
func ToolsetStreamID ¶
ToolsetStreamID returns the deterministic Pulse stream identifier used for publishing tool call messages to providers for the given toolset registration ID.
func ValidationIssues ¶
func ValidationIssues(err error) []*tools.FieldIssue
ValidationIssues extracts structured field-level validation issues from err.
It supports two common sources:
- Generated tool-codec validation errors that expose Issues() []*tools.FieldIssue
- Goa ServiceErrors (possibly merged) that use Goa validation error names (missing_field, invalid_length, etc.) and populate ServiceError.Field.
ValidationIssues returns nil when err does not represent a field-level validation failure.
func WithOutputDeltaPublisher ¶
func WithOutputDeltaPublisher(ctx context.Context, pub OutputDeltaPublisher) context.Context
WithOutputDeltaPublisher returns a context that carries pub.
Types ¶
type OutputDeltaPublisher ¶
type OutputDeltaPublisher interface {
PublishToolOutputDelta(ctx context.Context, stream string, delta string) error
}
OutputDeltaPublisher emits best-effort tool output deltas for a single tool execution. Providers inject an instance into the tool call context so tool implementations can stream partial output while running.
func OutputDeltaPublisherFromContext ¶
func OutputDeltaPublisherFromContext(ctx context.Context) (OutputDeltaPublisher, bool)
OutputDeltaPublisherFromContext returns the output-delta publisher carried by ctx, if any.
type ServerDataItem ¶
type ServerDataItem struct {
Kind string `json:"kind"`
Audience string `json:"audience"`
Data json.RawMessage `json:"data"`
}
ServerDataItem is server-only tool output published alongside the canonical tool result JSON. Server data is never sent to model providers.
type ToolCallMessage ¶
type ToolCallMessage struct {
// ToolUseID is the transport identity for this request stream message. For
// registry-routed tool calls it is stable across retries and equals the
// logical ToolCallID when the caller supplied one.
Type ToolCallMessageType `json:"type"`
ToolUseID string `json:"tool_use_id,omitempty"`
PingID string `json:"ping_id,omitempty"`
Tool tools.Ident `json:"tool,omitempty"`
Payload json.RawMessage `json:"payload,omitempty"`
Meta *ToolCallMeta `json:"meta,omitempty"`
// TraceParent and TraceState carry W3C Trace Context headers for distributed
// tracing across Pulse boundaries. These fields are optional and may be empty.
// When set, consumers should extract them into their context before starting
// spans for handling the tool call.
TraceParent string `json:"traceparent,omitempty"`
TraceState string `json:"tracestate,omitempty"`
// Baggage carries the W3C baggage header when the global propagator includes
// baggage propagation (common for OTEL setups). Optional.
Baggage string `json:"baggage,omitempty"`
}
ToolCallMessage is published to a toolset request stream for tool invocations and provider health checks.
func NewPingMessage ¶
func NewPingMessage(pingID string) ToolCallMessage
NewPingMessage constructs a health ping message.
func NewToolCallMessage ¶
func NewToolCallMessage(toolUseID string, tool tools.Ident, payload json.RawMessage, meta *ToolCallMeta) ToolCallMessage
NewToolCallMessage constructs a tool invocation message.
type ToolCallMessageType ¶
type ToolCallMessageType string
ToolCallMessageType is the type discriminator for toolset stream messages.
type ToolCallMeta ¶
type ToolCallMeta struct {
RunID string `json:"run_id"`
SessionID string `json:"session_id"`
TurnID string `json:"turn_id,omitempty"`
// ToolCallID is the logical execution identity assigned by the runtime. When
// present, registry retries must reuse it as the transport ToolUseID instead
// of minting a fresh per-attempt identifier.
ToolCallID string `json:"tool_call_id,omitempty"`
ParentToolCallID string `json:"parent_tool_call_id,omitempty"`
}
ToolCallMeta is execution metadata propagated alongside tool calls. Providers may use this metadata to scope data access and persistence (for example, applying session-scoped policies without polluting tool payload schemas).
type ToolError ¶
type ToolError struct {
Code string `json:"code"`
Message string `json:"message"`
// Issues optionally carries structured field-level validation issues.
// When present, consumers can build a RetryHint without parsing Message.
Issues []*tools.FieldIssue `json:"issues,omitempty"`
}
ToolError is a structured tool error published by providers.
type ToolOutputDeltaMessage ¶
type ToolOutputDeltaMessage struct {
ToolUseID string `json:"tool_use_id"`
// Stream identifies which logical output channel produced the delta
// (for example, "stdout", "stderr", "log", "progress").
Stream string `json:"stream"`
Delta string `json:"delta"`
}
ToolOutputDeltaMessage is published to a per-call result stream while a tool is still running. It streams partial output to consumers for improved UX (live output panels) without changing the final ToolResultMessage.
Contract:
- This is best-effort and may be dropped by consumers.
- Deltas are not persisted by default; the canonical output remains the final tool result payload.
func NewToolOutputDeltaMessage ¶
func NewToolOutputDeltaMessage(toolUseID string, stream string, delta string) ToolOutputDeltaMessage
NewToolOutputDeltaMessage constructs a tool output delta message.
type ToolResultMessage ¶
type ToolResultMessage struct {
ToolUseID string `json:"tool_use_id"`
Result json.RawMessage `json:"result_json,omitempty"`
// Bounds carries canonical bounded-result metadata projected out-of-band
// from the semantic result payload when the tool declares a bounded-result
// contract.
Bounds *agent.Bounds `json:"bounds,omitempty"`
// ServerData carries server-only metadata about the tool execution that must
// not be serialized into model provider requests.
//
// This is the canonical home for any non-model payloads emitted alongside a
// tool result. Consumers may project it into different observer views (for
// example, UI render cards vs persistence-only evidence), but the wire
// protocol keeps a single server-side envelope.
ServerData []*ServerDataItem `json:"server_data,omitempty"`
Error *ToolError `json:"error,omitempty"`
}
ToolResultMessage is published to a per-call result stream. The gateway never interprets these bytes; consumers decode them using compiled tool codecs.
func NewToolResultErrorMessage ¶
func NewToolResultErrorMessage(toolUseID, code, message string) ToolResultMessage
NewToolResultErrorMessage constructs an error tool result message.
func NewToolResultErrorMessageWithIssues ¶
func NewToolResultErrorMessageWithIssues(toolUseID, code, message string, issues []*tools.FieldIssue) ToolResultMessage
NewToolResultErrorMessageWithIssues constructs an error tool result message that includes structured validation issues for building retry hints.
func NewToolResultMessage ¶
func NewToolResultMessage(toolUseID string, result json.RawMessage) ToolResultMessage
NewToolResultMessage constructs a successful tool result message.
func NewToolResultMessageWithServerData ¶
func NewToolResultMessageWithServerData(toolUseID string, result json.RawMessage, serverData []*ServerDataItem) ToolResultMessage
NewToolResultMessageWithServerData constructs a successful tool result message with additional server-only metadata.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package executor provides registry-backed tool execution.
|
Package executor provides registry-backed tool execution. |
|
Package provider implements the provider-side Pulse subscription loop for registry-routed tool execution.
|
Package provider implements the provider-side Pulse subscription loop for registry-routed tool execution. |