Skip to main content

Module settings

Module settings 

Source
Expand description

Lightweight settings helpers: a secret-masking string newtype and a precedence-based value loader.

This mirrors upstream’s _settings.py, which replaced a pydantic-settings-based AFBaseSettings with a function-based loader (load_settings) plus a repr-masking SecretString. Rather than port the Python TypedDict-driven schema loader (which leans on runtime reflection that has no idiomatic Rust equivalent), this module provides the two reusable primitives:

  • SecretString — a String newtype whose Debug/Display impls mask the value so secrets never leak into logs. It deserializes from a plain string — reading a secret in from config is what it is for — and deliberately does not implement Serialize, so a struct holding one cannot be JSON-encoded into a log line or a checkpoint by accident; see the type’s own docs for why a masked Serialize would be worse than none.
  • load_setting — a single-value loader implementing the same precedence as upstream’s load_settings: explicit override, then a .env file, then the process environment, then a default.

§Example

use agent_framework_core::settings::SecretString;

let key = SecretString::new("sk-super-secret");
assert_eq!(format!("{key}"), "***");
assert_eq!(format!("{key:?}"), "SecretString(\"***\")");
assert_eq!(key.expose_secret(), "sk-super-secret");

Structs§

SecretString
A string wrapper that masks its value when printed via Debug or Display, to prevent secrets (API keys, tokens, passwords, …) from accidentally ending up in logs or error messages.

Functions§

load_setting
Resolve a single setting value using the same precedence as upstream’s load_settings: