|
5 | 5 |
|
6 | 6 | import pytest
|
7 | 7 |
|
| 8 | +from strands import tool |
8 | 9 | from strands.experimental.agent_config import AgentConfig
|
9 | 10 | from strands.tools.registry import ToolRegistry
|
10 | 11 | from strands.types.tools import AgentTool
|
@@ -191,3 +192,38 @@ def test_agent_config_missing_tool_validation_with_flag_true(self):
|
191 | 192 | tool_registry=custom_tool_registry,
|
192 | 193 | raise_exception_on_missing_tool=True,
|
193 | 194 | )
|
| 195 | + |
| 196 | + @patch("strands.experimental.agent_config.AgentConfig._create_default_tool_registry") |
| 197 | + def test_agent_config_tools_without_tool_registry_error(self, mock_create_registry): |
| 198 | + """Test that config can load tools from default ToolRegistry when strands_tools is available.""" |
| 199 | + # Mock the default tool registry to return a registry with file_read tool |
| 200 | + mock_registry = ToolRegistry() |
| 201 | + |
| 202 | + @tool |
| 203 | + def file_read(path: str) -> str: |
| 204 | + return f"content of {path}" |
| 205 | + |
| 206 | + mock_registry.process_tools([file_read]) |
| 207 | + mock_create_registry.return_value = mock_registry |
| 208 | + |
| 209 | + config = AgentConfig({"model": "test-model", "tools": ["file_read"]}) |
| 210 | + assert len(config.configured_tools) == 1 |
| 211 | + assert config.configured_tools[0].tool_name == "file_read" |
| 212 | + |
| 213 | + @patch("strands.experimental.agent_config.AgentConfig._create_default_tool_registry") |
| 214 | + def test_agent_config_loads_from_default_tools_without_tool_registry(self, mock_create_registry): |
| 215 | + """Test that config can load tools from default strands_tools without explicit tool registry.""" |
| 216 | + # Mock the default tool registry to return a registry with file_read tool |
| 217 | + mock_registry = ToolRegistry() |
| 218 | + |
| 219 | + @tool |
| 220 | + def file_read(path: str) -> str: |
| 221 | + return f"content of {path}" |
| 222 | + |
| 223 | + mock_registry.process_tools([file_read]) |
| 224 | + mock_create_registry.return_value = mock_registry |
| 225 | + |
| 226 | + config = AgentConfig({"model": "test-model", "tools": ["file_read"]}) |
| 227 | + # Verify the tool was loaded from the default tool registry |
| 228 | + assert len(config.configured_tools) == 1 |
| 229 | + assert config.configured_tools[0].tool_name == "file_read" |
0 commit comments