|
| 1 | +# Agent Configuration |
| 2 | + |
| 3 | +The Strands SDK supports loading agent configuration from JSON files following the [agent-format.md specification](https://github.com/aws/amazon-q-developer-cli/blob/main/docs/agent-format.md) used by Amazon Q Developer CLI. |
| 4 | + |
| 5 | +## Basic Usage |
| 6 | + |
| 7 | +You can initialize an Agent using a configuration file: |
| 8 | + |
| 9 | +```python |
| 10 | +from strands import Agent |
| 11 | + |
| 12 | +# Load from configuration file |
| 13 | +agent = Agent(config="/path/to/agent-config.json") |
| 14 | + |
| 15 | +# Or from a configuration dictionary |
| 16 | +config = { |
| 17 | + "tools": ["shell", "calculator"], |
| 18 | + "model": "us.anthropic.claude-sonnet-4-20250514-v1:0", |
| 19 | + "prompt": "You are a helpful coding assistant" |
| 20 | +} |
| 21 | +agent = Agent(config=config) |
| 22 | +``` |
| 23 | + |
| 24 | +## Supported Configuration Fields |
| 25 | + |
| 26 | +Currently, the following fields from the agent-format.md specification are supported: |
| 27 | + |
| 28 | +### `tools` |
| 29 | +List of tools available to the agent. Tools can be specified as: |
| 30 | + |
| 31 | +1. **Tool names from strands_tools** (recommended): |
| 32 | +```json |
| 33 | +{ |
| 34 | + "tools": ["calculator", "shell", "current_time"] |
| 35 | +} |
| 36 | +``` |
| 37 | + |
| 38 | +2. **File paths** to custom tool files: |
| 39 | +```json |
| 40 | +{ |
| 41 | + "tools": ["./tools/my_custom_tool.py", "/path/to/another_tool.py"] |
| 42 | +} |
| 43 | +``` |
| 44 | + |
| 45 | +3. **Tool objects** (when using Python dict config): |
| 46 | +```python |
| 47 | +from strands_tools import calculator, shell |
| 48 | + |
| 49 | +config = { |
| 50 | + "tools": [calculator, shell], |
| 51 | + "model": "us.anthropic.claude-sonnet-4-20250514-v1:0", |
| 52 | + "prompt": "You are a helpful assistant" |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +### `model` |
| 57 | +Model ID to use for the agent (must be full Bedrock model ID): |
| 58 | + |
| 59 | +```json |
| 60 | +{ |
| 61 | + "model": "us.anthropic.claude-sonnet-4-20250514-v1:0" |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +### `prompt` |
| 66 | +System prompt for the agent (maps to `system_prompt` parameter): |
| 67 | + |
| 68 | +```json |
| 69 | +{ |
| 70 | + "prompt": "You are a helpful assistant specialized in Python development" |
| 71 | +} |
| 72 | +``` |
| 73 | + |
| 74 | +## Example Configuration File |
| 75 | + |
| 76 | +Create a file named `my-agent.json`: |
| 77 | + |
| 78 | +```json |
| 79 | +{ |
| 80 | + "tools": [ |
| 81 | + "calculator", |
| 82 | + "shell", |
| 83 | + "current_time" |
| 84 | + ], |
| 85 | + "model": "us.anthropic.claude-sonnet-4-20250514-v1:0", |
| 86 | + "prompt": "You are an expert Python developer. Help users write clean, efficient code." |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +Then load it in your Python code: |
| 91 | + |
| 92 | +```python |
| 93 | +from strands import Agent |
| 94 | + |
| 95 | +agent = Agent(config="my-agent.json") |
| 96 | +result = agent("Help me write a function to parse JSON files") |
| 97 | +print(result.message) |
| 98 | +``` |
| 99 | + |
| 100 | +## Parameter Precedence |
| 101 | + |
| 102 | +Constructor parameters take precedence over configuration file values: |
| 103 | + |
| 104 | +```python |
| 105 | +# Config file has model: "us.anthropic.claude-3-haiku-20240307-v1:0" |
| 106 | +# But constructor parameter overrides it |
| 107 | +agent = Agent( |
| 108 | + config="my-agent.json", |
| 109 | + model="us.anthropic.claude-sonnet-4-20250514-v1:0" # This takes precedence |
| 110 | +) |
| 111 | +``` |
| 112 | + |
| 113 | +## Backward Compatibility |
| 114 | + |
| 115 | +The configuration feature is fully backward compatible. Existing Agent initialization continues to work unchanged: |
| 116 | + |
| 117 | +```python |
| 118 | +# This still works exactly as before |
| 119 | +from strands_tools import shell |
| 120 | + |
| 121 | +agent = Agent( |
| 122 | + model="us.anthropic.claude-sonnet-4-20250514-v1:0", |
| 123 | + tools=[shell], |
| 124 | + system_prompt="You are helpful" |
| 125 | +) |
| 126 | +``` |
| 127 | + |
| 128 | +## Error Handling |
| 129 | + |
| 130 | +The SDK provides clear error messages for configuration issues: |
| 131 | + |
| 132 | +```python |
| 133 | +try: |
| 134 | + agent = Agent(config="/nonexistent/config.json") |
| 135 | +except ValueError as e: |
| 136 | + print(f"Configuration error: {e}") |
| 137 | + # Output: Configuration error: Failed to load agent configuration: Agent config file not found: /nonexistent/config.json |
| 138 | +``` |
| 139 | + |
| 140 | +## Future Enhancements |
| 141 | + |
| 142 | +Additional fields from the agent-format.md specification may be supported in future releases, including: |
| 143 | + |
| 144 | +- `mcpServers` - MCP server configurations |
| 145 | +- `allowedTools` - Tool permission settings |
| 146 | +- `resources` - File and resource access |
| 147 | +- `hooks` - Lifecycle event handlers |
| 148 | + |
| 149 | +For the complete specification, see the [agent-format.md documentation](https://github.com/aws/amazon-q-developer-cli/blob/main/docs/agent-format.md). |
0 commit comments