Documentation
¶
Overview ¶
Package client provides client interface for GoAgent API.
Package client provides configuration loading utilities for the GoAgent client.
Package client provides error definitions for API client.
Package client provides simple, fool-proof API for GoAgent.
Package client provides workflow orchestration functionality.
Index ¶
- Variables
- func SetAllowedConfigDir(dir string)
- type APIConfig
- type AgentsConfig
- type Client
- func (c *Client) Agent() (*agentSvc.Service, error)
- func (c *Client) Close(ctx context.Context) error
- func (c *Client) GetConfig() *ConfigFile
- func (c *Client) LLM() (*llmSvc.Service, error)
- func (c *Client) Memory() (*memorySvc.Service, error)
- func (c *Client) Ping(ctx context.Context) bool
- func (c *Client) Retrieval() (*retrievalSvc.Service, error)
- type Config
- type ConfigFile
- type ConfigLoader
- type ConfigLoaderOption
- type DatabaseConfig
- type LeaderAgentConfig
- type MemoryConfig
- type OutputConfig
- type PromptsConfig
- type ServerConfig
- type SimpleClient
- func (s *SimpleClient) Chat(ctx context.Context, messages []*core.Message) (string, error)
- func (s *SimpleClient) Close(ctx context.Context) error
- func (s *SimpleClient) Execute(ctx context.Context, query string) (string, error)
- func (s *SimpleClient) ExecuteWithAgent(ctx context.Context, agentID, query string) (string, error)
- func (s *SimpleClient) GetConfig() *ConfigFile
- type StorageConfig
- type SubAgentConfig
- type WorkflowAgentExecutor
- func (e *WorkflowAgentExecutor) ID() string
- func (e *WorkflowAgentExecutor) Process(ctx context.Context, input any) (any, error)
- func (e *WorkflowAgentExecutor) Start(ctx context.Context) error
- func (e *WorkflowAgentExecutor) Status() models.AgentStatus
- func (e *WorkflowAgentExecutor) Stop(ctx context.Context) error
- func (e *WorkflowAgentExecutor) Type() models.AgentType
- type WorkflowClient
- func (w *WorkflowClient) Execute(ctx context.Context, workflow *engine.Workflow, input string) (*engine.WorkflowResult, error)
- func (w *WorkflowClient) ExecuteFromFile(ctx context.Context, path, input string) (*engine.WorkflowResult, error)
- func (w *WorkflowClient) LoadWorkflow(ctx context.Context, path string) (*engine.Workflow, error)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidConfig is returned when config is nil or invalid. ErrInvalidConfig = errors.New("invalid config") // ErrAgentNotConfigured is returned when agent service is not configured. ErrAgentNotConfigured = errors.New("agent service not configured") // ErrMemoryNotConfigured is returned when memory service is not configured. ErrMemoryNotConfigured = errors.New("memory service not configured") // ErrRetrievalNotConfigured is returned when retrieval service is not configured. ErrRetrievalNotConfigured = errors.New("retrieval service not configured") // ErrLLMNotConfigured is returned when LLM service is not configured. ErrLLMNotConfigured = errors.New("LLM service not configured") )
Functions ¶
func SetAllowedConfigDir ¶
func SetAllowedConfigDir(dir string)
SetAllowedConfigDir sets the allowed directory for config files. This is a security measure to prevent path traversal attacks.
Types ¶
type AgentsConfig ¶
type AgentsConfig struct {
Leader LeaderAgentConfig `yaml:"leader"`
Sub []SubAgentConfig `yaml:"sub"`
}
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides a unified client interface for all GoAgent modules.
func NewClient ¶
NewClient creates a new GoAgent client instance. Args: config - client configuration. Returns new client instance or error.
func NewClientFromConfigPath ¶
NewClientFromConfigPath creates a new GoAgent client from a configuration file path. This is the simplest way to initialize the client - just provide the config file path. Args: configPath - path to the configuration file. Returns new client instance or error.
Example:
client, err := client.NewClientFromConfigPath("config.yaml")
if err != nil {
slog.Error(err)
}
defer client.Close(ctx)
func NewClientFromDefaultPath ¶
NewClientFromDefaultPath creates a new GoAgent client from default configuration paths. It searches for configuration files in standard locations. Returns new client instance or error.
func NewClientWithConfigFile ¶
func NewClientWithConfigFile(config *Config, configFile *ConfigFile) (*Client, error)
NewClientWithConfigFile creates a new GoAgent client with both config and config file.
func (*Client) Agent ¶
Agent returns the agent service. Returns the agent service or an error if not configured.
func (*Client) GetConfig ¶
func (c *Client) GetConfig() *ConfigFile
GetConfig returns the loaded configuration file. Returns the configuration file structure or nil if not available.
func (*Client) LLM ¶
LLM returns the LLM service. Returns the LLM service or an error if not configured.
func (*Client) Memory ¶
Memory returns the memory service. Returns the memory service or an error if not configured.
type Config ¶
type Config struct {
BaseConfig *core.BaseConfig // Base configuration
Agent *agentSvc.Config // Agent service configuration
Memory *memorySvc.Config // Memory service configuration
Retrieval *retrievalSvc.Config // Retrieval service configuration
LLM *llmSvc.Config // LLM service configuration
}
Config holds configuration for the GoAgent client.
type ConfigFile ¶
type ConfigFile struct {
Server ServerConfig `yaml:"server"`
API APIConfig `yaml:"api"`
LLM core.LLMConfig `yaml:"llm"`
Database DatabaseConfig `yaml:"database"`
Storage StorageConfig `yaml:"storage"`
Memory MemoryConfig `yaml:"memory"`
Agents AgentsConfig `yaml:"agents"`
Prompts PromptsConfig `yaml:"prompts"`
Output OutputConfig `yaml:"output"`
}
func LoadConfigFile
deprecated
func LoadConfigFile(path string) (*ConfigFile, error)
LoadConfigFile loads configuration from a YAML file using default loader. This is a convenience function that creates a default ConfigLoader. Args: path - path to the configuration file. Returns loaded and validated configuration or error.
Deprecated: Use NewConfigLoader().Load(path) instead for more control.
func (*ConfigFile) ToClientConfig ¶
func (c *ConfigFile) ToClientConfig() *Config
ToClientConfig converts ConfigFile to client.Config. Returns client configuration instance.
type ConfigLoader ¶
type ConfigLoader struct {
// contains filtered or unexported fields
}
ConfigLoader provides configuration loading functionality with validation.
func NewConfigLoader ¶
func NewConfigLoader(opts ...ConfigLoaderOption) *ConfigLoader
NewConfigLoader creates a new configuration loader. Args: opts - optional configuration options. Returns new config loader instance.
func (*ConfigLoader) Load ¶
func (l *ConfigLoader) Load(path string) (*ConfigFile, error)
Load loads configuration from the specified path or default locations. Args: path - optional path to the configuration file. Returns loaded and validated configuration or error.
type ConfigLoaderOption ¶
type ConfigLoaderOption func(*ConfigLoader)
ConfigLoaderOption represents a configuration loader option.
func WithDefaultPaths ¶
func WithDefaultPaths(paths ...string) ConfigLoaderOption
WithDefaultPaths sets custom default search paths.
func WithEnvPrefix ¶
func WithEnvPrefix(prefix string) ConfigLoaderOption
WithEnvPrefix sets the environment variable prefix.
type DatabaseConfig ¶
type LeaderAgentConfig ¶
type MemoryConfig ¶
type OutputConfig ¶
type OutputConfig struct {
Format string `yaml:"format"`
}
type PromptsConfig ¶
type ServerConfig ¶
type SimpleClient ¶
type SimpleClient struct {
// contains filtered or unexported fields
}
SimpleClient provides the simplest possible API for GoAgent. Just configure and call!
func NewSimpleClient ¶
func NewSimpleClient(configPath string) (*SimpleClient, error)
NewSimpleClient creates a simple client from config file. This is the easiest way to use GoAgent - just load config and go! Args: configPath - path to config file (empty string for default). Returns simple client or error.
Example:
client, err := client.NewSimpleClient("config.yaml")
if err != nil {
slog.Error(err)
}
defer client.Close()
// Execute a task
result, err := client.Execute("user query here")
if err != nil {
slog.Error(err)
}
fmt.Println(result)
func (*SimpleClient) Chat ¶
Chat conducts a multi-turn conversation. Args: ctx - context for the operation. messages - list of messages in the conversation. Returns assistant's response or error.
Example:
messages := []core.Message{
{Role: core.MessageRoleUser, Content: "I want to buy clothes"},
{Role: core.MessageRoleAssistant, Content: "What style do you prefer?"},
{Role: core.MessageRoleUser, Content: "Casual style"},
}
response, err := client.Chat(ctx, messages)
if err != nil {
slog.Error(err)
}
fmt.Println(response)
func (*SimpleClient) Close ¶
func (s *SimpleClient) Close(ctx context.Context) error
Close closes the client and cleans up resources. Args: ctx - context for the operation. Returns error if cleanup fails.
func (*SimpleClient) Execute ¶
Execute executes a user query using the configured agents. This is the main entry point - just pass your question and get the answer! Args: ctx - context for the operation. query - user's question or task description. Returns result text or error.
Example:
result, err := client.Execute(ctx, "Find me some casual shirts for daily commute, budget 500-1000")
if err != nil {
slog.Error(err)
}
fmt.Println(result)
func (*SimpleClient) ExecuteWithAgent ¶
ExecuteWithAgent executes a query using a specific agent. Args: ctx - context for the operation. agentID - the ID of the agent to use. query - user's question or task description. Returns result text or error.
Example:
result, err := client.ExecuteWithAgent(ctx, "agent-top", "Recommend some casual shirts")
if err != nil {
slog.Error(err)
}
fmt.Println(result)
func (*SimpleClient) GetConfig ¶
func (s *SimpleClient) GetConfig() *ConfigFile
GetConfig returns the loaded configuration. Returns configuration file structure.
type StorageConfig ¶
type SubAgentConfig ¶
type WorkflowAgentExecutor ¶
type WorkflowAgentExecutor struct {
// contains filtered or unexported fields
}
func (*WorkflowAgentExecutor) ID ¶
func (e *WorkflowAgentExecutor) ID() string
func (*WorkflowAgentExecutor) Start ¶
func (e *WorkflowAgentExecutor) Start(ctx context.Context) error
func (*WorkflowAgentExecutor) Status ¶
func (e *WorkflowAgentExecutor) Status() models.AgentStatus
func (*WorkflowAgentExecutor) Stop ¶
func (e *WorkflowAgentExecutor) Stop(ctx context.Context) error
func (*WorkflowAgentExecutor) Type ¶
func (e *WorkflowAgentExecutor) Type() models.AgentType
type WorkflowClient ¶
type WorkflowClient struct {
// contains filtered or unexported fields
}
WorkflowClient provides workflow orchestration capabilities.
func NewWorkflowClient ¶
func NewWorkflowClient(client *Client) (*WorkflowClient, error)
NewWorkflowClient creates a new workflow client. Args: client - underlying GoAgent client. Returns workflow client or error.
func (*WorkflowClient) Execute ¶
func (w *WorkflowClient) Execute(ctx context.Context, workflow *engine.Workflow, input string) (*engine.WorkflowResult, error)
Execute executes a workflow with the given input. Args: ctx - operation context. workflow - workflow definition. input - initial input data. Returns workflow result or error.
func (*WorkflowClient) ExecuteFromFile ¶
func (w *WorkflowClient) ExecuteFromFile(ctx context.Context, path, input string) (*engine.WorkflowResult, error)
ExecuteFromFile loads and executes a workflow from a file. Args: ctx - operation context. path - path to workflow YAML file. input - initial input data. Returns workflow result or error.
func (*WorkflowClient) LoadWorkflow ¶
LoadWorkflow loads a workflow from a YAML file. Args: ctx - operation context. path - path to workflow YAML file. Returns loaded workflow or error.