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
ContentBlock
¶
Bases: TypedDict
A block of content for a message that you pass to, or receive from, a model.
Attributes:
Name | Type | Description |
---|---|---|
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
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
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
133 134 135 136 137 138 139 140 141 142 |
|
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
123 124 125 126 127 128 129 130 |
|
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
111 112 113 114 115 116 117 118 119 120 |
|
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
145 146 147 148 149 150 151 152 |
|
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
99 100 101 102 103 104 105 106 107 108 |
|
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
29 30 31 32 33 34 35 36 |
|
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
17 18 19 20 21 22 23 24 25 26 |
|
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
163 164 165 166 167 168 169 170 171 172 |
|
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
51 52 53 54 55 56 57 58 59 60 |
|
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
39 40 41 42 43 44 45 46 47 48 |
|
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
87 88 89 90 91 92 93 94 95 96 |
|
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
Future
¶
Bases: Protocol
Interface representing the result of an asynchronous computation.
Source code in strands/types/event_loop.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
result(timeout=None)
¶
Return the result of the call that the future represents.
This method will block until the asynchronous operation completes or until the specified timeout is reached.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout
|
Optional[int]
|
The number of seconds to wait for the result. If None, then there is no limit on the wait time. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The result of the asynchronous operation. |
Source code in strands/types/event_loop.py
55 56 57 58 59 60 61 62 63 64 65 66 |
|
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
22 23 24 25 26 27 28 29 |
|
ParallelToolExecutorInterface
¶
Bases: Protocol
Interface for parallel tool execution.
Attributes:
Name | Type | Description |
---|---|---|
timeout |
int
|
Default timeout in seconds for futures. |
Source code in strands/types/event_loop.py
69 70 71 72 73 74 75 76 77 78 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 |
|
as_completed(futures, timeout=timeout)
¶
Iterate over the given futures, yielding each as it completes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
futures
|
Iterable[Future]
|
The sequence of Futures to iterate over. |
required |
timeout
|
Optional[int]
|
The maximum number of seconds to wait. If None, then there is no limit on the wait time. |
timeout
|
Returns:
Type | Description |
---|---|
Iterator[Future]
|
An iterator that yields the given Futures as they complete (finished or cancelled). |
Source code in strands/types/event_loop.py
94 95 96 97 98 99 100 101 102 103 104 |
|
shutdown(wait=True)
¶
Shutdown the executor and free associated resources.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
wait
|
bool
|
If True, shutdown will not return until all running futures have finished executing. |
True
|
Source code in strands/types/event_loop.py
106 107 108 109 110 111 |
|
submit(fn, /, *args, **kwargs)
¶
Submit a callable to be executed with the given arguments.
Schedules the callable to be executed as fn(args, *kwargs) and returns a Future instance representing the execution of the callable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fn
|
Callable[..., Any]
|
The callable to execute. |
required |
*args
|
Any
|
Positional arguments to pass to the callable. |
()
|
**kwargs
|
Any
|
Keyword arguments to pass to the callable. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Future |
Future
|
A Future representing the given call. |
Source code in strands/types/event_loop.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
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
8 9 10 11 12 13 14 15 16 17 18 19 |
|
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
21 22 23 24 25 26 27 28 29 |
|
EventLoopException
¶
Bases: Exception
Exception raised by the event loop.
Source code in strands/types/exceptions.py
6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
__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
9 10 11 12 13 14 15 16 17 18 |
|
MCPClientInitializationError
¶
Bases: Exception
Raised when the MCP server fails to initialize properly.
Source code in strands/types/exceptions.py
32 33 34 35 |
|
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
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
__init__(message)
¶
Initialize exception.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message
|
str
|
The message from the service that describes the throttling. |
required |
Source code in strands/types/exceptions.py
45 46 47 48 49 50 51 52 |
|
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
53 54 55 56 57 58 59 60 61 62 63 64 |
|
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
67 68 69 70 71 72 73 74 |
|
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
189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
|
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
205 206 207 208 209 210 211 212 |
|
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
77 78 79 80 81 82 83 84 85 86 |
|
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. |
topicPolic |
SensitiveInformationPolicy
|
The topic policy. |
wordPolicy |
WordPolicy
|
The word policy. |
Source code in strands/types/guardrails.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
|
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']]
|
Procesing mode. |
trace |
Literal['enabled', 'disabled']
|
The trace behavior for the guardrail. |
Source code in strands/types/guardrails.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
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
233 234 235 236 237 238 239 240 241 242 243 244 |
|
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
89 90 91 92 93 94 95 96 97 98 99 100 |
|
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
115 116 117 118 119 120 121 122 123 124 125 126 127 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 |
|
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
161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|
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
177 178 179 180 181 182 183 184 185 186 |
|
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
29 30 31 32 33 34 35 36 37 38 39 40 |
|
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
43 44 45 46 47 48 49 50 |
|
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
247 248 249 250 251 252 253 254 |
|
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
103 104 105 106 107 108 109 110 111 112 |
|
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
26 27 28 29 30 31 32 33 34 35 36 37 |
|
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
16 17 18 19 20 21 22 23 |
|
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
54 55 56 57 58 59 60 61 62 63 |
|
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
44 45 46 47 48 49 50 51 |
|
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
80 81 82 83 84 85 86 87 88 89 |
|
VideoSource
¶
Bases: TypedDict
Contains the content of a vidoe.
Attributes:
Name | Type | Description |
---|---|---|
bytes |
bytes
|
The binary content of the video. |
Source code in strands/types/media.py
70 71 72 73 74 75 76 77 |
|
strands.types.models
¶
Model-related type definitions for the SDK.
Model
¶
Bases: ABC
Abstract base class for AI model implementations.
This class defines the interface for all model implementations in the Strands Agents SDK. It provides a standardized way to configure, format, and process requests for different AI model providers.
Source code in strands/types/models.py
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 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 |
|
converse(messages, tool_specs=None, system_prompt=None)
¶
Converse with the model.
This method handles the full lifecycle of conversing with the model: 1. Format the messages, tool specs, and configuration into a streaming request 2. Send the request to the model 3. Yield the formatted message chunks
Parameters:
Name | Type | Description | Default |
---|---|---|---|
messages
|
Messages
|
List of message objects to be processed by the model. |
required |
tool_specs
|
Optional[list[ToolSpec]]
|
List of tool specifications to make available to the model. |
None
|
system_prompt
|
Optional[str]
|
System prompt to provide context to the model. |
None
|
Yields:
Type | Description |
---|---|
Iterable[StreamEvent]
|
Formatted message chunks from the model. |
Raises:
Type | Description |
---|---|
ModelThrottledException
|
When the model service is throttling requests from the client. |
Source code in strands/types/models.py
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 |
|
format_chunk(event)
abstractmethod
¶
Format the model response events into standardized message chunks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event
|
Any
|
A response event from the model. |
required |
Returns:
Type | Description |
---|---|
StreamEvent
|
The formatted chunk. |
Source code in strands/types/models.py
58 59 60 61 62 63 64 65 66 67 68 69 |
|
format_request(messages, tool_specs=None, system_prompt=None)
abstractmethod
¶
Format a streaming request to the underlying model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
messages
|
Messages
|
List of message objects to be processed by the model. |
required |
tool_specs
|
Optional[list[ToolSpec]]
|
List of tool specifications to make available to the model. |
None
|
system_prompt
|
Optional[str]
|
System prompt to provide context to the model. |
None
|
Returns:
Type | Description |
---|---|
Any
|
The formatted request. |
Source code in strands/types/models.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
get_config()
abstractmethod
¶
Return the model configuration.
Returns:
Type | Description |
---|---|
Any
|
The model's configuration. |
Source code in strands/types/models.py
31 32 33 34 35 36 37 38 39 |
|
stream(request)
abstractmethod
¶
Send the request to the model and get a streaming response.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request
|
Any
|
The formatted request to send to the model. |
required |
Returns:
Type | Description |
---|---|
Iterable[Any]
|
The model's response. |
Raises:
Type | Description |
---|---|
ModelThrottledException
|
When the model service is throttling requests from the client. |
Source code in strands/types/models.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
update_config(**model_config)
abstractmethod
¶
Update the model configuration with the provided arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**model_config
|
Any
|
Configuration overrides. |
{}
|
Source code in strands/types/models.py
21 22 23 24 25 26 27 28 29 |
|
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
74 75 76 77 78 79 80 81 82 83 84 85 |
|
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
88 89 90 91 92 93 94 95 96 97 98 |
|
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
40 41 42 43 44 45 46 47 |
|
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
50 51 52 53 54 55 56 57 |
|
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
27 28 29 30 31 32 33 34 35 36 37 |
|
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
101 102 103 104 105 106 107 108 109 |
|
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
138 139 140 141 142 143 144 145 |
|
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
17 18 19 20 21 22 23 24 |
|
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
112 113 114 115 116 117 118 119 120 121 |
|
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
124 125 126 127 128 129 130 131 132 133 134 135 |
|
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
148 149 150 151 152 153 154 155 156 157 |
|
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
60 61 62 63 64 65 66 67 68 69 70 71 |
|
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
160 161 162 163 164 165 166 167 168 169 170 |
|
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
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 |
|
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.
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
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 an invoke method that executes the tool's functionality.
Source code in strands/types/tools.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 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 |
|
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
159 160 161 |
|
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
226 227 228 229 230 231 232 233 234 235 236 237 |
|
invoke(tool, *args, **kwargs)
abstractmethod
¶
Execute the tool's functionality with the given tool use request.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tool
|
ToolUse
|
The tool use request containing tool ID and parameters. |
required |
*args
|
Any
|
Positional arguments to pass to the tool. |
()
|
**kwargs
|
dict[str, Any]
|
Keyword arguments to pass to the tool. |
{}
|
Returns:
Type | Description |
---|---|
ToolResult
|
The result of the tool execution. |
Source code in strands/types/tools.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
|
mark_dynamic()
¶
Mark this tool as dynamically loaded.
Source code in strands/types/tools.py
222 223 224 |
|
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
37 38 39 40 41 42 43 44 45 46 |
|
ToolChoiceAny
¶
Bases: TypedDict
Configuration indicating that the model must request at least one tool.
Source code in strands/types/tools.py
108 109 110 111 |
|
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
98 99 100 101 102 103 104 105 |
|
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
114 115 116 117 118 119 120 121 |
|
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
138 139 140 141 142 143 144 145 146 147 |
|
ToolHandler
¶
Bases: ABC
Abstract base class for handling tool execution within the agent framework.
Source code in strands/types/tools.py
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 |
|
preprocess(tool, tool_config, **kwargs)
abstractmethod
¶
Preprocess a tool use request before execution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tool
|
ToolUse
|
The tool use request to preprocess. |
required |
tool_config
|
ToolConfig
|
The tool configuration for the current session. |
required |
**kwargs
|
Any
|
Additional context-specific arguments. |
{}
|
Returns:
Type | Description |
---|---|
Optional[ToolResult]
|
A preprocessed tool result object. |
Source code in strands/types/tools.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
|
process(tool, *, messages, model, system_prompt, tool_config, callback_handler, **kwargs)
abstractmethod
¶
Process a tool use request and execute the tool.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tool
|
ToolUse
|
The tool use request to process. |
required |
messages
|
Messages
|
The current conversation history. |
required |
model
|
Model
|
The model being used for the conversation. |
required |
system_prompt
|
Optional[str]
|
The system prompt for the conversation. |
required |
tool_config
|
ToolConfig
|
The tool configuration for the current session. |
required |
callback_handler
|
Any
|
Callback for processing events as they happen. |
required |
**kwargs
|
Any
|
Additional context-specific arguments. |
{}
|
Returns:
Type | Description |
---|---|
ToolResult
|
The result of the tool execution. |
Source code in strands/types/tools.py
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 |
|
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
84 85 86 87 88 89 90 91 92 93 94 95 |
|
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
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
|
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
23 24 25 26 27 28 29 30 31 32 33 34 |
|
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
49 50 51 52 53 54 55 56 57 58 59 60 61 |
|