A ready-to-run example is available here!
OpenHandsAgentSettings gives you a structured, serializable way to define an agent’s model, tools, and optional subsystems like the condenser. Use it when you want to store agent configuration in JSON, send it over an API, or rebuild agents from validated settings later.
Why Use Agent Settings
- Keep agent configuration as data instead of wiring everything together imperatively.
- Validate settings with Pydantic before creating an agent.
- Serialize and deserialize settings for storage, transport, or UI-driven configuration.
- Create different agent variants by changing only the settings payload.
Build Settings
Create anOpenHandsAgentSettings object with the same ingredients you would normally pass to an Agent.
Serialize and Restore Settings
BecauseOpenHandsAgentSettings is a Pydantic model, you can dump it to JSON-compatible data and restore it later.
- Saving agent configuration in a database
- Sending settings through an API
- Letting users edit agent configuration in a form-based UI
- Rehydrating the same agent setup in another process
Load Persisted Settings
model_validate only accepts payloads that already match the current schema. Use from_persisted for data written by an older SDK version: it applies the registered schema migrations first, then validates the migrated payload against the class you call it on.
from_persisted is defined on AgentSettingsBase, so it is a concrete-variant loader: OpenHandsAgentSettings.from_persisted() returns an OpenHandsAgentSettings and ACPAgentSettings.from_persisted() returns an ACPAgentSettings. When you do not know which variant a payload holds, use validate_agent_settings (also in openhands.sdk.settings) instead — it dispatches across the settings union.
Passing an already-validated instance of that variant returns it unchanged, so its secrets are preserved without a lossy serialization round trip.
The deprecated
agent_kind="llm" discriminator is only rewritten while migrating between schema versions. A payload that is already at the current schema version but still carries agent_kind="llm" is therefore rejected by OpenHandsAgentSettings.from_persisted. Load those payloads with validate_agent_settings, which canonicalizes the discriminator unconditionally.Encrypted Payloads
Secret-bearing fields only decrypt when you pass the same validation context that was used to write them.Errors
Create an Agent from Settings
Once validated, create a working agent directly from the settings object.Conversation, or derive another agent by changing the settings payload. For example, the full example below also shows how removing FileEditorTool and disabling the condenser produces a different agent configuration without rewriting the rest of the setup.
Ready-to-run Example
This example is available on GitHub: examples/01_standalone_sdk/46_agent_settings.py
examples/01_standalone_sdk/46_agent_settings.py
The model name should follow the LiteLLM convention:
provider/model_name (e.g., anthropic/claude-sonnet-4-5-20250929, openai/gpt-4o).
The LLM_API_KEY should be the API key for your chosen provider.Next Steps
- Getting Started - Start from a minimal agent and conversation setup
- Context Condenser - Control conversation compaction behavior
- TaskToolSet - Compose specialized sub-agents for larger tasks

