Documentation
¶
Overview ¶
Package structured implements the structured_output tool: a per-run tool whose input schema IS a caller-supplied JSON schema, letting a headless host receive the agent's final answer as validated JSON instead of prose.
The tool never appears in a static profile. The agent registers it dynamically — only when the host opts in via agent.WithStructuredOutput — and captures the payload through the Sink seam, ending the run (the analog of how EnterPlanMode reaches the agent through PlanModeController). Ported from ref/src/tools/SyntheticOutputTool/SyntheticOutputTool.ts.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Sink ¶
type Sink interface {
CaptureStructuredOutput(payload json.RawMessage)
}
Sink is the seam back to the owning agent. The tool hands the validated structured payload to the sink, which captures it and ends the run.
type SinkLookup ¶
type SinkLookup func() Sink
SinkLookup is the late-bound factory closure passed to New. Returning nil disables the tool — Execute surfaces a clear "no sink installed" error instead of silently dropping the payload (mirrors mode.ControllerLookup).
type Tool ¶
type Tool struct {
// contains filtered or unexported fields
}
Tool is the structured_output tool instance for one agent. The caller schema is baked in at construction and returned verbatim from Schema(), so the provider constrains the model's tool input to it server-side.
func New ¶
func New(schema json.RawMessage, lookup SinkLookup) *Tool
New builds the tool around the caller's JSON schema. A nil/empty schema falls back to a permissive empty-object schema so metadata reads stay total; the agent layer only registers the tool when a real schema exists.
func (*Tool) Description ¶
func (*Tool) Schema ¶
func (t *Tool) Schema() json.RawMessage
Schema returns the caller-supplied schema verbatim — it IS the tool's input schema, so schema-enforcing providers (Anthropic, OpenAI) constrain the model's payload to it by construction.