client

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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 APIConfig

type APIConfig struct {
	RequestTimeout int `yaml:"request_timeout"`

	MaxRetries int `yaml:"max_retries"`

	RetryDelay int `yaml:"retry_delay"`
}

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

func NewClient(config *Config) (*Client, error)

NewClient creates a new GoAgent client instance. Args: config - client configuration. Returns new client instance or error.

func NewClientFromConfigPath

func NewClientFromConfigPath(configPath string) (*Client, error)

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

func NewClientFromDefaultPath() (*Client, error)

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

func (c *Client) Agent() (*agentSvc.Service, error)

Agent returns the agent service. Returns the agent service or an error if not configured.

func (*Client) Close

func (c *Client) Close(ctx context.Context) error

Close closes the client and cleans up resources.

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

func (c *Client) LLM() (*llmSvc.Service, error)

LLM returns the LLM service. Returns the LLM service or an error if not configured.

func (*Client) Memory

func (c *Client) Memory() (*memorySvc.Service, error)

Memory returns the memory service. Returns the memory service or an error if not configured.

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) bool

Ping checks if all configured services are available. Returns true if all services are available, false otherwise.

func (*Client) Retrieval

func (c *Client) Retrieval() (*retrievalSvc.Service, error)

Retrieval returns the retrieval service. Returns the retrieval 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 DatabaseConfig struct {
	Enabled bool `yaml:"enabled"`

	Type string `yaml:"type"`

	Host string `yaml:"host"`

	Port int `yaml:"port"`

	User string `yaml:"username"`

	Password string `yaml:"password"`

	DBName string `yaml:"database"`

	SSLMode string `yaml:"ssl_mode"`
}

type LeaderAgentConfig

type LeaderAgentConfig struct {
	ID string `yaml:"id"`

	MaxSteps int `yaml:"max_steps"`

	MaxParallelTasks int `yaml:"max_parallel_tasks"`
}

type MemoryConfig

type MemoryConfig struct {
	Enabled bool `yaml:"enabled"`

	Session struct {
		MaxHistory int `yaml:"max_history"`
	} `yaml:"session"`
}

type OutputConfig

type OutputConfig struct {
	Format string `yaml:"format"`
}

type PromptsConfig

type PromptsConfig struct {
	ProfileExtraction string `yaml:"profile_extraction"`

	Recommendation string `yaml:"recommendation"`
}

type ServerConfig

type ServerConfig struct {
	Host string `yaml:"host"`

	Port int `yaml:"port"`
}

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

func (s *SimpleClient) Chat(ctx context.Context, messages []*core.Message) (string, error)

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

func (s *SimpleClient) Execute(ctx context.Context, query string) (string, error)

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

func (s *SimpleClient) ExecuteWithAgent(ctx context.Context, agentID, query string) (string, error)

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 StorageConfig struct {
	Enabled bool `yaml:"enabled"`

	Type string `yaml:"type"`
}

type SubAgentConfig

type SubAgentConfig struct {
	ID string `yaml:"id"`

	Type string `yaml:"type"`

	Category string `yaml:"category"`

	Name string `yaml:"name"`

	MaxRetries int `yaml:"max_retries"`

	Timeout int `yaml:"timeout"`
}

type WorkflowAgentExecutor

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

func (*WorkflowAgentExecutor) ID

func (e *WorkflowAgentExecutor) ID() string

func (*WorkflowAgentExecutor) Process

func (e *WorkflowAgentExecutor) Process(ctx context.Context, input any) (any, error)

func (*WorkflowAgentExecutor) Start

func (*WorkflowAgentExecutor) Status

func (*WorkflowAgentExecutor) Stop

func (*WorkflowAgentExecutor) Type

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

func (w *WorkflowClient) LoadWorkflow(ctx context.Context, path string) (*engine.Workflow, error)

LoadWorkflow loads a workflow from a YAML file. Args: ctx - operation context. path - path to workflow YAML file. Returns loaded workflow or error.

Jump to

Keyboard shortcuts

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