config

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 5 Imported by: 8

Documentation

Overview

Package config provides configuration management for the go-agents library. It defines structures for agent, model, provider, and transport configuration with support for human-readable duration strings and JSON serialization.

Configuration files use hierarchical JSON structure with transport-based organization. Example:

{
  "name": "my-agent",
  "system_prompt": "You are a helpful assistant",
  "transport": {
    "provider": {
      "name": "ollama",
      "base_url": "http://localhost:11434",
      "model": {
        "name": "llama3.2:3b",
        "capabilities": {
          "chat": {"format": "openai-chat", "options": {...}}
        }
      }
    },
    "timeout": "24s",
    "connection_pool_size": 10
  }
}

Duration values support human-readable strings ("24s", "1m", "2h") or numeric nanoseconds for programmatic configuration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentConfig

type AgentConfig struct {
	Name         string          `json:"name"`
	SystemPrompt string          `json:"system_prompt,omitempty"`
	Format       string          `json:"format,omitempty"`
	Client       *ClientConfig   `json:"client,omitempty"`
	Provider     *ProviderConfig `json:"provider"`
	Model        *ModelConfig    `json:"model"`
}

AgentConfig defines the complete configuration for an agent. It includes the agent name, optional system prompt, optional client settings, provider configuration, and model configuration.

func DefaultAgentConfig

func DefaultAgentConfig() AgentConfig

DefaultAgentConfig creates an AgentConfig with default values.

func LoadAgentConfig

func LoadAgentConfig(filename string) (*AgentConfig, error)

LoadAgentConfig loads an AgentConfig from a JSON file and merges it with defaults. Returns an error if the file cannot be read or the JSON is invalid.

func (*AgentConfig) Merge

func (c *AgentConfig) Merge(source *AgentConfig)

Merge combines the source AgentConfig into this AgentConfig. Non-empty values from source override the current values.

type ClientConfig added in v0.2.0

type ClientConfig struct {
	Timeout            Duration    `json:"timeout"`
	Retry              RetryConfig `json:"retry"`
	ConnectionPoolSize int         `json:"connection_pool_size"`
	ConnectionTimeout  Duration    `json:"connection_timeout"`
}

ClientConfig defines the configuration for the HTTP client layer. It includes timeout settings, retry behavior, and connection pooling parameters.

func DefaultClientConfig added in v0.2.0

func DefaultClientConfig() *ClientConfig

DefaultClientConfig creates a ClientConfig with default values.

func (*ClientConfig) Merge added in v0.2.0

func (c *ClientConfig) Merge(source *ClientConfig)

Merge combines the source ClientConfig into this ClientConfig. Positive values from source override the current values. Zero values are ignored.

type Duration

type Duration time.Duration

Duration is a wrapper around time.Duration that supports JSON unmarshaling from both string format ("24s", "1m", "2h") and numeric nanoseconds.

Example JSON formats:

"timeout": "24s"           // string format
"timeout": 24000000000     // numeric nanoseconds

When marshaling to JSON, Duration outputs string format.

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for Duration. It outputs the duration in string format (e.g., "24s", "1m30s").

func (Duration) ToDuration

func (d Duration) ToDuration() time.Duration

ToDuration converts Duration to time.Duration.

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler for Duration. It accepts both string duration format ("24s", "1m", "2h") and numeric nanoseconds. Returns an error if the value cannot be parsed as either format.

type ModelConfig

type ModelConfig struct {
	Name         string                    `json:"name,omitempty"`
	Capabilities map[string]map[string]any `json:"capabilities,omitempty"`
}

ModelConfig defines the configuration for an LLM model. Name is the model identifier (e.g., "gpt-4o", "claude-3-opus", "llama3.1:8b"). Capabilities maps protocol names to their default options.

Example JSON:

{
  "name": "gpt-4o",
  "capabilities": {
    "chat": {
      "temperature": 0.7,
      "max_tokens": 4096
    },
    "vision": {
      "temperature": 0.5,
      "max_tokens": 2048
    }
  }
}

func DefaultModelConfig

func DefaultModelConfig() *ModelConfig

DefaultModelConfig creates a ModelConfig with initialized empty capabilities.

func (*ModelConfig) Merge

func (c *ModelConfig) Merge(source *ModelConfig)

Merge combines the source ModelConfig into this ModelConfig. Non-empty name from source overrides the current value. Capabilities are merged at the protocol level.

type ProviderConfig

type ProviderConfig struct {
	Name    string         `json:"name"`
	BaseURL string         `json:"base_url"`
	Options map[string]any `json:"options"`
}

ProviderConfig defines the configuration for an LLM provider. It includes the provider name, base URL, and provider-specific options (e.g., deployment, API version, authentication type).

func DefaultProviderConfig

func DefaultProviderConfig() *ProviderConfig

DefaultProviderConfig creates a ProviderConfig with Ollama defaults. BaseURL is intentionally empty — providers auto-construct their default base URL when not explicitly configured (e.g., Ollama defaults to localhost:11434, Bedrock constructs from region).

func (*ProviderConfig) Merge

func (c *ProviderConfig) Merge(source *ProviderConfig)

Merge combines the source ProviderConfig into this ProviderConfig. Non-empty name, base_url, and options from source override the current values.

type RetryConfig added in v0.2.0

type RetryConfig struct {
	MaxRetries        int      `json:"max_retries"`
	InitialBackoff    Duration `json:"initial_backoff"`
	MaxBackoff        Duration `json:"max_backoff"`
	BackoffMultiplier float64  `json:"backoff_multiplier"`
	Jitter            bool     `json:"jitter"`
}

RetryConfig configures retry behavior for failed requests. Implements exponential backoff with jitter for transient failures.

func DefaultRetryConfig added in v0.2.0

func DefaultRetryConfig() RetryConfig

DefaultRetryConfig creates a RetryConfig with default values. Retries up to 3 times with exponential backoff starting at 1s, capped at 30s.

Jump to

Keyboard shortcuts

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