Documentation
¶
Overview ¶
Package structuredagent wraps ADK agents with JSON-schema-constrained I/O.
NewAgent validates structured input before invoking the wrapped agent and validates structured output before returning the final ADK event. The package is intended for higher-level workflows that require deterministic machine- readable JSON instead of free-form model text.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrStructuredIOSchemaValidation = errors.New("structured I/O schema validation error")
ErrStructuredIOSchemaValidation is the umbrella error for all structured I/O schema validation failures.
var ErrStructuredInputSchemaValidation = errors.Join( errors.New("structured input schema validation error"), ErrStructuredIOSchemaValidation, )
ErrStructuredInputSchemaValidation is returned when input JSON fails to match the expected schema. It satisfies errors.Is(err, ErrStructuredIOSchemaValidation).
var ErrStructuredOutputSchemaValidation = errors.Join( errors.New("structured output schema validation error"), ErrStructuredIOSchemaValidation, )
ErrStructuredOutputSchemaValidation is returned when output JSON fails to match the expected schema. It satisfies errors.Is(err, ErrStructuredIOSchemaValidation).
Functions ¶
func NewAgent ¶
NewAgent creates an ADK agent wrapper around another agent and validates structured input/output using configured schemas.
Example ¶
inner, err := adkagent.New(adkagent.Config{
Name: "formatter",
Description: "Formats structured output",
Run: func(ctx adkagent.InvocationContext) iter.Seq2[*session.Event, error] {
return func(yield func(*session.Event, error) bool) {
ev := session.NewEvent(ctx.InvocationID())
ev.Content = genai.NewContentFromText(`{"output":"done"}`, genai.RoleModel)
ev.TurnComplete = true
_ = yield(ev, nil)
}
},
})
if err != nil {
fmt.Println(err)
return
}
wrapped, err := NewAgent(inner)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(wrapped.Name())
Output: formatter_structured
Types ¶
type Option ¶
type Option func(*options)
Option customizes wrapper behavior at creation time.
func WithInputSchema ¶
WithInputSchema overrides default input JSON schema.
func WithMaxAccumulatedOutputBytes ¶
WithMaxAccumulatedOutputBytes sets the maximum number of output text bytes accumulated for schema validation in a single turn.
func WithOutputSchema ¶
WithOutputSchema overrides default output JSON schema.
func WithOutputValidationRetries ¶
WithOutputValidationRetries sets the number of retries for output schema validation failures. Default is 1 retry (2 total attempts).
func WithSystemInstruction ¶
WithSystemInstruction sets the system instruction for the agent. This instruction is prepended to the I/O requirements prompt.