structured

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StructToJSONSchema

func StructToJSONSchema(t reflect.Type) map[string]any

Types

type Agent

type Agent[Output any] struct {
	// contains filtered or unexported fields
}

Agent represents a simplified structured data agent that hides OpenAI SDK details

func NewAgent

func NewAgent[Output any](
	ctx context.Context,
	agentConfig agents.Config,
	modelConfig models.Config,
	opts ...StructuredAgentOption[Output],
) (*Agent[Output], error)

NewAgent creates a new simplified structured data agent

func (*Agent[Output]) AddMessage added in v0.0.9

func (agent *Agent[Output]) AddMessage(role roles.Role, content string)

func (*Agent[Output]) AddMessages added in v1.0.4

func (agent *Agent[Output]) AddMessages(msgs []messages.Message)

AddMessages adds multiple messages to the conversation history

func (*Agent[Output]) ExportMessagesToJSON added in v1.1.2

func (agent *Agent[Output]) ExportMessagesToJSON() (string, error)

func (*Agent[Output]) GenerateStructuredData

func (agent *Agent[Output]) GenerateStructuredData(userMessages []messages.Message) (response *Output, finishReason string, err error)

Generate sends messages and returns structured data

func (*Agent[Output]) GetConfig added in v1.0.8

func (agent *Agent[Output]) GetConfig() agents.Config

GetConfig returns the agent configuration

func (*Agent[Output]) GetContext added in v1.2.2

func (agent *Agent[Output]) GetContext() context.Context

GetContext returns the agent's context

func (*Agent[Output]) GetLastRequestJSON added in v1.0.2

func (agent *Agent[Output]) GetLastRequestJSON() (string, error)

func (*Agent[Output]) GetLastRequestRawJSON added in v1.1.2

func (agent *Agent[Output]) GetLastRequestRawJSON() string

func (*Agent[Output]) GetLastResponseJSON added in v1.0.2

func (agent *Agent[Output]) GetLastResponseJSON() (string, error)

func (*Agent[Output]) GetLastResponseRawJSON added in v1.1.2

func (agent *Agent[Output]) GetLastResponseRawJSON() string

func (*Agent[Output]) GetMessages added in v0.0.8

func (agent *Agent[Output]) GetMessages() []messages.Message

GetMessages returns all conversation messages

func (*Agent[Output]) GetModelConfig added in v1.0.8

func (agent *Agent[Output]) GetModelConfig() models.Config

GetModelConfig returns the model configuration

func (*Agent[Output]) GetModelID added in v0.0.7

func (agent *Agent[Output]) GetModelID() string

func (*Agent[Output]) GetName added in v0.0.3

func (agent *Agent[Output]) GetName() string

func (*Agent[Output]) Kind

func (agent *Agent[Output]) Kind() agents.Kind

Kind returns the agent type

func (*Agent[Output]) ResetMessages

func (agent *Agent[Output]) ResetMessages()

ResetMessages clears all messages except the system instruction

func (*Agent[Output]) SetConfig added in v1.0.8

func (agent *Agent[Output]) SetConfig(config agents.Config)

SetConfig updates the agent configuration

func (*Agent[Output]) SetContext added in v1.2.2

func (agent *Agent[Output]) SetContext(ctx context.Context)

SetContext updates the agent's context

func (*Agent[Output]) SetModelConfig added in v1.0.8

func (agent *Agent[Output]) SetModelConfig(config models.Config)

SetModelConfig updates the model configuration Note: This updates the stored config but doesn't regenerate the internal OpenAI params For most parameters to take effect, create a new agent with the new config

type AgentOption

type AgentOption[Output any] func(*BaseAgent[Output])

type BaseAgent

type BaseAgent[Output any] struct {
	*base.Agent
}

BaseAgent wraps the shared base.Agent for structured output functionality

func NewBaseAgent

func NewBaseAgent[Output any](
	ctx context.Context,
	agentConfig agents.Config,
	modelConfig openai.ChatCompletionNewParams,
	options ...AgentOption[Output],
) (structuredAgent *BaseAgent[Output], err error)

func (*BaseAgent[Output]) GenerateStructuredData

func (agent *BaseAgent[Output]) GenerateStructuredData(messages []openai.ChatCompletionMessageParamUnion) (response *Output, finishReason string, err error)

func (*BaseAgent[Output]) Kind

func (agent *BaseAgent[Output]) Kind() (kind agents.Kind)

type StructuredAgentOption added in v1.2.9

type StructuredAgentOption[Output any] func(*Agent[Output])

StructuredAgentOption is a functional option for configuring an Agent during creation

func AfterCompletion added in v1.2.9

func AfterCompletion[Output any](fn func(*Agent[Output])) StructuredAgentOption[Output]

AfterCompletion sets a hook that is called after each structured data generation

func BeforeCompletion added in v1.2.9

func BeforeCompletion[Output any](fn func(*Agent[Output])) StructuredAgentOption[Output]

BeforeCompletion sets a hook that is called before each structured data generation

type StructuredResult

type StructuredResult[Output any] struct {
	Data         *Output
	FinishReason string
}

StructuredResult represents the result of structured data generation

Jump to

Keyboard shortcuts

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