agent

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertYAMLSchemaToResponseFormat added in v0.0.24

func ConvertYAMLSchemaToResponseFormat(config *ResponseFormatConfig) (*interfaces.ResponseFormat, error)

ConvertYAMLSchemaToResponseFormat converts a ResponseFormatConfig to interfaces.ResponseFormat

func FormatSystemPromptFromConfig added in v0.0.3

func FormatSystemPromptFromConfig(config AgentConfig, variables map[string]string) string

FormatSystemPromptFromConfig formats a system prompt based on the agent configuration

func GenerateConfigFromSystemPrompt added in v0.0.3

func GenerateConfigFromSystemPrompt(ctx context.Context, llm interfaces.LLM, systemPrompt string) (AgentConfig, []TaskConfig, error)

GenerateConfigFromSystemPrompt uses the LLM to generate agent and task configurations from a system prompt

func GetAgentForTask added in v0.0.3

func GetAgentForTask(taskConfigs TaskConfigs, taskName string) (string, error)

GetAgentForTask returns the agent name for a given task

func GetInvocationID added in v0.0.26

func GetInvocationID(ctx context.Context) string

GetInvocationID retrieves the invocation ID from context

func GetParentAgent added in v0.0.26

func GetParentAgent(ctx context.Context) string

GetParentAgent retrieves the parent agent from context

func GetRecursionDepth added in v0.0.26

func GetRecursionDepth(ctx context.Context) int

GetRecursionDepth retrieves the current recursion depth from context

func GetSubAgentName added in v0.0.26

func GetSubAgentName(ctx context.Context) string

GetSubAgentName retrieves the sub-agent name from context

func IsSubAgentCall added in v0.0.26

func IsSubAgentCall(ctx context.Context) bool

IsSubAgentCall checks if the current context is a sub-agent call

func SaveAgentConfigsToFile added in v0.0.3

func SaveAgentConfigsToFile(configs AgentConfigs, file *os.File) error

SaveAgentConfigsToFile saves agent configurations to a YAML file

func SaveTaskConfigsToFile added in v0.0.3

func SaveTaskConfigsToFile(configs TaskConfigs, file *os.File) error

SaveTaskConfigsToFile saves task configurations to a YAML file

func ValidateRecursionDepth added in v0.0.26

func ValidateRecursionDepth(ctx context.Context) error

ValidateRecursionDepth checks if the recursion depth is within limits

func WithSubAgentContext added in v0.0.26

func WithSubAgentContext(ctx context.Context, parentAgent, subAgentName string) context.Context

WithSubAgentContext adds sub-agent context to the context

func WithTimeout added in v0.0.26

func WithTimeout(ctx context.Context, timeout time.Duration) (context.Context, context.CancelFunc)

WithTimeout adds a timeout to the context for sub-agent calls

Types

type Agent

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

Agent represents an AI agent

func CreateAgentForTask added in v0.0.3

func CreateAgentForTask(taskName string, agentConfigs AgentConfigs, taskConfigs TaskConfigs, variables map[string]string, options ...Option) (*Agent, error)

CreateAgentForTask creates a new agent for a specific task

func NewAgent

func NewAgent(options ...Option) (*Agent, error)

NewAgent creates a new agent with the given options

func NewAgentFromConfig added in v0.0.3

func NewAgentFromConfig(agentName string, configs AgentConfigs, variables map[string]string, options ...Option) (*Agent, error)

NewAgentFromConfig creates a new agent from a YAML configuration

func NewAgentWithAutoConfig added in v0.0.3

func NewAgentWithAutoConfig(ctx context.Context, options ...Option) (*Agent, error)

NewAgentWithAutoConfig creates a new agent with automatic configuration generation based on the system prompt if explicit configuration is not provided

func (*Agent) ApproveExecutionPlan added in v0.0.2

func (a *Agent) ApproveExecutionPlan(ctx context.Context, plan *executionplan.ExecutionPlan) (string, error)

ApproveExecutionPlan approves an execution plan for execution

func (*Agent) Disconnect added in v0.0.26

func (a *Agent) Disconnect() error

Disconnect closes the connection to a remote agent

func (*Agent) ExecuteTaskFromConfig added in v0.0.3

func (a *Agent) ExecuteTaskFromConfig(ctx context.Context, taskName string, taskConfigs TaskConfigs, variables map[string]string) (string, error)

ExecuteTaskFromConfig executes a task using its YAML configuration

func (*Agent) GenerateExecutionPlan added in v0.0.2

func (a *Agent) GenerateExecutionPlan(ctx context.Context, input string) (*executionplan.ExecutionPlan, error)

GenerateExecutionPlan generates an execution plan

func (*Agent) GetCapabilities added in v0.0.20

func (a *Agent) GetCapabilities() string

GetCapabilities returns a description of what the agent can do

func (*Agent) GetDescription added in v0.0.20

func (a *Agent) GetDescription() string

GetDescription returns the description of the agent

func (*Agent) GetGeneratedAgentConfig added in v0.0.3

func (a *Agent) GetGeneratedAgentConfig() *AgentConfig

GetGeneratedAgentConfig returns the automatically generated agent configuration, if any

func (*Agent) GetGeneratedTaskConfigs added in v0.0.3

func (a *Agent) GetGeneratedTaskConfigs() TaskConfigs

GetGeneratedTaskConfigs returns the automatically generated task configurations, if any

func (*Agent) GetLLM added in v0.0.43

func (a *Agent) GetLLM() interfaces.LLM

GetLLM returns the LLM instance (for use in custom functions)

func (*Agent) GetLogger added in v0.0.43

func (a *Agent) GetLogger() logging.Logger

GetLogger returns the logger instance (for use in custom functions)

func (*Agent) GetMemory added in v0.0.43

func (a *Agent) GetMemory() interfaces.Memory

GetMemory returns the memory instance (for use in custom functions)

func (*Agent) GetName added in v0.0.20

func (a *Agent) GetName() string

GetName returns the agent's name

func (*Agent) GetRemoteURL added in v0.0.26

func (a *Agent) GetRemoteURL() string

GetRemoteURL returns the URL of the remote agent (empty string if not remote)

func (*Agent) GetSubAgent added in v0.0.26

func (a *Agent) GetSubAgent(name string) (*Agent, bool)

GetSubAgent retrieves a sub-agent by name

func (*Agent) GetSubAgents added in v0.0.26

func (a *Agent) GetSubAgents() []*Agent

GetSubAgents returns the list of sub-agents

func (*Agent) GetSystemPrompt added in v0.0.43

func (a *Agent) GetSystemPrompt() string

GetSystemPrompt returns the system prompt (for use in custom functions)

func (*Agent) GetTaskByID added in v0.0.2

func (a *Agent) GetTaskByID(taskID string) (*executionplan.ExecutionPlan, bool)

GetTaskByID returns a task by its ID

func (*Agent) GetTools added in v0.0.43

func (a *Agent) GetTools() []interfaces.Tool

GetTools returns the tools slice (for use in custom functions)

func (*Agent) GetTracer added in v0.0.43

func (a *Agent) GetTracer() interfaces.Tracer

GetTracer returns the tracer instance (for use in custom functions)

func (*Agent) HasSubAgent added in v0.0.26

func (a *Agent) HasSubAgent(name string) bool

HasSubAgent checks if a specific agent is a sub-agent

func (*Agent) IsRemote added in v0.0.26

func (a *Agent) IsRemote() bool

IsRemote returns true if this is a remote agent

func (*Agent) ListTasks added in v0.0.2

func (a *Agent) ListTasks() []*executionplan.ExecutionPlan

ListTasks returns a list of all tasks

func (*Agent) ModifyExecutionPlan added in v0.0.2

func (a *Agent) ModifyExecutionPlan(ctx context.Context, plan *executionplan.ExecutionPlan, modifications string) (*executionplan.ExecutionPlan, error)

ModifyExecutionPlan modifies an execution plan based on user input

func (*Agent) Run

func (a *Agent) Run(ctx context.Context, input string) (string, error)

Run runs the agent with the given input

func (*Agent) RunStream added in v0.0.34

func (a *Agent) RunStream(ctx context.Context, input string) (<-chan interfaces.AgentStreamEvent, error)

RunStream executes the agent with streaming response

func (*Agent) RunStreamWithAuth added in v0.0.35

func (a *Agent) RunStreamWithAuth(ctx context.Context, input string, authToken string) (<-chan interfaces.AgentStreamEvent, error)

RunStreamWithAuth executes the agent with streaming response and explicit auth token

func (*Agent) RunWithAuth added in v0.0.29

func (a *Agent) RunWithAuth(ctx context.Context, input string, authToken string) (string, error)

RunWithAuth executes the agent with an explicit auth token

type AgentConfig added in v0.0.3

type AgentConfig struct {
	Role           string                `yaml:"role"`
	Goal           string                `yaml:"goal"`
	Backstory      string                `yaml:"backstory"`
	ResponseFormat *ResponseFormatConfig `yaml:"response_format,omitempty"`
}

AgentConfig represents the configuration for an agent loaded from YAML

type AgentConfigs added in v0.0.3

type AgentConfigs map[string]AgentConfig

AgentConfigs represents a map of agent configurations

func LoadAgentConfigsFromDir added in v0.0.3

func LoadAgentConfigsFromDir(dirPath string) (AgentConfigs, error)

LoadAgentConfigsFromDir loads all agent configurations from YAML files in a directory

func LoadAgentConfigsFromFile added in v0.0.3

func LoadAgentConfigsFromFile(filePath string) (AgentConfigs, error)

LoadAgentConfigsFromFile loads agent configurations from a YAML file

type ContextKey added in v0.0.26

type ContextKey string

ContextKey is a type for context keys to avoid collisions

const (
	// SubAgentNameKey is the context key for sub-agent name
	SubAgentNameKey ContextKey = "sub_agent_name"

	// ParentAgentKey is the context key for parent agent
	ParentAgentKey ContextKey = "parent_agent"

	// RecursionDepthKey is the context key for recursion depth
	RecursionDepthKey ContextKey = "recursion_depth"

	// InvocationIDKey is the context key for invocation ID
	InvocationIDKey ContextKey = "invocation_id"

	// MaxRecursionDepth is the maximum allowed recursion depth
	MaxRecursionDepth = 5

	// DefaultSubAgentTimeout is the default timeout for sub-agent calls
	DefaultSubAgentTimeout = 30 * time.Second
)

type CustomRunFunction added in v0.0.43

type CustomRunFunction func(ctx context.Context, input string, agent *Agent) (string, error)

CustomRunFunction represents a custom function that can replace the default Run behavior

type CustomRunStreamFunction added in v0.0.43

type CustomRunStreamFunction func(ctx context.Context, input string, agent *Agent) (<-chan interfaces.AgentStreamEvent, error)

CustomRunStreamFunction represents a custom function that can replace the default RunStream behavior

type LazyMCPConfig added in v0.0.42

type LazyMCPConfig struct {
	Name    string
	Type    string // "stdio" or "http"
	Command string
	Args    []string
	Env     []string
	URL     string
	Tools   []LazyMCPToolConfig
}

LazyMCPConfig holds configuration for lazy MCP server initialization

type LazyMCPToolConfig added in v0.0.42

type LazyMCPToolConfig struct {
	Name        string
	Description string
	Schema      interface{}
}

LazyMCPToolConfig holds configuration for a lazy MCP tool

type Option

type Option func(*Agent)

Option represents an option for configuring an agent

func WithAgentConfig added in v0.0.3

func WithAgentConfig(config AgentConfig, variables map[string]string) Option

WithAgentConfig sets the agent configuration from a YAML config

func WithAgents added in v0.0.26

func WithAgents(subAgents ...*Agent) Option

WithAgents sets the sub-agents that can be called as tools

func WithCustomRunFunction added in v0.0.43

func WithCustomRunFunction(fn CustomRunFunction) Option

WithCustomRunFunction sets a custom run function that replaces the default Run behavior

func WithCustomRunStreamFunction added in v0.0.43

func WithCustomRunStreamFunction(fn CustomRunStreamFunction) Option

WithCustomRunStreamFunction sets a custom streaming run function that replaces the default RunStream behavior

func WithDescription added in v0.0.20

func WithDescription(description string) Option

WithDescription sets the description for the agent

func WithGuardrails

func WithGuardrails(guardrails interfaces.Guardrails) Option

WithGuardrails sets the guardrails for the agent

func WithLLM

func WithLLM(llm interfaces.LLM) Option

WithLLM sets the LLM for the agent

func WithLLMConfig added in v0.0.11

func WithLLMConfig(config interfaces.LLMConfig) Option

func WithLazyMCPConfigs added in v0.0.42

func WithLazyMCPConfigs(configs []LazyMCPConfig) Option

WithLazyMCPConfigs sets the lazy MCP server configurations for the agent

func WithLogger added in v0.0.36

func WithLogger(logger logging.Logger) Option

WithLogger sets the logger for the agent

func WithMCPServers added in v0.0.13

func WithMCPServers(mcpServers []interfaces.MCPServer) Option

WithMCPServers sets the MCP servers for the agent

func WithMaxIterations added in v0.0.19

func WithMaxIterations(maxIterations int) Option

WithMaxIterations sets the maximum number of tool-calling iterations for the agent

func WithMemory

func WithMemory(memory interfaces.Memory) Option

WithMemory sets the memory for the agent

func WithName added in v0.0.2

func WithName(name string) Option

WithName sets the name for the agent

func WithOrgID

func WithOrgID(orgID string) Option

WithOrgID sets the organization ID for multi-tenancy

func WithRemoteTimeout added in v0.0.29

func WithRemoteTimeout(timeout time.Duration) Option

WithRemoteTimeout sets the timeout for remote agent operations

func WithRequirePlanApproval added in v0.0.2

func WithRequirePlanApproval(require bool) Option

WithRequirePlanApproval sets whether execution plans require user approval

func WithResponseFormat added in v0.0.4

func WithResponseFormat(formatType interfaces.ResponseFormat) Option

WithResponseFormat sets the response format for the agent

func WithStreamConfig added in v0.0.46

func WithStreamConfig(config *interfaces.StreamConfig) Option

WithStreamConfig sets the streaming configuration for the agent

func WithSystemPrompt

func WithSystemPrompt(prompt string) Option

WithSystemPrompt sets the system prompt for the agent

func WithTools

func WithTools(tools ...interfaces.Tool) Option

WithTools sets the tools for the agent

func WithTracer

func WithTracer(tracer interfaces.Tracer) Option

WithTracer sets the tracer for the agent

func WithURL added in v0.0.26

func WithURL(url string) Option

WithURL creates a remote agent that communicates via gRPC

type ResponseFormatConfig added in v0.0.24

type ResponseFormatConfig struct {
	Type             string                 `yaml:"type"`
	SchemaName       string                 `yaml:"schema_name"`
	SchemaDefinition map[string]interface{} `yaml:"schema_definition"`
}

ResponseFormatConfig represents the configuration for the response format of an agent or task

type SubAgentContext added in v0.0.26

type SubAgentContext struct {
	ParentAgent    string
	SubAgentName   string
	RecursionDepth int
	InvocationID   string
	StartTime      time.Time
}

SubAgentContext contains context information for sub-agent invocations

type TaskConfig added in v0.0.3

type TaskConfig struct {
	Description    string                `yaml:"description"`
	ExpectedOutput string                `yaml:"expected_output"`
	Agent          string                `yaml:"agent"`
	OutputFile     string                `yaml:"output_file,omitempty"`
	ResponseFormat *ResponseFormatConfig `yaml:"response_format,omitempty"`
}

TaskConfig represents a task definition loaded from YAML

type TaskConfigs added in v0.0.3

type TaskConfigs map[string]TaskConfig

TaskConfigs represents a map of task configurations

func LoadTaskConfigsFromDir added in v0.0.3

func LoadTaskConfigsFromDir(dirPath string) (TaskConfigs, error)

LoadTaskConfigsFromDir loads all task configurations from YAML files in a directory

func LoadTaskConfigsFromFile added in v0.0.3

func LoadTaskConfigsFromFile(filePath string) (TaskConfigs, error)

LoadTaskConfigsFromFile loads task configurations from a YAML file

Jump to

Keyboard shortcuts

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