agent

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent struct {
	// Core properties
	Name         string
	Instructions string
	Description  string

	// Model configuration
	Model         interface{} // Can be a string (model name) or a Model instance
	ModelSettings *model.Settings

	// Capabilities
	Tools    []tool.Tool
	Handoffs []*Agent

	// Output configuration
	OutputType reflect.Type

	// Lifecycle hooks
	Hooks Hooks
	// contains filtered or unexported fields
}

Agent represents an AI agent with specific configuration

func NewAgent

func NewAgent(name ...string) *Agent

NewAgent creates a new agent with the given name and instructions

func (*Agent) AddFunctionTool

func (a *Agent) AddFunctionTool(name, description string, fn interface{}) *Agent

AddFunctionTool adds a function as a tool to the agent

func (*Agent) AddToolFromDefinition

func (a *Agent) AddToolFromDefinition(definition map[string]interface{}, executeFn func(map[string]interface{}) (interface{}, error)) *Agent

AddToolFromDefinition adds a tool from an OpenAI-compatible tool definition

func (*Agent) AddToolsFromDefinitions

func (a *Agent) AddToolsFromDefinitions(definitions []map[string]interface{}, executeFns map[string]func(map[string]interface{}) (interface{}, error)) *Agent

AddToolsFromDefinitions adds multiple tools from OpenAI-compatible tool definitions

func (*Agent) AsTaskDelegator

func (a *Agent) AsTaskDelegator() *Agent

AsTaskDelegator configures this agent as a task delegator with bidirectional flow support

func (*Agent) AsTaskExecutor

func (a *Agent) AsTaskExecutor() *Agent

AsTaskExecutor configures this agent as a task executor with bidirectional flow support

func (*Agent) AsTool

func (a *Agent) AsTool(toolName, toolDescription string) tool.Tool

AsTool transforms this agent into a tool callable by other agents

func (*Agent) Clone

func (a *Agent) Clone(overrides map[string]interface{}) *Agent

Clone creates a copy of the agent with optional overrides

func (*Agent) SetModelProvider

func (a *Agent) SetModelProvider(provider model.Provider) *Agent

SetModelProvider sets the model provider for the agent

func (*Agent) SetSystemInstructions

func (a *Agent) SetSystemInstructions(instructions string) *Agent

SetSystemInstructions sets the system instructions for the agent

func (*Agent) WithBidirectionalHandoffs

func (a *Agent) WithBidirectionalHandoffs(agents ...*Agent) *Agent

WithBidirectionalHandoffs adds agents as handoffs with bidirectional flow support

func (*Agent) WithHandoffs

func (a *Agent) WithHandoffs(handoffs ...*Agent) *Agent

WithHandoffs adds handoffs to the agent

func (*Agent) WithHooks

func (a *Agent) WithHooks(hooks Hooks) *Agent

WithHooks sets the lifecycle hooks for the agent

func (*Agent) WithModel

func (a *Agent) WithModel(model interface{}) *Agent

WithModel sets the model for the agent

func (*Agent) WithModelSettings

func (a *Agent) WithModelSettings(settings *model.Settings) *Agent

WithModelSettings sets the model settings for the agent

func (*Agent) WithOutputType

func (a *Agent) WithOutputType(outputType interface{}) *Agent

WithOutputType sets the output type for the agent

func (*Agent) WithTools

func (a *Agent) WithTools(tools ...tool.Tool) *Agent

WithTools adds tools to the agent

type DefaultAgentHooks

type DefaultAgentHooks struct{}

DefaultAgentHooks provides a default implementation of Hooks

func (*DefaultAgentHooks) OnAfterHandoff

func (h *DefaultAgentHooks) OnAfterHandoff(ctx context.Context, agent *Agent, handoffAgent *Agent, result interface{}) error

OnAfterHandoff is called after a handoff to another agent

func (*DefaultAgentHooks) OnAfterModelCall

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

OnAfterModelCall is called after the model is called

func (*DefaultAgentHooks) OnAfterToolCall

func (h *DefaultAgentHooks) OnAfterToolCall(ctx context.Context, agent *Agent, tool tool.Tool, result interface{}, err error) error

OnAfterToolCall is called after a tool is called

func (*DefaultAgentHooks) OnAgentEnd

func (h *DefaultAgentHooks) OnAgentEnd(ctx context.Context, agent *Agent, result interface{}) error

OnAgentEnd is called when the agent finishes processing

func (*DefaultAgentHooks) OnAgentStart

func (h *DefaultAgentHooks) OnAgentStart(ctx context.Context, agent *Agent, input interface{}) error

OnAgentStart is called when the agent starts processing

func (*DefaultAgentHooks) OnBeforeHandoff

func (h *DefaultAgentHooks) OnBeforeHandoff(ctx context.Context, agent *Agent, handoffAgent *Agent) error

OnBeforeHandoff is called before a handoff to another agent

func (*DefaultAgentHooks) OnBeforeModelCall

func (h *DefaultAgentHooks) OnBeforeModelCall(ctx context.Context, agent *Agent, request *model.Request) error

OnBeforeModelCall is called before the model is called

func (*DefaultAgentHooks) OnBeforeToolCall

func (h *DefaultAgentHooks) OnBeforeToolCall(ctx context.Context, agent *Agent, tool tool.Tool, params map[string]interface{}) error

OnBeforeToolCall is called before a tool is called

type Hooks

type Hooks interface {
	// OnAgentStart is called when the agent starts processing
	OnAgentStart(ctx context.Context, agent *Agent, input interface{}) error

	// OnBeforeModelCall is called before the model is called
	OnBeforeModelCall(ctx context.Context, agent *Agent, request *model.Request) error

	// OnAfterModelCall is called after the model is called
	OnAfterModelCall(ctx context.Context, agent *Agent, response *model.Response) error

	// OnBeforeToolCall is called before a tool is called
	OnBeforeToolCall(ctx context.Context, agent *Agent, tool tool.Tool, params map[string]interface{}) error

	// OnAfterToolCall is called after a tool is called
	OnAfterToolCall(ctx context.Context, agent *Agent, tool tool.Tool, result interface{}, err error) error

	// OnBeforeHandoff is called before a handoff to another agent
	OnBeforeHandoff(ctx context.Context, agent *Agent, handoffAgent *Agent) error

	// OnAfterHandoff is called after a handoff to another agent
	OnAfterHandoff(ctx context.Context, agent *Agent, handoffAgent *Agent, result interface{}) error

	// OnAgentEnd is called when the agent finishes processing
	OnAgentEnd(ctx context.Context, agent *Agent, result interface{}) error
}

Hooks defines lifecycle hooks for an agent

Jump to

Keyboard shortcuts

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