agent

package
v0.0.0-...-d9b65ce Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base64EncodeImage

func Base64EncodeImage(filename string) (string, error)

func MustJSONSchema

func MustJSONSchema(s any) *jsonschema.Definition

Types

type Agent

type Agent struct {
	Tools    Tools
	Handoffs Tools
	// contains filtered or unexported fields
}

func New

func New(name, instructions string, options ...AgentOption) *Agent

func (*Agent) AsTool

func (agent *Agent) AsTool(description string) Tool

AsTool creates a tool that returns the agent itself This is useful for agent handoff scenarios where one agent can call another agent

func (*Agent) IsZero

func (agent *Agent) IsZero() bool

Know when the agent has no responsibility

func (*Agent) Name

func (agent *Agent) Name() string

func (*Agent) Run

func (agent *Agent) Run(ctx context.Context, messages Messages, options ...RunOption) (*Response, error)

Run executes the agent's logic It will continue to run until the agent has no more messages to process or the maximum number of messages is reached.

func (*Agent) SetSchema

func (agent *Agent) SetSchema(value any) error

func (*Agent) String

func (agent *Agent) String() string

Identify an agent in the messages

type AgentHooks

type AgentHooks interface {
	OnAgentStart(ctx context.Context, agent *Agent, messages Messages) error
	OnAgentEnd(ctx context.Context, agent *Agent, response *Response) error
	OnHandoff(ctx context.Context, fromAgent *Agent, toAgent *Agent, agentContext string) error
	OnToolStart(ctx context.Context, agent *Agent, toolName string, params map[string]any) error
	OnToolEnd(ctx context.Context, agent *Agent, toolName string, result any) error
}

AgentHooks defines callbacks for agent lifecycle events

type AgentOption

type AgentOption func(*Agent)

func WithClient

func WithClient(client *client.Client) AgentOption

func WithHooks

func WithHooks(hooks AgentHooks) AgentOption

WithHooks adds lifecycle hooks to the agent

func WithLogger

func WithLogger(logger *slog.Logger) AgentOption

type Caller

type Caller interface {
	Call(ctx context.Context) (any, error)
}

type DefaultAgentHooks

type DefaultAgentHooks struct{}

DefaultAgentHooks provides a no-op implementation of AgentHooks Users can embed this struct and override only the methods they need

func (*DefaultAgentHooks) OnAgentEnd

func (h *DefaultAgentHooks) OnAgentEnd(ctx context.Context, agent *Agent, response *Response) error

func (*DefaultAgentHooks) OnAgentStart

func (h *DefaultAgentHooks) OnAgentStart(ctx context.Context, agent *Agent, messages Messages) error

func (*DefaultAgentHooks) OnHandoff

func (h *DefaultAgentHooks) OnHandoff(ctx context.Context, fromAgent *Agent, toAgent *Agent, agentContext string) error

func (*DefaultAgentHooks) OnToolEnd

func (h *DefaultAgentHooks) OnToolEnd(ctx context.Context, agent *Agent, toolName string, result any) error

func (*DefaultAgentHooks) OnToolStart

func (h *DefaultAgentHooks) OnToolStart(ctx context.Context, agent *Agent, toolName string, params map[string]any) error

type Message

type Message = openai.ChatCompletionMessage

func ImageMessage

func ImageMessage(filename string) Message

type Messages

type Messages []Message

func Demo

func Demo(agent *Agent) (Messages, error)

type Response

type Response struct {
	Messages Messages
	Agent    *Agent
}

type RunOption

type RunOption func(*runOptions)

RunOption defines options for the Run function

func WithMaxMessages

func WithMaxMessages(max int) RunOption

WithMaxMessages sets the maximum number of message iterations in the agent's run loop

type Tool

type Tool struct {
	Name        string
	Description string
	Parameters  *jsonschema.Definition
	Func        func(ctx context.Context, params map[string]any) (any, error)
}

func MustWrapStruct

func MustWrapStruct(description string, s Caller) Tool

func WrapStruct

func WrapStruct(description string, src Caller) (Tool, error)

type Tools

type Tools []Tool

func (*Tools) Add

func (f *Tools) Add(tools ...Tool)

func (Tools) AsTools

func (f Tools) AsTools() []openai.Tool

func (*Tools) Get

func (f *Tools) Get(name string) (Tool, bool)

Jump to

Keyboard shortcuts

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