Skip to content

Configuration

The pf_config crate provides layered configuration loading — JSON files, .env files, and OS environment variables are merged in precedence order, giving you a single unified config value. The config-loader feature on agent_sdk integrates this into AgentBuilder::from_config_path().

[dependencies]
agent_sdk = { workspace = true, features = ["config-loader"] }

Optional pf_config sub-features:

FeatureWhat it enables
dotenvLoad .env files via dotenvy
cargo-tomlRead config from [package.metadata] in Cargo.toml
  1. Create an agent-config.json file with your agent settings.

  2. Call AgentBuilder::from_config_path("agent-config.json") — this loads JSON, overlays env vars, and returns a configured builder.

  3. Optionally chain builder methods to override specific settings.

  4. Call .build() to get the agent.

use agent_sdk::AgentBuilder;
let agent = AgentBuilder::from_config_path("agent-config.json")?
.build()?;
assert_eq!(agent.config().name, "my-agent");
{
"agent": {
"name": "my-agent",
"description": "A helpful assistant agent",
"version": "1.0.0",
"max_message_size": 1048576,
"streaming": true,
"batch_processing": false,
"concurrent_tasks": 10,
"stateless_methods": false,
"base_url": "https://my-agent.example.com",
"history_policy": {
"mode": "sliding_window",
"strategy": "sliding_window",
"context_window_tokens": 128000,
"max_output_tokens": 16384,
"enable_summarization": false,
"enable_long_term_memory": false,
"recall_top_k": 5,
"memory_token_budget": 2000
}
},
"observability": {
"service_name": "my-agent",
"service_version": "1.0.0",
"otel": { "enabled": true },
"prometheus": { "enabled": false }
}
}
FieldTypeDefaultDescription
nameString"sdk-agent"Agent name (used in agent card)
descriptionString"Agent built with SDK"Human-readable description
versionString"1.0.0"Semantic version
max_message_sizeu641048576 (1 MB)Maximum incoming message size in bytes
streamingboolfalseWhether the agent advertises streaming support
batch_processingboolfalseWhether the agent supports batch processing
concurrent_tasksOption<u32>Some(10)Max concurrent tasks (None = unlimited)
stateless_methodsboolfalsePrefer lightweight Message responses over Task
base_urlOption<String>NoneBase URL for absolute agent card interface URLs
history_policyOption<HistoryPolicyConfig>NoneHistory management strategy for durable continuation

Sources are merged in order (later wins):

  1. Cargo.toml section (lowest, requires cargo-toml feature)

  2. JSON files — in order; later files override earlier

  3. .env file (requires dotenv feature)

  4. OS environment variables (highest precedence)

Environment variables with the prefix AGENT_ are automatically merged into the config tree. Double underscores (__) denote nesting:

Env varJSON path
AGENT_AGENT__NAME=bot{ "agent": { "name": "bot" } }
AGENT_AGENT__STREAMING=true{ "agent": { "streaming": true } }
AGENT_OBSERVABILITY__SERVICE_NAME=x{ "observability": { "service_name": "x" } }

This means you can override any JSON config value at deploy time without changing files:

Terminal window
AGENT_AGENT__NAME=production-bot \
AGENT_AGENT__STREAMING=true \
./my-agent

For custom config structures outside of AgentBuilder:

use pf_config::{load_config_untyped, LoadOptions};
use std::path::PathBuf;
let opts = LoadOptions {
json_paths: vec![PathBuf::from("./config.json")],
enable_dotenv: true,
env_prefix: Some("AGENT_"),
..Default::default()
};
let value: serde_json::Value = load_config_untyped(opts)?;
println!("agent.name = {}", value["agent"]["name"]);
FieldTypeDefaultDescription
json_pathsVec<PathBuf>["./config.json"]JSON files to load (in order, later wins)
enable_dotenvbooltrueWhether to load .env file
env_prefixOption<&'static str>Some("AGENT_")Prefix for env var matching
env_key_transformEnvKeyTransformDoubleUnderscoreToNestedHow env var keys map to nested JSON
requiredboolfalseError if no config sources found
cargoOption<CargoTomlOptions>NoneCargo.toml section config (requires cargo-toml feature)
TypeModuleDescription
AgentBuilder::from_config_path()agent_sdkLoad config and build an agent in one step
AgentConfigagent_sdk::agent::configDeserialized agent configuration
HistoryPolicyConfigagent_sdk::agent::configHistory management settings
HistoryPolicyModeagent_sdk::agent::configPassThrough or HistoryManager
HistoryStrategyKindagent_sdk::agent::configSlidingWindow, SlidingWindowWithSummary, PriorityBased
load_config_untyped()pf_configReturns serde_json::Value
load_config::<T>()pf_configDeserializes into T: DeserializeOwned
LoadOptionspf_configAll loading options: paths, env prefix, dotenv, required
EnvKeyTransformpf_configDoubleUnderscoreToNested — env key nesting strategy
ConfigErrorpf_configNotFound, TypeMismatch, parse errors