strands.types.tools
¶
Tool-related type definitions for the SDK.
These types are modeled after the Bedrock API.
- Bedrock docs: https://docs.aws.amazon.com/bedrock/latest/APIReference/API_Types_Amazon_Bedrock_Runtime.html
JSONSchema = dict
module-attribute
¶
Type alias for JSON Schema dictionaries.
RunToolHandler = Callable[[ToolUse], AsyncGenerator[dict[str, Any], None]]
module-attribute
¶
Callback that runs a single tool and streams back results.
ToolChoice = ToolChoiceAutoDict | ToolChoiceAnyDict | ToolChoiceToolDict
module-attribute
¶
Configuration for how the model should choose tools.
- "auto": The model decides whether to use tools based on the context
- "any": The model must use at least one tool (any tool)
- "tool": The model must use the specified tool
ToolChoiceAnyDict = dict[Literal['any'], ToolChoiceAny]
module-attribute
¶
ToolChoiceAutoDict = dict[Literal['auto'], ToolChoiceAuto]
module-attribute
¶
ToolChoiceToolDict = dict[Literal['tool'], ToolChoiceTool]
module-attribute
¶
ToolGenerator = AsyncGenerator[Any, None]
module-attribute
¶
Generator of tool events with the last being the tool result.
ToolResultStatus = Literal['success', 'error']
module-attribute
¶
Status of a tool execution result.
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
210 211 212 213 214 215 216 217 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 | |
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
219 220 221 | |
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
287 288 289 290 291 292 293 294 295 296 297 298 | |
mark_dynamic()
¶
Mark this tool as dynamically loaded.
Source code in strands/types/tools.py
283 284 285 | |
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
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
DocumentContent
¶
Bases: TypedDict
A document to include in a message.
Attributes:
| Name | Type | Description |
|---|---|---|
format |
Literal['pdf', 'csv', 'doc', 'docx', 'xls', 'xlsx', 'html', 'txt', 'md']
|
The format of the document (e.g., "pdf", "txt"). |
name |
str
|
The name of the document. |
source |
DocumentSource
|
The source containing the document's binary content. |
Source code in strands/types/media.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
ImageContent
¶
Bases: TypedDict
An image to include in a message.
Attributes:
| Name | Type | Description |
|---|---|---|
format |
ImageFormat
|
The format of the image (e.g., "png", "jpeg"). |
source |
ImageSource
|
The source containing the image's binary content. |
Source code in strands/types/media.py
58 59 60 61 62 63 64 65 66 67 | |
Tool
¶
Bases: TypedDict
A tool that can be provided to a model.
This type wraps a tool specification for inclusion in a model request.
Attributes:
| Name | Type | Description |
|---|---|---|
toolSpec |
ToolSpec
|
The specification of the tool. |
Source code in strands/types/tools.py
41 42 43 44 45 46 47 48 49 50 | |
ToolChoiceAny
¶
Bases: TypedDict
Configuration indicating that the model must request at least one tool.
Source code in strands/types/tools.py
112 113 114 115 | |
ToolChoiceAuto
¶
Bases: TypedDict
Configuration for automatic tool selection.
This represents the configuration for automatic tool selection, where the model decides whether and which tool to use based on the context.
Source code in strands/types/tools.py
102 103 104 105 106 107 108 109 | |
ToolChoiceTool
¶
Bases: TypedDict
Configuration for forcing the use of a specific tool.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the tool that the model must use. |
Source code in strands/types/tools.py
118 119 120 121 122 123 124 125 | |
ToolConfig
¶
Bases: TypedDict
Configuration for tools in a model request.
Attributes:
| Name | Type | Description |
|---|---|---|
tools |
list[Tool]
|
List of tools available to the model. |
toolChoice |
ToolChoice
|
Configuration for how the model should choose tools. |
Source code in strands/types/tools.py
184 185 186 187 188 189 190 191 192 193 | |
ToolContext
dataclass
¶
Bases: _Interruptible
Context object containing framework-provided data for decorated tools.
This object provides access to framework-level information that may be useful for tool implementations.
Attributes:
| Name | Type | Description |
|---|---|---|
tool_use |
ToolUse
|
The complete ToolUse object containing tool invocation details. |
agent |
Any
|
The Agent or BidiAgent instance executing this tool, providing access to conversation history, model configuration, and other agent state. |
invocation_state |
dict[str, Any]
|
Caller-provided kwargs that were passed to the agent when it was invoked (agent(), agent.invoke_async(), etc.). |
Note
This class is intended to be instantiated by the SDK. Direct construction by users is not supported and may break in future versions as new fields are added.
Source code in strands/types/tools.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
ToolFunc
¶
Bases: Protocol
Function signature for Python decorated and module based tools.
Source code in strands/types/tools.py
196 197 198 199 200 201 202 203 204 205 206 207 | |
__call__(*args, **kwargs)
¶
Function signature for Python decorated and module based tools.
Returns:
| Type | Description |
|---|---|
ToolResult | Awaitable[ToolResult]
|
Tool result or awaitable tool result. |
Source code in strands/types/tools.py
201 202 203 204 205 206 207 | |
ToolResult
¶
Bases: TypedDict
Result of a tool execution.
Attributes:
| Name | Type | Description |
|---|---|---|
content |
list[ToolResultContent]
|
List of result content returned by the tool. |
status |
ToolResultStatus
|
The status of the tool execution ("success" or "error"). |
toolUseId |
str
|
The unique identifier of the tool use request that produced this result. |
Source code in strands/types/tools.py
88 89 90 91 92 93 94 95 96 97 98 99 | |
ToolResultContent
¶
Bases: TypedDict
Content returned by a tool execution.
Attributes:
| Name | Type | Description |
|---|---|---|
document |
DocumentContent
|
Document content returned by the tool. |
image |
ImageContent
|
Image content returned by the tool. |
json |
Any
|
JSON-serializable data returned by the tool. |
text |
str
|
Text content returned by the tool. |
Source code in strands/types/tools.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
ToolSpec
¶
Bases: TypedDict
Specification for a tool that can be used by an agent.
Attributes:
| Name | Type | Description |
|---|---|---|
description |
str
|
A human-readable description of what the tool does. |
inputSchema |
JSONSchema
|
JSON Schema defining the expected input parameters. |
name |
str
|
The unique name of the tool. |
outputSchema |
NotRequired[JSONSchema]
|
Optional JSON Schema defining the expected output format. Note: Not all model providers support this field. Providers that don't support it should filter it out before sending to their API. |
Source code in strands/types/tools.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
ToolUse
¶
Bases: TypedDict
A request from the model to use a specific tool with the provided input.
Attributes:
| Name | Type | Description |
|---|---|---|
input |
Any
|
The input parameters for the tool. Can be any JSON-serializable type. |
name |
str
|
The name of the tool to invoke. |
toolUseId |
str
|
A unique identifier for this specific tool use request. |
Source code in strands/types/tools.py
53 54 55 56 57 58 59 60 61 62 63 64 65 | |
_Interruptible
¶
Bases: Protocol
Interface that adds interrupt support to hook events and tools.
Source code in strands/types/interrupt.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
interrupt(name, reason=None, response=None)
¶
Trigger the interrupt with a reason.
reason: User provided reason for the interrupt.
response: Preemptive response from user if available.
Returns:
| Type | Description |
|---|---|
Any
|
The response from a human user when resuming from an interrupt state. |
Raises:
| Type | Description |
|---|---|
InterruptException
|
If human input is required. |
RuntimeError
|
If agent instance attribute not set. |
Source code in strands/types/interrupt.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |