strands.experimental.bidi.io.text
¶
Handle text input and output to and from bidi agent.
BidiOutputEvent = BidiConnectionStartEvent | BidiConnectionRestartEvent | BidiResponseStartEvent | BidiAudioStreamEvent | BidiTranscriptStreamEvent | BidiInterruptionEvent | BidiResponseCompleteEvent | BidiUsageEvent | BidiConnectionCloseEvent | BidiErrorEvent | ToolUseStreamEvent
module-attribute
¶
Union of different bidi output event types.
logger = logging.getLogger(__name__)
module-attribute
¶
BidiConnectionCloseEvent
¶
Bases: TypedEvent
Streaming connection closed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection_id
|
str
|
Unique identifier for this streaming connection (matches BidiConnectionStartEvent). |
required |
reason
|
Literal['client_disconnect', 'timeout', 'error', 'complete', 'user_request']
|
Why the connection was closed. |
required |
Source code in strands/experimental/bidi/types/events.py
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 | |
connection_id
property
¶
Unique identifier for this streaming connection.
reason
property
¶
Why the interruption occurred.
__init__(connection_id, reason)
¶
Initialize connection close event.
Source code in strands/experimental/bidi/types/events.py
510 511 512 513 514 515 516 517 518 519 520 521 522 | |
BidiInput
¶
Bases: Protocol
Protocol for bidirectional input callables.
Input callables read data from a source (microphone, camera, websocket, etc.) and return events to be sent to the agent.
Source code in strands/experimental/bidi/types/io.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
__call__()
¶
Read input data from the source.
Returns:
| Type | Description |
|---|---|
Awaitable[BidiInputEvent]
|
Awaitable that resolves to an input event (audio, text, image, etc.) |
Source code in strands/experimental/bidi/types/io.py
32 33 34 35 36 37 38 | |
start(agent)
async
¶
Start input.
Source code in strands/experimental/bidi/types/io.py
24 25 26 | |
stop()
async
¶
Stop input.
Source code in strands/experimental/bidi/types/io.py
28 29 30 | |
BidiInterruptionEvent
¶
Bases: TypedEvent
Model generation was interrupted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reason
|
Literal['user_speech', 'error']
|
Why the interruption occurred. |
required |
Source code in strands/experimental/bidi/types/events.py
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
reason
property
¶
Why the interruption occurred.
__init__(reason)
¶
Initialize interruption event.
Source code in strands/experimental/bidi/types/events.py
370 371 372 373 374 375 376 377 | |
BidiOutput
¶
Bases: Protocol
Protocol for bidirectional output callables.
Output callables receive events from the agent and handle them appropriately (play audio, display text, send over websocket, etc.).
Source code in strands/experimental/bidi/types/io.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
__call__(event)
¶
Process output events from the agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
BidiOutputEvent
|
Output event from the agent (audio, text, tool calls, etc.) |
required |
Source code in strands/experimental/bidi/types/io.py
57 58 59 60 61 62 63 | |
start(agent)
async
¶
Start output.
Source code in strands/experimental/bidi/types/io.py
49 50 51 | |
stop()
async
¶
Stop output.
Source code in strands/experimental/bidi/types/io.py
53 54 55 | |
BidiTextIO
¶
Handle text input and output to and from bidi agent.
Accepts input from stdin and outputs to stdout.
Source code in strands/experimental/bidi/io/text.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
__init__(**config)
¶
Initialize I/O.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**config
|
Any
|
Optional I/O configurations.
|
{}
|
Source code in strands/experimental/bidi/io/text.py
71 72 73 74 75 76 77 78 79 | |
input()
¶
Return text processing BidiInput.
Source code in strands/experimental/bidi/io/text.py
81 82 83 | |
output()
¶
Return text processing BidiOutput.
Source code in strands/experimental/bidi/io/text.py
85 86 87 | |
BidiTextInputEvent
¶
Bases: TypedEvent
Text input event for sending text to the model.
Used for sending text content through the send() method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text content to send to the model. |
required |
role
|
Role
|
The role of the message sender (default: "user"). |
'user'
|
Source code in strands/experimental/bidi/types/events.py
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 | |
role
property
¶
The role of the message sender.
text
property
¶
The text content to send to the model.
__init__(text, role='user')
¶
Initialize text input event.
Source code in strands/experimental/bidi/types/events.py
74 75 76 77 78 79 80 81 82 | |
BidiTranscriptStreamEvent
¶
Bases: ModelStreamEvent
Audio transcription streaming (user or assistant speech).
Supports incremental transcript updates for providers that send partial transcripts before the final version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
delta
|
ContentBlockDelta
|
The incremental transcript change (ContentBlockDelta). |
required |
text
|
str
|
The delta text (same as delta content for convenience). |
required |
role
|
Role
|
Who is speaking ("user" or "assistant"). |
required |
is_final
|
bool
|
Whether this is the final/complete transcript. |
required |
current_transcript
|
str | None
|
The accumulated transcript text so far (None for first delta). |
None
|
Source code in strands/experimental/bidi/types/events.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | |
current_transcript
property
¶
The accumulated transcript text so far.
delta
property
¶
The incremental transcript change.
is_final
property
¶
Whether this is the final/complete transcript.
role
property
¶
The role of the message sender.
text
property
¶
The text content to send to the model.
__init__(delta, text, role, is_final, current_transcript=None)
¶
Initialize transcript stream event.
Source code in strands/experimental/bidi/types/events.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | |
_BidiTextInput
¶
Bases: BidiInput
Handle text input from user.
Source code in strands/experimental/bidi/io/text.py
20 21 22 23 24 25 26 27 28 29 30 31 | |
__call__()
async
¶
Read user input from stdin.
Source code in strands/experimental/bidi/io/text.py
28 29 30 31 | |
__init__(config)
¶
Extract configs and setup prompt session.
Source code in strands/experimental/bidi/io/text.py
23 24 25 26 | |
_BidiTextOutput
¶
Bases: BidiOutput
Handle text output from bidi agent.
Source code in strands/experimental/bidi/io/text.py
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 | |
__call__(event)
async
¶
Print text events to stdout.
Source code in strands/experimental/bidi/io/text.py
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 | |