structured

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 6 Imported by: 0

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 (t *Tool) Description() string

func (*Tool) Execute

func (t *Tool) Execute(_ context.Context, logger *slog.Logger, input json.RawMessage) (tools.Result, error)

func (*Tool) Name

func (t *Tool) Name() string

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.

Jump to

Keyboard shortcuts

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