Skip to content

Commit a895d25

Browse files
committed
update docs to match updated pr
1 parent 6a66da0 commit a895d25

File tree

1 file changed

+17
-129
lines changed

1 file changed

+17
-129
lines changed

docs/user-guide/concepts/experimental/agent-config.md

Lines changed: 17 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,6 @@ The experimental `config_to_agent` function provides a simple way to create agen
1414
- Support both file paths and dictionary configurations
1515
- Leverage the Agent class's built-in tool loading capabilities
1616

17-
!!! note "Tool Loading Limitations"
18-
Configuration-based agent setup only works for tools that don't require code-based instantiation. For tools that need constructor arguments or complex setup, use the programmatic approach after creating the agent:
19-
20-
```python
21-
import http.client
22-
from sample_module import ToolWithConfigArg
23-
24-
agent = config_to_agent("config.json")
25-
# Add tools that need code-based instantiation
26-
agent.process_tools([ToolWithConfigArg(http.client.HTTPSConnection("localhost"))])
27-
```
28-
2917
## Basic Usage
3018

3119
### Dictionary Configuration
@@ -93,21 +81,25 @@ The `tools` configuration supports Python-specific tool loading formats:
9381
}
9482
```
9583

96-
!!! important "Python Tool Support Only"
97-
Currently, tool loading is Python-specific and supports:
98-
99-
- **File paths**: Python files containing @tool annotated functions
100-
- **Module names**: Python modules with @tool annotated functions
101-
- **Function references**: Specific @tool annotated functions in modules
102-
103-
Support for tools in other languages will be added when MCP server support is introduced to this feature.
104-
10584
The Agent class handles all tool loading internally, including:
85+
10686
- Loading from module paths
10787
- Loading from file paths
10888
- Error handling for missing tools
10989
- Tool validation
11090

91+
!!! note "Tool Loading Limitations"
92+
Configuration-based agent setup only works for tools that don't require code-based instantiation. For tools that need constructor arguments or complex setup, use the programmatic approach after creating the agent:
93+
94+
```python
95+
import http.client
96+
from sample_module import ToolWithConfigArg
97+
98+
agent = config_to_agent("config.json")
99+
# Add tools that need code-based instantiation
100+
agent.process_tools([ToolWithConfigArg(http.client.HTTPSConnection("localhost"))])
101+
```
102+
111103
## Function Parameters
112104

113105
The `config_to_agent` function accepts:
@@ -123,114 +115,10 @@ agent = config_to_agent(
123115
)
124116
```
125117

126-
## Error Handling
127-
128-
### Configuration Validation
129-
130-
The `config_to_agent` function validates configuration against a JSON schema and provides detailed error messages:
131-
132-
```python
133-
from strands.experimental import config_to_agent
134-
135-
# Invalid field
136-
try:
137-
agent = config_to_agent({"model": "test-model", "invalid_field": "value"})
138-
except ValueError as e:
139-
print(f"Error: {e}") # Configuration validation error at root: Additional properties are not allowed ('invalid_field' was unexpected)
140-
141-
# Wrong field type
142-
try:
143-
agent = config_to_agent({"model": "test-model", "tools": "not-a-list"})
144-
except ValueError as e:
145-
print(f"Error: {e}") # Configuration validation error at tools: 'not-a-list' is not of type 'array'
146-
147-
# Invalid tool item
148-
try:
149-
agent = config_to_agent({"model": "test-model", "tools": ["valid-tool", 123]})
150-
except ValueError as e:
151-
print(f"Error: {e}") # Configuration validation error at tools -> 1: 123 is not of type 'string'
152-
```
153-
154-
### Tool Validation Errors
155-
156-
The function validates that tools can be loaded and provides helpful error messages:
157-
158-
```python
159-
# Tool not found
160-
try:
161-
agent = config_to_agent({"model": "test-model", "tools": ["nonexistent_tool"]})
162-
except ValueError as e:
163-
print(f"Error: {e}")
164-
# Tool 'nonexistent_tool' not found. The configured tool is not annotated with @tool,
165-
# and is not a module or file. To properly import this tool, you must annotate it with @tool.
166-
```
167-
168-
### File Not Found
169-
```python
170-
from strands.experimental import config_to_agent
171-
172-
try:
173-
agent = config_to_agent("/nonexistent/config.json")
174-
except FileNotFoundError as e:
175-
print(f"Error: {e}") # Configuration file not found
176-
```
177-
178-
### Invalid JSON
179-
```python
180-
try:
181-
agent = config_to_agent("/path/to/invalid.json")
182-
except json.JSONDecodeError as e:
183-
print(f"Error: {e}") # Invalid JSON format
184-
```
185-
186-
### Invalid Configuration Type
187-
```python
188-
try:
189-
agent = config_to_agent(123) # Invalid type
190-
except ValueError as e:
191-
print(f"Error: {e}") # Config must be a file path string or dictionary
192-
```
193-
194-
### Tool Loading Errors
195-
196-
Tool loading errors are handled by the Agent class according to its standard behavior:
197-
198-
```python
199-
# If tools cannot be loaded, Agent will raise appropriate errors
200-
agent = config_to_agent({
201-
"model": "test-model",
202-
"tools": ["nonexistent_tool"]
203-
})
204-
# This will raise an error from the Agent class during tool loading
205-
```
206-
207118
## Best Practices
208119

209-
1. **Use absolute paths**: Prefer absolute file paths for configuration files
210-
2. **Handle errors gracefully**: Catch FileNotFoundError and JSONDecodeError for robust applications
211-
3. **Override when needed**: Use kwargs to override configuration values dynamically
212-
4. **Leverage Agent defaults**: Only specify configuration values you want to override
213-
5. **Use standard tool formats**: Follow Agent class conventions for tool specifications
214-
215-
## Migration from AgentConfig Class
216-
217-
If you were using the previous `AgentConfig` class, here's how to migrate:
218-
219-
### Before (AgentConfig class)
220-
```python
221-
from strands.experimental.agent_config import AgentConfig
222-
223-
config = AgentConfig("/path/to/config.json")
224-
agent = config.to_agent()
225-
```
226-
227-
### After (config_to_agent function)
228-
```python
229-
from strands.experimental import config_to_agent
230-
231-
agent = config_to_agent("/path/to/config.json")
232-
```
233-
234-
The new interface is simpler and delegates all complexity to the existing Agent class, providing a more consistent experience.
120+
1. **Override when needed**: Use kwargs to override configuration values dynamically
121+
2. **Leverage Agent defaults**: Only specify configuration values you want to override
122+
3. **Use standard tool formats**: Follow Agent class conventions for tool specifications
123+
4. **Handle errors gracefully**: Catch FileNotFoundError and JSONDecodeError for robust applications
235124

236-
This experimental feature provides a foundation for more advanced agent configuration patterns while maintaining full compatibility with the existing Agent API.

0 commit comments

Comments
 (0)