strands.types
¶
SDK type definitions.
strands.types.content
¶
Content-related type definitions for the SDK.
This module defines the types used to represent messages, content blocks, and other content-related structures in 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
Messages = List[Message]
module-attribute
¶
A list of messages representing a conversation.
Role = Literal['user', 'assistant']
module-attribute
¶
Role of a message sender.
- "user": Messages from the user to the assistant
- "assistant": Messages from the assistant to the user
CachePoint
¶
Bases: TypedDict
A cache point configuration for optimizing conversation history.
Attributes:
Name | Type | Description |
---|---|---|
type |
str
|
The type of cache point, typically "default". |
Source code in strands/types/content.py
ContentBlock
¶
Bases: TypedDict
A block of content for a message that you pass to, or receive from, a model.
Attributes:
Name | Type | Description |
---|---|---|
cachePoint |
CachePoint
|
A cache point configuration to optimize conversation history. |
document |
DocumentContent
|
A document to include in the message. |
guardContent |
GuardContent
|
Contains the content to assess with the guardrail. |
image |
ImageContent
|
Image to include in the message. |
reasoningContent |
ReasoningContentBlock
|
Contains content regarding the reasoning that is carried out by the model. |
text |
str
|
Text to include in the message. |
toolResult |
ToolResult
|
The result for a tool request that a model makes. |
toolUse |
ToolUse
|
Information about a tool use request from a model. |
video |
VideoContent
|
Video to include in the message. |
Source code in strands/types/content.py
ContentBlockDelta
¶
Bases: TypedDict
The content block delta event.
Attributes:
Name | Type | Description |
---|---|---|
contentBlockIndex |
int
|
The block index for a content block delta event. |
delta |
DeltaContent
|
The delta for a content block delta event. |
Source code in strands/types/content.py
ContentBlockStart
¶
Bases: TypedDict
Content block start information.
Attributes:
Name | Type | Description |
---|---|---|
toolUse |
Optional[ContentBlockStartToolUse]
|
Information about a tool that the model is requesting to use. |
Source code in strands/types/content.py
ContentBlockStartToolUse
¶
Bases: TypedDict
The start of a tool use block.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The name of the tool that the model is requesting to use. |
toolUseId |
str
|
The ID for the tool request. |
Source code in strands/types/content.py
ContentBlockStop
¶
Bases: TypedDict
A content block stop event.
Attributes:
Name | Type | Description |
---|---|---|
contentBlockIndex |
int
|
The index for a content block. |
Source code in strands/types/content.py
DeltaContent
¶
Bases: TypedDict
A block of content in a streaming response.
Attributes:
Name | Type | Description |
---|---|---|
text |
str
|
The content text. |
toolUse |
Dict[Literal['input'], str]
|
Information about a tool that the model is requesting to use. |
Source code in strands/types/content.py
GuardContent
¶
Bases: TypedDict
Content block to be evaluated by guardrails.
Attributes:
Name | Type | Description |
---|---|---|
text |
GuardContentText
|
Text within content block to be evaluated by the guardrail. |
Source code in strands/types/content.py
GuardContentText
¶
Bases: TypedDict
Text content to be evaluated by guardrails.
Attributes:
Name | Type | Description |
---|---|---|
qualifiers |
List[Literal['grounding_source', 'query', 'guard_content']]
|
The qualifiers describing the text block. |
text |
str
|
The input text details to be evaluated by the guardrail. |
Source code in strands/types/content.py
Message
¶
Bases: TypedDict
A message in a conversation with the agent.
Attributes:
Name | Type | Description |
---|---|---|
content |
List[ContentBlock]
|
The message content. |
role |
Role
|
The role of the message sender. |
Source code in strands/types/content.py
ReasoningContentBlock
¶
Bases: TypedDict
Contains content regarding the reasoning that is carried out by the model.
Attributes:
Name | Type | Description |
---|---|---|
reasoningText |
ReasoningTextBlock
|
The reasoning that the model used to return the output. |
redactedContent |
bytes
|
The content in the reasoning that was encrypted by the model provider for safety reasons. |
Source code in strands/types/content.py
ReasoningTextBlock
¶
Bases: TypedDict
Contains the reasoning that the model used to return the output.
Attributes:
Name | Type | Description |
---|---|---|
signature |
Optional[str]
|
A token that verifies that the reasoning text was generated by the model. |
text |
str
|
The reasoning that the model used to return the output. |
Source code in strands/types/content.py
SystemContentBlock
¶
Bases: TypedDict
Contains configurations for instructions to provide the model for how to handle input.
Attributes:
Name | Type | Description |
---|---|---|
guardContent |
GuardContent
|
A content block to assess with the guardrail. |
text |
str
|
A system prompt for the model. |
Source code in strands/types/content.py
strands.types.event_loop
¶
Event loop-related type definitions for the SDK.
StopReason = Literal['content_filtered', 'end_turn', 'guardrail_intervened', 'max_tokens', 'stop_sequence', 'tool_use']
module-attribute
¶
Reason for the model ending its response generation.
- "content_filtered": Content was filtered due to policy violation
- "end_turn": Normal completion of the response
- "guardrail_intervened": Guardrail system intervened
- "max_tokens": Maximum token limit reached
- "stop_sequence": Stop sequence encountered
- "tool_use": Model requested to use a tool
Metrics
¶
Bases: TypedDict
Performance metrics for model interactions.
Attributes:
Name | Type | Description |
---|---|---|
latencyMs |
int
|
Latency of the model request in milliseconds. |
Source code in strands/types/event_loop.py
Usage
¶
Bases: TypedDict
Token usage information for model interactions.
Attributes:
Name | Type | Description |
---|---|---|
inputTokens |
int
|
Number of tokens sent in the request to the model.. |
outputTokens |
int
|
Number of tokens that the model generated for the request. |
totalTokens |
int
|
Total number of tokens (input + output). |
Source code in strands/types/event_loop.py
strands.types.exceptions
¶
Exception-related type definitions for the SDK.
ContextWindowOverflowException
¶
Bases: Exception
Exception raised when the context window is exceeded.
This exception is raised when the input to a model exceeds the maximum context window size that the model can handle. This typically occurs when the combined length of the conversation history, system prompt, and current message is too large for the model to process.
Source code in strands/types/exceptions.py
EventLoopException
¶
Bases: Exception
Exception raised by the event loop.
Source code in strands/types/exceptions.py
__init__(original_exception, request_state=None)
¶
Initialize exception.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
original_exception
|
Exception
|
The original exception that was raised. |
required |
request_state
|
Any
|
The state of the request at the time of the exception. |
None
|
Source code in strands/types/exceptions.py
MCPClientInitializationError
¶
ModelThrottledException
¶
Bases: Exception
Exception raised when the model is throttled.
This exception is raised when the model is throttled by the service. This typically occurs when the service is throttling the requests from the client.
Source code in strands/types/exceptions.py
__init__(message)
¶
Initialize exception.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message
|
str
|
The message from the service that describes the throttling. |
required |
strands.types.guardrails
¶
Guardrail-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
ContentFilter
¶
Bases: TypedDict
The content filter for a guardrail.
Attributes:
Name | Type | Description |
---|---|---|
action |
Literal['BLOCKED']
|
Action to take when content is detected. |
confidence |
Literal['NONE', 'LOW', 'MEDIUM', 'HIGH']
|
Confidence level of the detection. |
type |
Literal['INSULTS', 'HATE', 'SEXUAL', 'VIOLENCE', 'MISCONDUCT', 'PROMPT_ATTACK']
|
The type of content to filter. |
Source code in strands/types/guardrails.py
ContentPolicy
¶
Bases: TypedDict
An assessment of a content policy for a guardrail.
Attributes:
Name | Type | Description |
---|---|---|
filters |
List[ContentFilter]
|
List of content filters to apply. |
Source code in strands/types/guardrails.py
ContextualGroundingFilter
¶
Bases: TypedDict
Filter for ensuring responses are grounded in provided context.
Attributes:
Name | Type | Description |
---|---|---|
action |
Literal['BLOCKED', 'NONE']
|
Action to take when the threshold is not met. |
score |
float
|
The score generated by contextual grounding filter (range [0, 1]). |
threshold |
float
|
Threshold used by contextual grounding filter to determine whether the content is grounded or not. |
type |
Literal['GROUNDING', 'RELEVANCE']
|
The contextual grounding filter type. |
Source code in strands/types/guardrails.py
ContextualGroundingPolicy
¶
Bases: TypedDict
The policy assessment details for the guardrails contextual grounding filter.
Attributes:
Name | Type | Description |
---|---|---|
filters |
List[ContextualGroundingFilter]
|
The filter details for the guardrails contextual grounding filter. |
Source code in strands/types/guardrails.py
CustomWord
¶
Bases: TypedDict
Definition of a custom word to be filtered.
Attributes:
Name | Type | Description |
---|---|---|
action |
Literal['BLOCKED']
|
Action to take when the word is detected. |
match |
str
|
The word or phrase to match. |
Source code in strands/types/guardrails.py
GuardrailAssessment
¶
Bases: TypedDict
A behavior assessment of the guardrail policies used in a call to the Converse API.
Attributes:
Name | Type | Description |
---|---|---|
contentPolicy |
ContentPolicy
|
The content policy. |
contextualGroundingPolicy |
ContextualGroundingPolicy
|
The contextual grounding policy used for the guardrail assessment. |
sensitiveInformationPolicy |
SensitiveInformationPolicy
|
The sensitive information policy. |
topicPolicy |
TopicPolicy
|
The topic policy. |
wordPolicy |
WordPolicy
|
The word policy. |
Source code in strands/types/guardrails.py
GuardrailConfig
¶
Bases: TypedDict
Configuration for content filtering guardrails.
Attributes:
Name | Type | Description |
---|---|---|
guardrailIdentifier |
str
|
Unique identifier for the guardrail. |
guardrailVersion |
str
|
Version of the guardrail to apply. |
streamProcessingMode |
Optional[Literal['sync', 'async']]
|
Processing mode. |
trace |
Literal['enabled', 'disabled']
|
The trace behavior for the guardrail. |
Source code in strands/types/guardrails.py
GuardrailTrace
¶
Bases: TypedDict
Trace information from guardrail processing.
Attributes:
Name | Type | Description |
---|---|---|
inputAssessment |
Dict[str, GuardrailAssessment]
|
Assessment of input content against guardrail policies, keyed by input identifier. |
modelOutput |
List[str]
|
The original output from the model before guardrail processing. |
outputAssessments |
Dict[str, List[GuardrailAssessment]]
|
Assessments of output content against guardrail policies, keyed by output identifier. |
Source code in strands/types/guardrails.py
ManagedWord
¶
Bases: TypedDict
Definition of a managed word to be filtered.
Attributes:
Name | Type | Description |
---|---|---|
action |
Literal['BLOCKED']
|
Action to take when the word is detected. |
match |
str
|
The word or phrase to match. |
type |
Literal['PROFANITY']
|
Type of the word. |
Source code in strands/types/guardrails.py
PIIEntity
¶
Bases: TypedDict
Definition of a Personally Identifiable Information (PII) entity to be filtered.
Attributes:
Name | Type | Description |
---|---|---|
action |
Literal['ANONYMIZED', 'BLOCKED']
|
Action to take when PII is detected. |
match |
str
|
The specific PII instance to match. |
type |
Literal['ADDRESS', 'AGE', 'AWS_ACCESS_KEY', 'AWS_SECRET_KEY', 'CA_HEALTH_NUMBER', 'CA_SOCIAL_INSURANCE_NUMBER', 'CREDIT_DEBIT_CARD_CVV', 'CREDIT_DEBIT_CARD_EXPIRY', 'CREDIT_DEBIT_CARD_NUMBER', 'DRIVER_ID', 'EMAIL', 'INTERNATIONAL_BANK_ACCOUNT_NUMBER', 'IP_ADDRESS', 'LICENSE_PLATE', 'MAC_ADDRESS', 'NAME', 'PASSWORD', 'PHONE', 'PIN', 'SWIFT_CODE', 'UK_NATIONAL_HEALTH_SERVICE_NUMBER', 'UK_NATIONAL_INSURANCE_NUMBER', 'UK_UNIQUE_TAXPAYER_REFERENCE_NUMBER', 'URL', 'USERNAME', 'US_BANK_ACCOUNT_NUMBER', 'US_BANK_ROUTING_NUMBER', 'US_INDIVIDUAL_TAX_IDENTIFICATION_NUMBER', 'US_PASSPORT_NUMBER', 'US_SOCIAL_SECURITY_NUMBER', 'VEHICLE_IDENTIFICATION_NUMBER']
|
The type of PII to detect. |
Source code in strands/types/guardrails.py
Regex
¶
Bases: TypedDict
Definition of a custom regex pattern for filtering sensitive information.
Attributes:
Name | Type | Description |
---|---|---|
action |
Literal['ANONYMIZED', 'BLOCKED']
|
Action to take when the pattern is matched. |
match |
str
|
The regex filter match. |
name |
str
|
Name of the regex pattern for identification. |
regex |
str
|
The regex query. |
Source code in strands/types/guardrails.py
SensitiveInformationPolicy
¶
Bases: TypedDict
Policy defining sensitive information filtering rules.
Attributes:
Name | Type | Description |
---|---|---|
piiEntities |
List[PIIEntity]
|
List of Personally Identifiable Information (PII) entities to detect and handle. |
regexes |
List[Regex]
|
The regex queries in the assessment. |
Source code in strands/types/guardrails.py
Topic
¶
Bases: TypedDict
Information about a topic guardrail.
Attributes:
Name | Type | Description |
---|---|---|
action |
Literal['BLOCKED']
|
The action the guardrail should take when it intervenes on a topic. |
name |
str
|
The name for the guardrail. |
type |
Literal['DENY']
|
The type behavior that the guardrail should perform when the model detects the topic. |
Source code in strands/types/guardrails.py
TopicPolicy
¶
Bases: TypedDict
A behavior assessment of a topic policy.
Attributes:
Name | Type | Description |
---|---|---|
topics |
List[Topic]
|
The topics in the assessment. |
Source code in strands/types/guardrails.py
Trace
¶
Bases: TypedDict
A Top level guardrail trace object.
Attributes:
Name | Type | Description |
---|---|---|
guardrail |
GuardrailTrace
|
Trace information from guardrail processing. |
Source code in strands/types/guardrails.py
WordPolicy
¶
Bases: TypedDict
The word policy assessment.
Attributes:
Name | Type | Description |
---|---|---|
customWords |
List[CustomWord]
|
List of custom words to filter. |
managedWordLists |
List[ManagedWord]
|
List of managed word lists to filter. |
Source code in strands/types/guardrails.py
strands.types.media
¶
Media-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
DocumentFormat = Literal['pdf', 'csv', 'doc', 'docx', 'xls', 'xlsx', 'html', 'txt', 'md']
module-attribute
¶
Supported document formats.
ImageFormat = Literal['png', 'jpeg', 'gif', 'webp']
module-attribute
¶
Supported image formats.
VideoFormat = Literal['flv', 'mkv', 'mov', 'mpeg', 'mpg', 'mp4', 'three_gp', 'webm', 'wmv']
module-attribute
¶
Supported video formats.
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
DocumentSource
¶
Bases: TypedDict
Contains the content of a document.
Attributes:
Name | Type | Description |
---|---|---|
bytes |
bytes
|
The binary content of the document. |
Source code in strands/types/media.py
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
ImageSource
¶
Bases: TypedDict
Contains the content of an image.
Attributes:
Name | Type | Description |
---|---|---|
bytes |
bytes
|
The binary content of the image. |
Source code in strands/types/media.py
VideoContent
¶
Bases: TypedDict
A video to include in a message.
Attributes:
Name | Type | Description |
---|---|---|
format |
VideoFormat
|
The format of the video (e.g., "mp4", "avi"). |
source |
VideoSource
|
The source containing the video's binary content. |
Source code in strands/types/media.py
VideoSource
¶
Bases: TypedDict
Contains the content of a video.
Attributes:
Name | Type | Description |
---|---|---|
bytes |
bytes
|
The binary content of the video. |
Source code in strands/types/media.py
strands.types.session
¶
Data models for session management.
Session
dataclass
¶
Session data model.
Source code in strands/types/session.py
from_dict(env)
classmethod
¶
Initialize a Session from a dictionary, ignoring keys that are not calss parameters.
SessionAgent
dataclass
¶
Agent that belongs to a Session.
Source code in strands/types/session.py
from_agent(agent)
classmethod
¶
Convert an Agent to a SessionAgent.
Source code in strands/types/session.py
from_dict(env)
classmethod
¶
Initialize a SessionAgent from a dictionary, ignoring keys that are not calss parameters.
Source code in strands/types/session.py
SessionMessage
dataclass
¶
Message within a SessionAgent.
Attributes:
Name | Type | Description |
---|---|---|
message |
Message
|
Message content |
message_id |
int
|
Index of the message in the conversation history |
redact_message |
Optional[Message]
|
If the original message is redacted, this is the new content to use |
created_at |
str
|
ISO format timestamp for when this message was created |
updated_at |
str
|
ISO format timestamp for when this message was last updated |
Source code in strands/types/session.py
from_dict(env)
classmethod
¶
Initialize a SessionMessage from a dictionary, ignoring keys that are not class parameters.
Source code in strands/types/session.py
from_message(message, index)
classmethod
¶
Convert from a Message, base64 encoding bytes values.
Source code in strands/types/session.py
to_dict()
¶
to_message()
¶
Convert SessionMessage back to a Message, decoding any bytes values.
If the message was redacted, return the redact content instead.
Source code in strands/types/session.py
SessionType
¶
Bases: str
, Enum
Enumeration of session types.
As sessions are expanded to support new usecases like multi-agent patterns, new types will be added here.
Source code in strands/types/session.py
decode_bytes_values(obj)
¶
Recursively decode any base64-encoded bytes values in an object.
Handles dictionaries, lists, and nested structures.
Source code in strands/types/session.py
encode_bytes_values(obj)
¶
Recursively encode any bytes values in an object to base64.
Handles dictionaries, lists, and nested structures.
Source code in strands/types/session.py
strands.types.streaming
¶
Streaming-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
ContentBlockDelta
¶
Bases: TypedDict
A block of content in a streaming response.
Attributes:
Name | Type | Description |
---|---|---|
reasoningContent |
ReasoningContentBlockDelta
|
Contains content regarding the reasoning that is carried out by the model. |
text |
str
|
Text fragment being streamed. |
toolUse |
ContentBlockDeltaToolUse
|
Tool use input fragment being streamed. |
Source code in strands/types/streaming.py
ContentBlockDeltaEvent
¶
Bases: TypedDict
Event containing a delta update for a content block in a streaming response.
Attributes:
Name | Type | Description |
---|---|---|
contentBlockIndex |
Optional[int]
|
Index of the content block within the message. This is optional to accommodate different model providers. |
delta |
ContentBlockDelta
|
The incremental content update for the content block. |
Source code in strands/types/streaming.py
ContentBlockDeltaText
¶
Bases: TypedDict
Text content delta in a streaming response.
Attributes:
Name | Type | Description |
---|---|---|
text |
str
|
The text fragment being streamed. |
Source code in strands/types/streaming.py
ContentBlockDeltaToolUse
¶
Bases: TypedDict
Tool use input delta in a streaming response.
Attributes:
Name | Type | Description |
---|---|---|
input |
str
|
The tool input fragment being streamed. |
Source code in strands/types/streaming.py
ContentBlockStartEvent
¶
Bases: TypedDict
Event signaling the start of a content block in a streaming response.
Attributes:
Name | Type | Description |
---|---|---|
contentBlockIndex |
Optional[int]
|
Index of the content block within the message. This is optional to accommodate different model providers. |
start |
ContentBlockStart
|
Information about the content block being started. |
Source code in strands/types/streaming.py
ContentBlockStopEvent
¶
Bases: TypedDict
Event signaling the end of a content block in a streaming response.
Attributes:
Name | Type | Description |
---|---|---|
contentBlockIndex |
Optional[int]
|
Index of the content block within the message. This is optional to accommodate different model providers. |
Source code in strands/types/streaming.py
ExceptionEvent
¶
Bases: TypedDict
Base event for exceptions in a streaming response.
Attributes:
Name | Type | Description |
---|---|---|
message |
str
|
The error message describing what went wrong. |
Source code in strands/types/streaming.py
MessageStartEvent
¶
Bases: TypedDict
Event signaling the start of a message in a streaming response.
Attributes:
Name | Type | Description |
---|---|---|
role |
Role
|
The role of the message sender (e.g., "assistant", "user"). |
Source code in strands/types/streaming.py
MessageStopEvent
¶
Bases: TypedDict
Event signaling the end of a message in a streaming response.
Attributes:
Name | Type | Description |
---|---|---|
additionalModelResponseFields |
Optional[Union[dict, list, int, float, str, bool, None]]
|
Additional fields to include in model response. |
stopReason |
StopReason
|
The reason why the model stopped generating content. |
Source code in strands/types/streaming.py
MetadataEvent
¶
Bases: TypedDict
Event containing metadata about the streaming response.
Attributes:
Name | Type | Description |
---|---|---|
metrics |
Metrics
|
Performance metrics related to the model invocation. |
trace |
Optional[Trace]
|
Trace information for debugging and monitoring. |
usage |
Usage
|
Resource usage information for the model invocation. |
Source code in strands/types/streaming.py
ModelStreamErrorEvent
¶
Bases: ExceptionEvent
Event for model streaming errors.
Attributes:
Name | Type | Description |
---|---|---|
originalMessage |
str
|
The original error message from the model provider. |
originalStatusCode |
int
|
The HTTP status code returned by the model provider. |
Source code in strands/types/streaming.py
ReasoningContentBlockDelta
¶
Bases: TypedDict
Delta for reasoning content block in a streaming response.
Attributes:
Name | Type | Description |
---|---|---|
redactedContent |
Optional[bytes]
|
The content in the reasoning that was encrypted by the model provider for safety reasons. |
signature |
Optional[str]
|
A token that verifies that the reasoning text was generated by the model. |
text |
Optional[str]
|
The reasoning that the model used to return the output. |
Source code in strands/types/streaming.py
RedactContentEvent
¶
Bases: TypedDict
Event for redacting content.
Attributes:
Name | Type | Description |
---|---|---|
redactUserContentMessage |
Optional[str]
|
The string to overwrite the users input with. |
redactAssistantContentMessage |
Optional[str]
|
The string to overwrite the assistants output with. |
Source code in strands/types/streaming.py
StreamEvent
¶
Bases: TypedDict
The messages output stream.
Attributes:
Name | Type | Description |
---|---|---|
contentBlockDelta |
ContentBlockDeltaEvent
|
Delta content for a content block. |
contentBlockStart |
ContentBlockStartEvent
|
Start of a content block. |
contentBlockStop |
ContentBlockStopEvent
|
End of a content block. |
internalServerException |
ExceptionEvent
|
Internal server error information. |
messageStart |
MessageStartEvent
|
Start of a message. |
messageStop |
MessageStopEvent
|
End of a message. |
metadata |
MetadataEvent
|
Metadata about the streaming response. |
modelStreamErrorException |
ModelStreamErrorEvent
|
Model streaming error information. |
serviceUnavailableException |
ExceptionEvent
|
Service unavailable error information. |
throttlingException |
ExceptionEvent
|
Throttling error information. |
validationException |
ExceptionEvent
|
Validation error information. |
Source code in strands/types/streaming.py
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 = Union[dict[Literal['auto'], ToolChoiceAuto], dict[Literal['any'], ToolChoiceAny], dict[Literal['tool'], ToolChoiceTool]]
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
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
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 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 |
|
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__()
¶
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
mark_dynamic()
¶
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]
|
Context for the tool invocation, including agent state. |
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
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
ToolChoiceAny
¶
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.
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
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
ToolFunc
¶
Bases: Protocol
Function signature for Python decorated and module based tools.
Source code in strands/types/tools.py
__call__(*args, **kwargs)
¶
Function signature for Python decorated and module based tools.
Returns:
Type | Description |
---|---|
Union[ToolResult, Awaitable[ToolResult]]
|
Tool result or awaitable tool result. |
Source code in strands/types/tools.py
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
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
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. |
Source code in strands/types/tools.py
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
strands.types.traces
¶
Tracing type definitions for the SDK.