strands.experimental.tools.tool_provider
¶
Tool provider interface.
AgentTool
¶
Bases: ABC
Abstract base class for all SDK tools.
This class defines the interface that all tool implementations must follow. Each tool must provide its name, specification, and implement a stream method that executes the tool's functionality.
Source code in strands/types/tools.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
is_dynamic
property
¶
Whether the tool was dynamically loaded during runtime.
Dynamic tools may have different lifecycle management.
Returns:
| Type | Description |
|---|---|
bool
|
True if loaded dynamically, False otherwise. |
supports_hot_reload
property
¶
Whether the tool supports automatic reloading when modified.
Returns:
| Type | Description |
|---|---|
bool
|
False by default. |
tool_name
abstractmethod
property
¶
The unique name of the tool used for identification and invocation.
tool_spec
abstractmethod
property
¶
Tool specification that describes its functionality and parameters.
tool_type
abstractmethod
property
¶
The type of the tool implementation (e.g., 'python', 'javascript', 'lambda').
Used for categorization and appropriate handling.
__init__()
¶
Initialize the base agent tool with default dynamic state.
Source code in strands/types/tools.py
227 228 229 | |
get_display_properties()
¶
Get properties to display in UI representations of this tool.
Subclasses can extend this to include additional properties.
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Dictionary of property names and their string values. |
Source code in strands/types/tools.py
295 296 297 298 299 300 301 302 303 304 305 306 | |
mark_dynamic()
¶
Mark this tool as dynamically loaded.
Source code in strands/types/tools.py
291 292 293 | |
stream(tool_use, invocation_state, **kwargs)
abstractmethod
¶
Stream tool events and return the final result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_use
|
ToolUse
|
The tool use request containing tool ID and parameters. |
required |
invocation_state
|
dict[str, Any]
|
Caller-provided kwargs that were passed to the agent when it was invoked (agent(), agent.invoke_async(), etc.). |
required |
**kwargs
|
Any
|
Additional keyword arguments for future extensibility. |
{}
|
Yields:
| Type | Description |
|---|---|
ToolGenerator
|
Tool events with the last being the tool result. |
Source code in strands/types/tools.py
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |
ToolProvider
¶
Bases: ABC
Interface for providing tools with lifecycle management.
Provides a way to load a collection of tools and clean them up when done, with lifecycle managed by the agent.
Source code in strands/experimental/tools/tool_provider.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
add_consumer(consumer_id, **kwargs)
abstractmethod
¶
Add a consumer to this tool provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
consumer_id
|
Any
|
Unique identifier for the consumer. |
required |
**kwargs
|
Any
|
Additional arguments for future compatibility. |
{}
|
Source code in strands/experimental/tools/tool_provider.py
29 30 31 32 33 34 35 36 37 | |
load_tools(**kwargs)
abstractmethod
async
¶
Load and return the tools in this provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Additional arguments for future compatibility. |
{}
|
Returns:
| Type | Description |
|---|---|
Sequence[AgentTool]
|
List of tools that are ready to use. |
Source code in strands/experimental/tools/tool_provider.py
17 18 19 20 21 22 23 24 25 26 27 | |
remove_consumer(consumer_id, **kwargs)
abstractmethod
¶
Remove a consumer from this tool provider.
This method must be idempotent - calling it multiple times with the same ID should have no additional effect after the first call.
Provider may clean up resources when no consumers remain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
consumer_id
|
Any
|
Unique identifier for the consumer. |
required |
**kwargs
|
Any
|
Additional arguments for future compatibility. |
{}
|
Source code in strands/experimental/tools/tool_provider.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |