Agent configuration loader and normalizer for AI/LLM applications
Project description
agent-config
A lightweight Python library and CLI for loading, merging, and validating agent configurations from files and environment variables.
Installation
pip install agent-config
For TOML support on Python < 3.11:
pip install agent-config[toml]
Quick Start
CLI Usage
Initialize a new configuration file:
agent-config init
This creates an agent.config.yaml file with sensible defaults.
Print the resolved configuration:
agent-config print --pretty
Get a specific value:
agent-config get model
agent-config get tools.0.name
Validate your configuration:
agent-config validate
Library Usage
from agent_config import load_config, validate_config
# Load configuration from file + environment
config = load_config()
# Access values
print(config["model"])
print(config["temperature"])
# Validate a configuration dict
issues = validate_config(config)
for issue in issues:
print(f"{issue.level}: {issue.message}")
Configuration Sources
Configuration is loaded and merged from multiple sources in this order (later sources override earlier ones):
- Built-in defaults - Sensible defaults for all fields
- Configuration file - YAML, JSON, or TOML
- Environment variables - Highest precedence
Configuration Files
The CLI automatically discovers configuration files in this order:
agent.config.yamlagent.config.ymlagent.config.jsonagent.config.toml.agent-configrc.agent-configrc.json
Example Configuration (YAML)
name: my-agent
model: gpt-4
temperature: 0.2
max_tokens: 4096
system_prompt: "You are a helpful assistant."
api_base: https://api.openai.com/v1
timeout_ms: 60000
tools:
- name: web_search
enabled: true
config:
max_results: 10
Example Configuration (JSON)
{
"name": "my-agent",
"model": "gpt-4",
"temperature": 0.2,
"max_tokens": 4096,
"system_prompt": "You are a helpful assistant.",
"timeout_ms": 60000,
"tools": [
{
"name": "web_search",
"enabled": true
}
]
}
Environment Variables
Override any configuration value using environment variables:
| Environment Variable | Config Key | Type |
|---|---|---|
AGENT_NAME |
name |
string |
AGENT_MODEL |
model |
string |
AGENT_TEMPERATURE |
temperature |
float |
AGENT_TOP_P |
top_p |
float |
AGENT_MAX_TOKENS |
max_tokens |
int |
AGENT_SYSTEM_PROMPT |
system_prompt |
string |
AGENT_PROMPT_FILE |
prompt_file |
string |
AGENT_API_BASE |
api_base |
string |
AGENT_API_KEY |
api_key |
string |
AGENT_TIMEOUT_MS |
timeout_ms |
int |
AGENT_TOOLS_JSON |
tools |
JSON array |
Example:
export AGENT_MODEL="gpt-4-turbo"
export AGENT_TEMPERATURE="0.5"
export AGENT_API_KEY="sk-..."
agent-config print
CLI Reference
agent-config print
Print the resolved configuration as JSON.
agent-config print [OPTIONS]
Options:
-f, --file PATH Path to configuration file
-C, --cwd PATH Working directory for config discovery
-p, --pretty Pretty-print JSON output
--strict Fail if no configuration file is found
--no-env Ignore environment variable overrides
--redact Redact sensitive values (default)
--no-redact Show sensitive values (use with caution)
agent-config get
Get a specific value by dot-notation path.
agent-config get PATH [OPTIONS]
Options:
-f, --file PATH Path to configuration file
-C, --cwd PATH Working directory for config discovery
-d, --default VAL Default value if path not found
-j, --json Output value as JSON
--strict Fail if no configuration file is found
--no-env Ignore environment variable overrides
Examples:
agent-config get model
agent-config get temperature --default 0.7
agent-config get tools.0.name
agent-config get tools --json
agent-config validate
Validate configuration and report issues.
agent-config validate [OPTIONS]
Options:
-f, --file PATH Path to configuration file
-C, --cwd PATH Working directory for config discovery
-j, --json Output issues as JSON
--strict Fail if no configuration file is found
--no-env Ignore environment variable overrides
Exit codes:
0- Valid configuration1- Validation errors found
agent-config init
Create a starter configuration file.
agent-config init [OPTIONS]
Options:
-t, --format FMT File format: yaml or json (default: yaml)
-f, --force Overwrite existing configuration file
-C, --cwd PATH Directory to create configuration file in
Library API
load_config()
Load and merge configuration from all sources.
from agent_config import load_config
config = load_config(
file=None, # Explicit path to config file
cwd=None, # Working directory for discovery
strict=False, # Require config file to exist
use_env=True, # Apply environment overrides
env=None, # Custom environment dict
redact=False, # Mask sensitive values
)
validate_config()
Validate a configuration dictionary.
from agent_config import validate_config, ValidationIssue
issues = validate_config(config)
for issue in issues:
print(f"[{issue.level}] {issue.path}: {issue.message}")
ValidationIssue
@dataclass
class ValidationIssue:
level: Literal["error", "warn"]
path: str | None
message: str
ConfigError
Raised when configuration loading or validation fails.
from agent_config import load_config, ConfigError
try:
config = load_config(strict=True)
except ConfigError as e:
print(f"Config error: {e}")
for issue in e.issues:
print(f" - {issue}")
Sensitive Data Handling
By default, the CLI redacts sensitive values (fields matching key, token, secret, password) when printing configuration. Use --no-redact to disable this behavior.
Warning: Be careful when using --no-redact in logs or shared environments.
Configuration Schema
| Field | Type | Default | Description |
|---|---|---|---|
name |
string | null | Agent identifier |
model |
string | null | Model name/identifier |
temperature |
float | 0.2 | Sampling temperature |
top_p |
float | null | Nucleus sampling parameter |
max_tokens |
int | null | Maximum tokens to generate |
system_prompt |
string | null | System prompt text |
prompt_file |
string | null | Path to system prompt file |
tools |
array | [] | Tool configurations |
api_base |
string | null | API base URL |
api_key |
string | null | API key |
timeout_ms |
int | 60000 | Request timeout in milliseconds |
Additional keys are preserved and passed through.
Import Name
Note: The PyPI package name is agent-config (with hyphen), but the Python import name uses underscores:
import agent_config
This follows Python naming conventions since hyphens are not valid in Python identifiers.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agent_config-0.1.0.tar.gz.
File metadata
- Download URL: agent_config-0.1.0.tar.gz
- Upload date:
- Size: 21.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a604a8995c04312f4cafdd3b79d84ccd0ba81a9c920f0673e8fb1719c72d234b
|
|
| MD5 |
8e692b77e4f9c47e5916d346711ae643
|
|
| BLAKE2b-256 |
ed21f2e183db90a1d72f4f15b14128af715d3e12e9711aca294fedb381c266ee
|
File details
Details for the file agent_config-0.1.0-py3-none-any.whl.
File metadata
- Download URL: agent_config-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8bfa7f138394ae588ef637def7653feb15cf9640868425e316d05dcb6ed33f60
|
|
| MD5 |
3f96d471ebc655aff7bc7d0e848e57e8
|
|
| BLAKE2b-256 |
4c7f0702696d750be72a0fa5627eb605d00447da8c27e88921c3efd7210339dd
|