7
7
8
8
from strands .experimental .agent_config import AgentConfig
9
9
from strands .experimental .tool_pool import ToolPool
10
+ from strands .types .tools import AgentTool
10
11
11
12
12
13
class TestAgentConfig :
@@ -18,16 +19,14 @@ def test_agent_config_creation(self):
18
19
assert config .model == "test-model"
19
20
20
21
def test_agent_config_with_tools (self ):
21
- """Test AgentConfig with tools configuration."""
22
+ """Test AgentConfig with basic configuration."""
22
23
23
24
config = AgentConfig ({
24
25
"model" : "test-model" ,
25
- "tools" : ["tool1" , "tool2" ],
26
26
"prompt" : "Test prompt"
27
27
})
28
28
29
29
assert config .model == "test-model"
30
- assert config .tools == ["tool1" , "tool2" ]
31
30
assert config .system_prompt == "Test prompt"
32
31
33
32
def test_agent_config_file_prefix_required (self ):
@@ -68,7 +67,6 @@ def test_to_agent_calls_agent_constructor(self, mock_agent):
68
67
69
68
config = AgentConfig ({
70
69
"model" : "test-model" ,
71
- "tools" : ["tool1" ],
72
70
"prompt" : "Test prompt"
73
71
})
74
72
@@ -112,3 +110,80 @@ def test_to_agent_with_tool_pool_parameter(self, mock_agent):
112
110
mock_agent .assert_called_once ()
113
111
call_args = mock_agent .call_args [1 ]
114
112
assert 'tools' in call_args
113
+
114
+ def test_agent_config_with_tool_pool_constructor (self ):
115
+ """Test AgentConfig with ToolPool parameter in constructor."""
116
+ # Create mock tools
117
+ class MockTool (AgentTool ):
118
+ def __init__ (self , name ):
119
+ self ._name = name
120
+
121
+ @property
122
+ def tool_name (self ):
123
+ return self ._name
124
+
125
+ @property
126
+ def tool_type (self ):
127
+ return "mock"
128
+
129
+ @property
130
+ def tool_spec (self ):
131
+ return {"name" : self ._name , "type" : "mock" }
132
+
133
+ def stream (self , input_data , context ):
134
+ return iter ([])
135
+
136
+ tool1 = MockTool ("calculator" )
137
+ tool2 = MockTool ("web_search" )
138
+
139
+ # Create ToolPool with tools
140
+ pool = ToolPool ([tool1 , tool2 ])
141
+
142
+ # Create config with tool selection
143
+ config = AgentConfig ({
144
+ "model" : "test-model" ,
145
+ "prompt" : "Test prompt" ,
146
+ "tools" : ["calculator" ]
147
+ }, tool_pool = pool )
148
+
149
+ # Should have selected only calculator
150
+ assert config .tool_pool .list_tool_names () == ["calculator" ]
151
+
152
+ def test_agent_config_tool_validation_error (self ):
153
+ """Test that invalid tool names raise validation error."""
154
+ class MockTool (AgentTool ):
155
+ def __init__ (self , name ):
156
+ self ._name = name
157
+
158
+ @property
159
+ def tool_name (self ):
160
+ return self ._name
161
+
162
+ @property
163
+ def tool_type (self ):
164
+ return "mock"
165
+
166
+ @property
167
+ def tool_spec (self ):
168
+ return {"name" : self ._name , "type" : "mock" }
169
+
170
+ def stream (self , input_data , context ):
171
+ return iter ([])
172
+
173
+ tool1 = MockTool ("calculator" )
174
+ pool = ToolPool ([tool1 ])
175
+
176
+ # Should raise error for unknown tool
177
+ with pytest .raises (ValueError , match = "Tool 'unknown_tool' not found in ToolPool" ):
178
+ AgentConfig ({
179
+ "model" : "test-model" ,
180
+ "tools" : ["unknown_tool" ]
181
+ }, tool_pool = pool )
182
+
183
+ def test_agent_config_tools_without_pool_error (self ):
184
+ """Test that specifying tools without ToolPool raises error."""
185
+ with pytest .raises (ValueError , match = "Tool names specified in config but no ToolPool provided" ):
186
+ AgentConfig ({
187
+ "model" : "test-model" ,
188
+ "tools" : ["calculator" ]
189
+ })
0 commit comments