State
State management for TAF agent graphs.
This package provides schemas and context managers for agent state, execution tracking, and message context management. All core state classes are exported for use in agent workflows and custom state extensions.
Modules:
| Name | Description |
|---|---|
agent_state |
Agent state schema for TAF agent graphs. |
base_context |
Abstract base class for context management in TAF agent graphs. |
execution_state |
Execution state management for graph execution in TAF. |
message |
Message and content block primitives for agent graphs. |
message_block |
|
message_context_manager |
Message context management for agent state in TAF. |
reducers |
Reducer utilities for merging and replacing lists and values in agent state. |
stream_chunks |
Stream chunk primitives for unified streaming data handling. |
Classes:
| Name | Description |
|---|---|
AgentState |
Common state schema that includes messages, context and internal execution metadata. |
AnnotationBlock |
Annotation content block for messages. |
AnnotationRef |
Reference to annotation metadata (e.g., citation, note). |
AudioBlock |
Audio content block for messages. |
BaseContextManager |
Abstract base class for context management in AI interactions. |
DataBlock |
Data content block for messages. |
DocumentBlock |
Document content block for messages. |
ErrorBlock |
Error content block for messages. |
ExecutionState |
Tracks the internal execution state of a graph. |
ExecutionStatus |
Status of graph execution. |
ImageBlock |
Image content block for messages. |
MediaRef |
Reference to media content (image/audio/video/document/data). |
Message |
Represents a message in a conversation, including content, role, metadata, and token usage. |
MessageContextManager |
Manages the context field for AI interactions. |
ReasoningBlock |
Reasoning content block for messages. |
StreamChunk |
Unified wrapper for different types of streaming data. |
StreamEvent |
|
TextBlock |
Text content block for messages. |
TokenUsages |
Tracks token usage statistics for a message or model response. |
ToolCallBlock |
Tool call content block for messages. |
ToolResultBlock |
Tool result content block for messages. |
VideoBlock |
Video content block for messages. |
Functions:
| Name | Description |
|---|---|
add_messages |
Adds messages to the list, avoiding duplicates by message_id. |
append_items |
Appends items to a list, avoiding duplicates by item.id. |
remove_tool_messages |
Remove COMPLETED tool interaction sequences from the message list. |
replace_messages |
Replaces the entire message list with a new one. |
replace_value |
Replaces a value with another. |
Attributes:
| Name | Type | Description |
|---|---|---|
ContentBlock |
|
Attributes¶
ContentBlock
module-attribute
¶
ContentBlock = Annotated[Union[TextBlock, ImageBlock, AudioBlock, VideoBlock, DocumentBlock, DataBlock, ToolCallBlock, RemoteToolCallBlock, ToolResultBlock, ReasoningBlock, AnnotationBlock, ErrorBlock], Field(discriminator='type')]
__all__
module-attribute
¶
__all__ = ['AgentState', 'AnnotationBlock', 'AnnotationRef', 'AudioBlock', 'BaseContextManager', 'ContentBlock', 'DataBlock', 'DocumentBlock', 'ErrorBlock', 'ExecutionState', 'ExecutionStatus', 'ImageBlock', 'MediaRef', 'Message', 'MessageContextManager', 'ReasoningBlock', 'StreamChunk', 'StreamEvent', 'TextBlock', 'TextBlock', 'TokenUsages', 'ToolCallBlock', 'ToolResultBlock', 'VideoBlock', 'add_messages', 'append_items', 'remove_tool_messages', 'replace_messages', 'replace_value']
Classes¶
AgentState
¶
Bases: BaseModel
Common state schema that includes messages, context and internal execution metadata.
This class can be subclassed to add application-specific fields while maintaining compatibility with the TAF framework. All internal execution metadata is preserved through subclassing.
Notes:
- execution_meta contains internal-only execution progress and interrupt info.
- Users may subclass AgentState to add application fields; internal exec meta remains
available to the runtime and will be persisted with the state.
- When subclassing, add your fields but keep the core fields intact.
Example
class MyCustomState(AgentState): user_data: dict = Field(default_factory=dict) custom_field: str = "default"
Methods:
| Name | Description |
|---|---|
advance_step |
Advance the execution step in the metadata. |
clear_interrupt |
Clear any interrupt in the execution metadata. |
complete |
Mark the agent state as completed. |
error |
Mark the agent state as errored. |
is_interrupted |
Check if the agent state is currently interrupted. |
is_running |
Check if the agent state is currently running. |
is_stopped_requested |
Check if a stop has been requested for the agent state. |
set_current_node |
Set the current node in the execution metadata. |
set_interrupt |
Set an interrupt in the execution metadata. |
Attributes:
| Name | Type | Description |
|---|---|---|
context |
Annotated[list[Message], add_messages]
|
|
context_summary |
str | None
|
|
execution_meta |
ExecutionState
|
|
Source code in agentflow/state/agent_state.py
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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
Attributes¶
execution_meta
class-attribute
instance-attribute
¶
execution_meta = Field(default_factory=lambda: ExecutionState(current_node=START))
Functions¶
advance_step
¶
advance_step()
Advance the execution step in the metadata.
Source code in agentflow/state/agent_state.py
93 94 95 96 97 98 99 | |
clear_interrupt
¶
clear_interrupt()
Clear any interrupt in the execution metadata.
Source code in agentflow/state/agent_state.py
64 65 66 67 68 69 | |
complete
¶
complete()
Mark the agent state as completed.
Source code in agentflow/state/agent_state.py
112 113 114 115 116 117 | |
error
¶
error(error_msg)
Mark the agent state as errored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Error message to record. |
required |
Source code in agentflow/state/agent_state.py
119 120 121 122 123 124 125 126 127 | |
is_interrupted
¶
is_interrupted()
Check if the agent state is currently interrupted.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if interrupted, False otherwise. |
Source code in agentflow/state/agent_state.py
82 83 84 85 86 87 88 89 90 91 | |
is_running
¶
is_running()
Check if the agent state is currently running.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if running, False otherwise. |
Source code in agentflow/state/agent_state.py
71 72 73 74 75 76 77 78 79 80 | |
is_stopped_requested
¶
is_stopped_requested()
Check if a stop has been requested for the agent state.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if stop requested, False otherwise. |
Source code in agentflow/state/agent_state.py
129 130 131 132 133 134 135 136 137 138 | |
set_current_node
¶
set_current_node(node)
Set the current node in the execution metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Node to set as current. |
required |
Source code in agentflow/state/agent_state.py
101 102 103 104 105 106 107 108 109 110 | |
set_interrupt
¶
set_interrupt(node, reason, status, data=None)
Set an interrupt in the execution metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Node where the interrupt occurred. |
required |
|
str
|
Reason for the interrupt. |
required |
|
Execution status to set. |
required | |
|
dict | None
|
Optional additional interrupt data. |
None
|
Source code in agentflow/state/agent_state.py
51 52 53 54 55 56 57 58 59 60 61 62 | |
AnnotationBlock
¶
Bases: BaseModel
Annotation content block for messages.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Literal['annotation']
|
Block type discriminator. |
kind |
Literal['citation', 'note']
|
Kind of annotation. |
refs |
list[AnnotationRef]
|
List of annotation references. |
spans |
list[tuple[int, int]] | None
|
Spans covered by the annotation. |
Source code in agentflow/state/message_block.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
AnnotationRef
¶
Bases: BaseModel
Reference to annotation metadata (e.g., citation, note).
Attributes:
| Name | Type | Description |
|---|---|---|
url |
str | None
|
URL to annotation source. |
file_id |
str | None
|
Provider-managed file ID. |
page |
int | None
|
Page number (if applicable). |
index |
int | None
|
Index within the annotation source. |
title |
str | None
|
Title of the annotation. |
Source code in agentflow/state/message_block.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
AudioBlock
¶
Bases: BaseModel
Audio content block for messages.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Literal['audio']
|
Block type discriminator. |
media |
MediaRef
|
Reference to audio media. |
transcript |
str | None
|
Transcript of audio. |
sample_rate |
int | None
|
Sample rate in Hz. |
channels |
int | None
|
Number of audio channels. |
Source code in agentflow/state/message_block.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
BaseContextManager
¶
Bases: ABC
Abstract base class for context management in AI interactions.
Subclasses should implement trim_context as either a synchronous or asynchronous method.
Generic over AgentState or its subclasses.
Methods:
| Name | Description |
|---|---|
atrim_context |
Trim context based on message count asynchronously. |
trim_context |
Trim context based on message count. Can be sync or async. |
Source code in agentflow/state/base_context.py
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 | |
Functions¶
atrim_context
abstractmethod
async
¶
atrim_context(state)
Trim context based on message count asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
S
|
The state containing context to be trimmed. |
required |
Returns:
| Type | Description |
|---|---|
S
|
The state with trimmed context. |
Source code in agentflow/state/base_context.py
43 44 45 46 47 48 49 50 51 52 53 54 | |
trim_context
abstractmethod
¶
trim_context(state)
Trim context based on message count. Can be sync or async.
Subclasses may implement as either a synchronous or asynchronous method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
S
|
The state containing context to be trimmed. |
required |
Returns:
| Type | Description |
|---|---|
S
|
The state with trimmed context, either directly or as an awaitable. |
Source code in agentflow/state/base_context.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
DataBlock
¶
Bases: BaseModel
Data content block for messages.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Literal['data']
|
Block type discriminator. |
mime_type |
str
|
MIME type of the data. |
data_base64 |
str | None
|
Base64-encoded data. |
media |
MediaRef | None
|
Reference to associated media. |
Source code in agentflow/state/message_block.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
DocumentBlock
¶
Bases: BaseModel
Document content block for messages.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Literal['document']
|
Block type discriminator. |
media |
MediaRef
|
Reference to document media. |
pages |
list[int] | None
|
List of page numbers. |
excerpt |
str | None
|
Excerpt from the document. |
Source code in agentflow/state/message_block.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
ErrorBlock
¶
Bases: BaseModel
Error content block for messages.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Literal['error']
|
Block type discriminator. |
message |
str
|
Error message. |
code |
str | None
|
Error code. |
data |
dict[str, Any] | None
|
Additional error data. |
Source code in agentflow/state/message_block.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | |
ExecutionState
¶
Bases: BaseModel
Tracks the internal execution state of a graph.
This class manages the execution progress, interrupt status, and internal data that should not be exposed to users.
Methods:
| Name | Description |
|---|---|
advance_step |
Advance to the next execution step. |
clear_interrupt |
Clear the interrupt state and resume execution. |
complete |
Mark execution as completed. |
error |
Mark execution as errored. |
from_dict |
Create an ExecutionState instance from a dictionary. |
is_interrupted |
Check if execution is currently interrupted. |
is_running |
Check if execution is currently running. |
is_stopped_requested |
Check if a stop has been requested for execution. |
set_current_node |
Update the current node in execution state. |
set_interrupt |
Set the interrupt state for execution. |
Attributes:
| Name | Type | Description |
|---|---|---|
current_node |
str
|
|
internal_data |
dict[str, Any]
|
|
interrupt_data |
dict[str, Any] | None
|
|
interrupt_reason |
str | None
|
|
interrupted_node |
str | None
|
|
status |
ExecutionStatus
|
|
step |
int
|
|
stop_current_execution |
StopRequestStatus
|
|
thread_id |
str | None
|
|
Source code in agentflow/state/execution_state.py
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 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 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 | |
Attributes¶
Functions¶
advance_step
¶
advance_step()
Advance to the next execution step.
Source code in agentflow/state/execution_state.py
134 135 136 137 138 139 140 | |
clear_interrupt
¶
clear_interrupt()
Clear the interrupt state and resume execution.
Source code in agentflow/state/execution_state.py
110 111 112 113 114 115 116 117 118 | |
complete
¶
complete()
Mark execution as completed.
Source code in agentflow/state/execution_state.py
153 154 155 156 157 158 | |
error
¶
error(error_msg)
Mark execution as errored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Error message to record. |
required |
Source code in agentflow/state/execution_state.py
160 161 162 163 164 165 166 167 168 169 | |
from_dict
classmethod
¶
from_dict(data)
Create an ExecutionState instance from a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict[str, Any]
|
Dictionary containing execution state fields. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ExecutionState |
ExecutionState
|
The deserialized execution state object. |
Source code in agentflow/state/execution_state.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
is_interrupted
¶
is_interrupted()
Check if execution is currently interrupted.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if interrupted, False otherwise. |
Source code in agentflow/state/execution_state.py
120 121 122 123 124 125 126 127 128 129 130 131 132 | |
is_running
¶
is_running()
Check if execution is currently running.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if running, False otherwise. |
Source code in agentflow/state/execution_state.py
171 172 173 174 175 176 177 178 179 180 | |
is_stopped_requested
¶
is_stopped_requested()
Check if a stop has been requested for execution.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if stop requested, False otherwise. |
Source code in agentflow/state/execution_state.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
set_current_node
¶
set_current_node(node)
Update the current node in execution state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Node to set as current. |
required |
Source code in agentflow/state/execution_state.py
142 143 144 145 146 147 148 149 150 151 | |
set_interrupt
¶
set_interrupt(node, reason, status, data=None)
Set the interrupt state for execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Node where the interrupt occurred. |
required |
|
str
|
Reason for the interrupt. |
required |
|
ExecutionStatus
|
Status to set for the interrupt. |
required |
|
dict[str, Any] | None
|
Optional additional interrupt data. |
None
|
Source code in agentflow/state/execution_state.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
ExecutionStatus
¶
Bases: Enum
Status of graph execution.
Attributes:
| Name | Type | Description |
|---|---|---|
COMPLETED |
|
|
ERROR |
|
|
INTERRUPTED_AFTER |
|
|
INTERRUPTED_BEFORE |
|
|
RUNNING |
|
Source code in agentflow/state/execution_state.py
18 19 20 21 22 23 24 25 | |
Attributes¶
ImageBlock
¶
Bases: BaseModel
Image content block for messages.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Literal['image']
|
Block type discriminator. |
media |
MediaRef
|
Reference to image media. |
alt_text |
str | None
|
Alternative text for accessibility. |
bbox |
list[float] | None
|
Bounding box coordinates [x1, y1, x2, y2]. |
Source code in agentflow/state/message_block.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
MediaRef
¶
Bases: BaseModel
Reference to media content (image/audio/video/document/data).
Prefer referencing by URL or provider file_id over inlining base64 for large payloads.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
Literal['url', 'file_id', 'data']
|
Type of reference. |
url |
str | None
|
URL to media content. |
file_id |
str | None
|
Provider-managed file ID. |
data_base64 |
str | None
|
Base64-encoded data (small payloads only). |
mime_type |
str | None
|
MIME type of the media. |
size_bytes |
int | None
|
Size in bytes. |
sha256 |
str | None
|
SHA256 hash of the media. |
filename |
str | None
|
Filename of the media. |
width |
int | None
|
Image width (if applicable). |
height |
int | None
|
Image height (if applicable). |
duration_ms |
int | None
|
Duration in milliseconds (if applicable). |
page |
int | None
|
Page number (if applicable). |
Source code in agentflow/state/message_block.py
6 7 8 9 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 | |
Attributes¶
Message
¶
Bases: BaseModel
Represents a message in a conversation, including content, role, metadata, and token usage.
Attributes:
| Name | Type | Description |
|---|---|---|
message_id |
str | int
|
Unique identifier for the message. |
role |
Literal['user', 'assistant', 'system', 'tool']
|
The role of the message sender. |
content |
list[ContentBlock]
|
The message content blocks. |
delta |
bool
|
Indicates if this is a delta/partial message. |
tools_calls |
list[dict[str, Any]] | None
|
Tool call information, if any. |
reasoning |
str | None
|
Reasoning or explanation, if any. |
timestamp |
datetime | None
|
Timestamp of the message. |
metadata |
dict[str, Any]
|
Additional metadata. |
usages |
TokenUsages | None
|
Token usage statistics. |
raw |
dict[str, Any] | None
|
Raw data, if any. |
Example
msg = Message(message_id="abc123", role="user", content=[TextBlock(text="Hello!")])
Methods:
| Name | Description |
|---|---|
attach_media |
Append a media block to the content. |
text |
Best-effort text extraction from content blocks. |
text_message |
Create a Message instance from plain text. |
tool_message |
Create a tool message, optionally marking it as an error. |
Source code in agentflow/state/message.py
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 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 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 | |
Attributes¶
message_id
class-attribute
instance-attribute
¶
message_id = Field(default_factory=lambda: generate_id(None))
timestamp
class-attribute
instance-attribute
¶
timestamp = Field(default_factory=lambda: timestamp())
Functions¶
attach_media
¶
attach_media(media, as_type)
Append a media block to the content.
If content was text, creates a block list. Supports image, audio, video, and document types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
MediaRef
|
Reference to media content. |
required |
|
Literal['image', 'audio', 'video', 'document']
|
Type of media block to append. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an unsupported media type is provided. |
Example
msg.attach_media(media_ref, as_type="image")
Source code in agentflow/state/message.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 | |
text
¶
text()
Best-effort text extraction from content blocks.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Concatenated text from TextBlock and ToolResultBlock outputs. |
Example
msg.text() 'Hello!Result text.'
Source code in agentflow/state/message.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | |
text_message
classmethod
¶
text_message(content, role='user', message_id=None)
Create a Message instance from plain text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The message content. |
required |
|
Literal['user', 'assistant', 'system', 'tool']
|
The role of the sender. |
'user'
|
|
str | None
|
Optional message ID. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Message |
Message
|
The created Message instance. |
Example
Message.text_message("Hello!", role="user")
Source code in agentflow/state/message.py
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 | |
tool_message
classmethod
¶
tool_message(content, message_id=None, meta=None)
Create a tool message, optionally marking it as an error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[ContentBlock]
|
The message content blocks. |
required |
|
str | None
|
Optional message ID. |
None
|
|
dict[str, Any] | None
|
Optional metadata. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Message |
Message
|
The created tool message instance. |
Example
Message.tool_message([ToolResultBlock(...)], message_id="tool1")
Source code in agentflow/state/message.py
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 | |
MessageContextManager
¶
Bases: BaseContextManager[S]
Manages the context field for AI interactions.
This class trims the context (message history) based on a maximum number of user messages, ensuring the first message (usually a system prompt) is always preserved. Optionally removes tool-related messages (AI messages with tool calls and tool result messages). Generic over AgentState or its subclasses.
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the MessageContextManager. |
atrim_context |
Asynchronous version of trim_context. |
trim_context |
Trim the context in the given AgentState based on the maximum number of user messages. |
Attributes:
| Name | Type | Description |
|---|---|---|
max_messages |
|
|
remove_tool_msgs |
|
Source code in agentflow/state/message_context_manager.py
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 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 | |
Attributes¶
Functions¶
__init__
¶
__init__(max_messages=10, remove_tool_msgs=False)
Initialize the MessageContextManager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int
|
Maximum number of user messages to keep in context. Default is 10. |
10
|
|
bool
|
Whether to remove tool messages from context. Default is False. |
False
|
Source code in agentflow/state/message_context_manager.py
33 34 35 36 37 38 39 40 41 42 43 44 45 | |
atrim_context
async
¶
atrim_context(state)
Asynchronous version of trim_context.
If remove_tool_msgs is True, also removes:
- AI messages that contain tool calls (intermediate tool-calling messages)
- Tool result messages (role="tool")
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
AgentState
|
The agent state containing the context to trim. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
S |
S
|
The updated agent state with trimmed context. |
Source code in agentflow/state/message_context_manager.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
trim_context
¶
trim_context(state)
Trim the context in the given AgentState based on the maximum number of user messages.
The first message (typically a system prompt) is always preserved. Only the most recent
user messages up to max_messages are kept, along with the first message.
If remove_tool_msgs is True, also removes:
- AI messages that contain tool calls (intermediate tool-calling messages)
- Tool result messages (role="tool")
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
AgentState
|
The agent state containing the context to trim. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
S |
S
|
The updated agent state with trimmed context. |
Source code in agentflow/state/message_context_manager.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
ReasoningBlock
¶
Bases: BaseModel
Reasoning content block for messages.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Literal['reasoning']
|
Block type discriminator. |
summary |
str
|
Summary of reasoning. |
details |
list[str] | None
|
Detailed reasoning steps. |
Source code in agentflow/state/message_block.py
218 219 220 221 222 223 224 225 226 227 228 229 230 | |
StreamChunk
¶
Bases: BaseModel
Unified wrapper for different types of streaming data.
This class provides a single interface for handling various streaming chunk types (messages, events, state updates, errors) with type-safe discrimination.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
The type of streaming chunk. |
|
data |
dict | None
|
The actual chunk data (Message, EventModel, dict, etc.). |
metadata |
dict | None
|
Optional additional metadata for the chunk. |
Classes:
| Name | Description |
|---|---|
Config |
Pydantic configuration for EventModel. |
Source code in agentflow/state/stream_chunks.py
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 | |
Attributes¶
timestamp
class-attribute
instance-attribute
¶
timestamp = Field(default_factory=timestamp, description='UNIX timestamp of when chunk was created')
Classes¶
Config
¶
Pydantic configuration for EventModel.
Attributes:
| Name | Type | Description |
|---|---|---|
use_enum_values |
Output enums as strings. |
Source code in agentflow/state/stream_chunks.py
59 60 61 62 63 64 65 66 | |
StreamEvent
¶
TextBlock
¶
Bases: BaseModel
Text content block for messages.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Literal['text']
|
Block type discriminator. |
text |
str
|
Text content. |
annotations |
list[AnnotationRef]
|
List of annotation references. |
Source code in agentflow/state/message_block.py
61 62 63 64 65 66 67 68 69 70 71 72 73 | |
TokenUsages
¶
Bases: BaseModel
Tracks token usage statistics for a message or model response.
Attributes:
| Name | Type | Description |
|---|---|---|
completion_tokens |
int
|
Number of completion tokens used. |
prompt_tokens |
int
|
Number of prompt tokens used. |
total_tokens |
int
|
Total tokens used. |
reasoning_tokens |
int
|
Reasoning tokens used (optional). |
cache_creation_input_tokens |
int
|
Cache creation input tokens (optional). |
cache_read_input_tokens |
int
|
Cache read input tokens (optional). |
image_tokens |
int | None
|
Image tokens for multimodal models (optional). |
audio_tokens |
int | None
|
Audio tokens for multimodal models (optional). |
Example
usage = TokenUsages(completion_tokens=10, prompt_tokens=20, total_tokens=30)
Source code in agentflow/state/message.py
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 124 125 126 | |
Attributes¶
ToolCallBlock
¶
Bases: BaseModel
Tool call content block for messages.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Literal['tool_call']
|
Block type discriminator. |
id |
str
|
Tool call ID. |
name |
str
|
Tool name. |
args |
dict[str, Any]
|
Arguments for the tool call. |
tool_type |
str | None
|
Type of tool (e.g., web_search, file_search). |
Source code in agentflow/state/message_block.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
ToolResultBlock
¶
Bases: BaseModel
Tool result content block for messages.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Literal['tool_result']
|
Block type discriminator. |
call_id |
str
|
Tool call ID. |
output |
Any
|
Output from the tool (str, dict, MediaRef, or list of blocks). |
is_error |
bool
|
Whether the result is an error. |
status |
Literal['completed', 'failed'] | None
|
Status of the tool call. |
Source code in agentflow/state/message_block.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
VideoBlock
¶
Bases: BaseModel
Video content block for messages.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Literal['video']
|
Block type discriminator. |
media |
MediaRef
|
Reference to video media. |
thumbnail |
MediaRef | None
|
Reference to thumbnail image. |
Source code in agentflow/state/message_block.py
112 113 114 115 116 117 118 119 120 121 122 123 124 | |
Functions¶
add_messages
¶
add_messages(left, right)
Adds messages to the list, avoiding duplicates by message_id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[Message]
|
Existing list of messages. |
required |
|
list[Message]
|
New messages to add. |
required |
Returns:
| Type | Description |
|---|---|
list[Message]
|
list[Message]: Combined list with unique messages. |
Example
add_messages([msg1], [msg2, msg1]) [msg1, msg2]
Source code in agentflow/state/reducers.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
append_items
¶
append_items(left, right)
Appends items to a list, avoiding duplicates by item.id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list
|
Existing list of items (must have .id attribute). |
required |
|
list
|
New items to add. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
Combined list with unique items. |
Example
append_items([item1], [item2, item1]) [item1, item2]
Source code in agentflow/state/reducers.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
remove_tool_messages
¶
remove_tool_messages(messages)
Remove COMPLETED tool interaction sequences from the message list.
A tool sequence is only removed if it's COMPLETE: 1. AI message with tool_calls (triggering tools) 2. One or more tool result messages (role="tool") 3. AI message WITHOUT tool_calls (final response using tool results)
If a sequence is incomplete (e.g., tool call made but no final AI response yet), ALL messages are kept to maintain conversation continuity.
Edge cases handled: - Incomplete sequences (AI called tool, waiting for results): Keep everything - Partial sequences (AI called tool, got results, but no final response): Keep everything - Multiple tool calls in one AI message: Handles correctly - Consecutive tool sequences: Each evaluated independently
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[Message]
|
List of messages to filter. |
required |
Returns:
| Type | Description |
|---|---|
list[Message]
|
list[Message]: Filtered list with only COMPLETED tool sequences removed. |
Example
Complete sequence (will be cleaned):
messages = [user_msg, ai_with_tools, tool_result, ai_final] remove_tool_messages(messages) [user_msg, ai_final]
Incomplete sequence (will be kept):
messages = [user_msg, ai_with_tools] remove_tool_messages(messages) [user_msg, ai_with_tools] # Keep everything - sequence incomplete!
Partial sequence (will be kept):
messages = [user_msg, ai_with_tools, tool_result] remove_tool_messages(messages) [user_msg, ai_with_tools, tool_result] # Keep - no final AI response!
Source code in agentflow/state/reducers.py
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 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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
replace_messages
¶
replace_messages(left, right)
Replaces the entire message list with a new one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[Message]
|
Existing list of messages (ignored). |
required |
|
list[Message]
|
New list of messages. |
required |
Returns:
| Type | Description |
|---|---|
list[Message]
|
list[Message]: The new message list. |
Example
replace_messages([msg1], [msg2]) [msg2]
Source code in agentflow/state/reducers.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
replace_value
¶
replace_value(left, right)
Replaces a value with another.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Existing value (ignored). |
required | |
|
New value to use. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
The new value. |
Example
replace_value(1, 2) 2
Source code in agentflow/state/reducers.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
Modules¶
agent_state
¶
Agent state schema for TAF agent graphs.
This module provides the AgentState class, which tracks message context, context summaries, and internal execution metadata for agent workflows. Supports subclassing for custom application fields.
Classes:
| Name | Description |
|---|---|
AgentState |
Common state schema that includes messages, context and internal execution metadata. |
Attributes:
| Name | Type | Description |
|---|---|---|
logger |
|
Attributes¶
Classes¶
AgentState
¶
Bases: BaseModel
Common state schema that includes messages, context and internal execution metadata.
This class can be subclassed to add application-specific fields while maintaining compatibility with the TAF framework. All internal execution metadata is preserved through subclassing.
Notes:
- execution_meta contains internal-only execution progress and interrupt info.
- Users may subclass AgentState to add application fields; internal exec meta remains
available to the runtime and will be persisted with the state.
- When subclassing, add your fields but keep the core fields intact.
Example
class MyCustomState(AgentState): user_data: dict = Field(default_factory=dict) custom_field: str = "default"
Methods:
| Name | Description |
|---|---|
advance_step |
Advance the execution step in the metadata. |
clear_interrupt |
Clear any interrupt in the execution metadata. |
complete |
Mark the agent state as completed. |
error |
Mark the agent state as errored. |
is_interrupted |
Check if the agent state is currently interrupted. |
is_running |
Check if the agent state is currently running. |
is_stopped_requested |
Check if a stop has been requested for the agent state. |
set_current_node |
Set the current node in the execution metadata. |
set_interrupt |
Set an interrupt in the execution metadata. |
Attributes:
| Name | Type | Description |
|---|---|---|
context |
Annotated[list[Message], add_messages]
|
|
context_summary |
str | None
|
|
execution_meta |
ExecutionState
|
|
Source code in agentflow/state/agent_state.py
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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
Attributes¶
execution_meta
class-attribute
instance-attribute
¶execution_meta = Field(default_factory=lambda: ExecutionState(current_node=START))
Functions¶
advance_step
¶advance_step()
Advance the execution step in the metadata.
Source code in agentflow/state/agent_state.py
93 94 95 96 97 98 99 | |
clear_interrupt
¶clear_interrupt()
Clear any interrupt in the execution metadata.
Source code in agentflow/state/agent_state.py
64 65 66 67 68 69 | |
complete
¶complete()
Mark the agent state as completed.
Source code in agentflow/state/agent_state.py
112 113 114 115 116 117 | |
error
¶error(error_msg)
Mark the agent state as errored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error_msg
¶ |
str
|
Error message to record. |
required |
Source code in agentflow/state/agent_state.py
119 120 121 122 123 124 125 126 127 | |
is_interrupted
¶is_interrupted()
Check if the agent state is currently interrupted.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if interrupted, False otherwise. |
Source code in agentflow/state/agent_state.py
82 83 84 85 86 87 88 89 90 91 | |
is_running
¶is_running()
Check if the agent state is currently running.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if running, False otherwise. |
Source code in agentflow/state/agent_state.py
71 72 73 74 75 76 77 78 79 80 | |
is_stopped_requested
¶is_stopped_requested()
Check if a stop has been requested for the agent state.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if stop requested, False otherwise. |
Source code in agentflow/state/agent_state.py
129 130 131 132 133 134 135 136 137 138 | |
set_current_node
¶set_current_node(node)
Set the current node in the execution metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
¶ |
str
|
Node to set as current. |
required |
Source code in agentflow/state/agent_state.py
101 102 103 104 105 106 107 108 109 110 | |
set_interrupt
¶set_interrupt(node, reason, status, data=None)
Set an interrupt in the execution metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
¶ |
str
|
Node where the interrupt occurred. |
required |
reason
¶ |
str
|
Reason for the interrupt. |
required |
status
¶ |
Execution status to set. |
required | |
data
¶ |
dict | None
|
Optional additional interrupt data. |
None
|
Source code in agentflow/state/agent_state.py
51 52 53 54 55 56 57 58 59 60 61 62 | |
Functions¶
base_context
¶
Abstract base class for context management in TAF agent graphs.
This module provides BaseContextManager, which defines the interface for trimming and managing message context in agent state objects.
Classes:
| Name | Description |
|---|---|
BaseContextManager |
Abstract base class for context management in AI interactions. |
Attributes:
| Name | Type | Description |
|---|---|---|
S |
|
|
logger |
|
Attributes¶
Classes¶
BaseContextManager
¶
Bases: ABC
Abstract base class for context management in AI interactions.
Subclasses should implement trim_context as either a synchronous or asynchronous method.
Generic over AgentState or its subclasses.
Methods:
| Name | Description |
|---|---|
atrim_context |
Trim context based on message count asynchronously. |
trim_context |
Trim context based on message count. Can be sync or async. |
Source code in agentflow/state/base_context.py
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 | |
Functions¶
atrim_context
abstractmethod
async
¶atrim_context(state)
Trim context based on message count asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
¶ |
S
|
The state containing context to be trimmed. |
required |
Returns:
| Type | Description |
|---|---|
S
|
The state with trimmed context. |
Source code in agentflow/state/base_context.py
43 44 45 46 47 48 49 50 51 52 53 54 | |
trim_context
abstractmethod
¶trim_context(state)
Trim context based on message count. Can be sync or async.
Subclasses may implement as either a synchronous or asynchronous method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
¶ |
S
|
The state containing context to be trimmed. |
required |
Returns:
| Type | Description |
|---|---|
S
|
The state with trimmed context, either directly or as an awaitable. |
Source code in agentflow/state/base_context.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
execution_state
¶
Execution state management for graph execution in TAF.
This module provides the ExecutionState class and related enums to track progress, interruptions, and pause/resume functionality for agent graph execution.
Classes:
| Name | Description |
|---|---|
ExecutionState |
Tracks the internal execution state of a graph. |
ExecutionStatus |
Status of graph execution. |
StopRequestStatus |
Status of graph execution. |
Attributes:
| Name | Type | Description |
|---|---|---|
logger |
|
Attributes¶
Classes¶
ExecutionState
¶
Bases: BaseModel
Tracks the internal execution state of a graph.
This class manages the execution progress, interrupt status, and internal data that should not be exposed to users.
Methods:
| Name | Description |
|---|---|
advance_step |
Advance to the next execution step. |
clear_interrupt |
Clear the interrupt state and resume execution. |
complete |
Mark execution as completed. |
error |
Mark execution as errored. |
from_dict |
Create an ExecutionState instance from a dictionary. |
is_interrupted |
Check if execution is currently interrupted. |
is_running |
Check if execution is currently running. |
is_stopped_requested |
Check if a stop has been requested for execution. |
set_current_node |
Update the current node in execution state. |
set_interrupt |
Set the interrupt state for execution. |
Attributes:
| Name | Type | Description |
|---|---|---|
current_node |
str
|
|
internal_data |
dict[str, Any]
|
|
interrupt_data |
dict[str, Any] | None
|
|
interrupt_reason |
str | None
|
|
interrupted_node |
str | None
|
|
status |
ExecutionStatus
|
|
step |
int
|
|
stop_current_execution |
StopRequestStatus
|
|
thread_id |
str | None
|
|
Source code in agentflow/state/execution_state.py
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 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 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 | |
Attributes¶
Functions¶
advance_step
¶advance_step()
Advance to the next execution step.
Source code in agentflow/state/execution_state.py
134 135 136 137 138 139 140 | |
clear_interrupt
¶clear_interrupt()
Clear the interrupt state and resume execution.
Source code in agentflow/state/execution_state.py
110 111 112 113 114 115 116 117 118 | |
complete
¶complete()
Mark execution as completed.
Source code in agentflow/state/execution_state.py
153 154 155 156 157 158 | |
error
¶error(error_msg)
Mark execution as errored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error_msg
¶ |
str
|
Error message to record. |
required |
Source code in agentflow/state/execution_state.py
160 161 162 163 164 165 166 167 168 169 | |
from_dict
classmethod
¶from_dict(data)
Create an ExecutionState instance from a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
¶ |
dict[str, Any]
|
Dictionary containing execution state fields. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ExecutionState |
ExecutionState
|
The deserialized execution state object. |
Source code in agentflow/state/execution_state.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
is_interrupted
¶is_interrupted()
Check if execution is currently interrupted.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if interrupted, False otherwise. |
Source code in agentflow/state/execution_state.py
120 121 122 123 124 125 126 127 128 129 130 131 132 | |
is_running
¶is_running()
Check if execution is currently running.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if running, False otherwise. |
Source code in agentflow/state/execution_state.py
171 172 173 174 175 176 177 178 179 180 | |
is_stopped_requested
¶is_stopped_requested()
Check if a stop has been requested for execution.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if stop requested, False otherwise. |
Source code in agentflow/state/execution_state.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
set_current_node
¶set_current_node(node)
Update the current node in execution state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
¶ |
str
|
Node to set as current. |
required |
Source code in agentflow/state/execution_state.py
142 143 144 145 146 147 148 149 150 151 | |
set_interrupt
¶set_interrupt(node, reason, status, data=None)
Set the interrupt state for execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
¶ |
str
|
Node where the interrupt occurred. |
required |
reason
¶ |
str
|
Reason for the interrupt. |
required |
status
¶ |
ExecutionStatus
|
Status to set for the interrupt. |
required |
data
¶ |
dict[str, Any] | None
|
Optional additional interrupt data. |
None
|
Source code in agentflow/state/execution_state.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
ExecutionStatus
¶
Bases: Enum
Status of graph execution.
Attributes:
| Name | Type | Description |
|---|---|---|
COMPLETED |
|
|
ERROR |
|
|
INTERRUPTED_AFTER |
|
|
INTERRUPTED_BEFORE |
|
|
RUNNING |
|
Source code in agentflow/state/execution_state.py
18 19 20 21 22 23 24 25 | |
Attributes¶
StopRequestStatus
¶
Bases: Enum
Status of graph execution.
Attributes:
| Name | Type | Description |
|---|---|---|
NONE |
|
|
STOPPED |
|
|
STOP_REQUESTED |
|
Source code in agentflow/state/execution_state.py
28 29 30 31 32 33 | |
message
¶
Message and content block primitives for agent graphs.
This module defines the core message representation, multimodal content blocks, token usage tracking, and utility functions for agent graph communication.
Classes:
| Name | Description |
|---|---|
TokenUsages |
Tracks token usage statistics for a message or model response. |
MediaRef |
Reference to media content (image/audio/video/document/data). |
AnnotationRef |
Reference to annotation metadata. |
Message |
Represents a message in a conversation, including content, role, metadata, and token usage. |
Functions:
| Name | Description |
|---|---|
generate_id |
Generates a message or tool call ID based on DI context and type. |
Attributes:
| Name | Type | Description |
|---|---|---|
logger |
|
Attributes¶
Classes¶
Message
¶
Bases: BaseModel
Represents a message in a conversation, including content, role, metadata, and token usage.
Attributes:
| Name | Type | Description |
|---|---|---|
message_id |
str | int
|
Unique identifier for the message. |
role |
Literal['user', 'assistant', 'system', 'tool']
|
The role of the message sender. |
content |
list[ContentBlock]
|
The message content blocks. |
delta |
bool
|
Indicates if this is a delta/partial message. |
tools_calls |
list[dict[str, Any]] | None
|
Tool call information, if any. |
reasoning |
str | None
|
Reasoning or explanation, if any. |
timestamp |
datetime | None
|
Timestamp of the message. |
metadata |
dict[str, Any]
|
Additional metadata. |
usages |
TokenUsages | None
|
Token usage statistics. |
raw |
dict[str, Any] | None
|
Raw data, if any. |
Example
msg = Message(message_id="abc123", role="user", content=[TextBlock(text="Hello!")])
Methods:
| Name | Description |
|---|---|
attach_media |
Append a media block to the content. |
text |
Best-effort text extraction from content blocks. |
text_message |
Create a Message instance from plain text. |
tool_message |
Create a tool message, optionally marking it as an error. |
Source code in agentflow/state/message.py
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 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 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 | |
Attributes¶
message_id
class-attribute
instance-attribute
¶message_id = Field(default_factory=lambda: generate_id(None))
timestamp
class-attribute
instance-attribute
¶timestamp = Field(default_factory=lambda: timestamp())
Functions¶
attach_media
¶attach_media(media, as_type)
Append a media block to the content.
If content was text, creates a block list. Supports image, audio, video, and document types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
media
¶ |
MediaRef
|
Reference to media content. |
required |
as_type
¶ |
Literal['image', 'audio', 'video', 'document']
|
Type of media block to append. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an unsupported media type is provided. |
Example
msg.attach_media(media_ref, as_type="image")
Source code in agentflow/state/message.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 | |
text
¶text()
Best-effort text extraction from content blocks.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Concatenated text from TextBlock and ToolResultBlock outputs. |
Example
msg.text() 'Hello!Result text.'
Source code in agentflow/state/message.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | |
text_message
classmethod
¶text_message(content, role='user', message_id=None)
Create a Message instance from plain text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
¶ |
str
|
The message content. |
required |
role
¶ |
Literal['user', 'assistant', 'system', 'tool']
|
The role of the sender. |
'user'
|
message_id
¶ |
str | None
|
Optional message ID. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Message |
Message
|
The created Message instance. |
Example
Message.text_message("Hello!", role="user")
Source code in agentflow/state/message.py
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 | |
tool_message
classmethod
¶tool_message(content, message_id=None, meta=None)
Create a tool message, optionally marking it as an error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
¶ |
list[ContentBlock]
|
The message content blocks. |
required |
message_id
¶ |
str | None
|
Optional message ID. |
None
|
meta
¶ |
dict[str, Any] | None
|
Optional metadata. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Message |
Message
|
The created tool message instance. |
Example
Message.tool_message([ToolResultBlock(...)], message_id="tool1")
Source code in agentflow/state/message.py
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 | |
TokenUsages
¶
Bases: BaseModel
Tracks token usage statistics for a message or model response.
Attributes:
| Name | Type | Description |
|---|---|---|
completion_tokens |
int
|
Number of completion tokens used. |
prompt_tokens |
int
|
Number of prompt tokens used. |
total_tokens |
int
|
Total tokens used. |
reasoning_tokens |
int
|
Reasoning tokens used (optional). |
cache_creation_input_tokens |
int
|
Cache creation input tokens (optional). |
cache_read_input_tokens |
int
|
Cache read input tokens (optional). |
image_tokens |
int | None
|
Image tokens for multimodal models (optional). |
audio_tokens |
int | None
|
Audio tokens for multimodal models (optional). |
Example
usage = TokenUsages(completion_tokens=10, prompt_tokens=20, total_tokens=30)
Source code in agentflow/state/message.py
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 124 125 126 | |
Attributes¶
Functions¶
generate_id
¶
generate_id(default_id)
Generate a message or tool call ID based on DI context and type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | int | None
|
Default ID to use if provided and matches type. |
required |
Returns:
| Type | Description |
|---|---|
str | int
|
str | int: Generated or provided ID, type determined by DI context. |
Example
generate_id("abc123") 'abc123' generate_id(None) 'a-uuid-string'
Source code in agentflow/state/message.py
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 | |
message_block
¶
Classes:
| Name | Description |
|---|---|
AnnotationBlock |
Annotation content block for messages. |
AnnotationRef |
Reference to annotation metadata (e.g., citation, note). |
AudioBlock |
Audio content block for messages. |
DataBlock |
Data content block for messages. |
DocumentBlock |
Document content block for messages. |
ErrorBlock |
Error content block for messages. |
ImageBlock |
Image content block for messages. |
MediaRef |
Reference to media content (image/audio/video/document/data). |
ReasoningBlock |
Reasoning content block for messages. |
RemoteToolCallBlock |
Remote Tool call content block for messages. |
TextBlock |
Text content block for messages. |
ToolCallBlock |
Tool call content block for messages. |
ToolResultBlock |
Tool result content block for messages. |
VideoBlock |
Video content block for messages. |
Attributes:
| Name | Type | Description |
|---|---|---|
ContentBlock |
|
Attributes¶
ContentBlock
module-attribute
¶
ContentBlock = Annotated[Union[TextBlock, ImageBlock, AudioBlock, VideoBlock, DocumentBlock, DataBlock, ToolCallBlock, RemoteToolCallBlock, ToolResultBlock, ReasoningBlock, AnnotationBlock, ErrorBlock], Field(discriminator='type')]
Classes¶
AnnotationBlock
¶
Bases: BaseModel
Annotation content block for messages.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Literal['annotation']
|
Block type discriminator. |
kind |
Literal['citation', 'note']
|
Kind of annotation. |
refs |
list[AnnotationRef]
|
List of annotation references. |
spans |
list[tuple[int, int]] | None
|
Spans covered by the annotation. |
Source code in agentflow/state/message_block.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
AnnotationRef
¶
Bases: BaseModel
Reference to annotation metadata (e.g., citation, note).
Attributes:
| Name | Type | Description |
|---|---|---|
url |
str | None
|
URL to annotation source. |
file_id |
str | None
|
Provider-managed file ID. |
page |
int | None
|
Page number (if applicable). |
index |
int | None
|
Index within the annotation source. |
title |
str | None
|
Title of the annotation. |
Source code in agentflow/state/message_block.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
AudioBlock
¶
Bases: BaseModel
Audio content block for messages.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Literal['audio']
|
Block type discriminator. |
media |
MediaRef
|
Reference to audio media. |
transcript |
str | None
|
Transcript of audio. |
sample_rate |
int | None
|
Sample rate in Hz. |
channels |
int | None
|
Number of audio channels. |
Source code in agentflow/state/message_block.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
DataBlock
¶
Bases: BaseModel
Data content block for messages.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Literal['data']
|
Block type discriminator. |
mime_type |
str
|
MIME type of the data. |
data_base64 |
str | None
|
Base64-encoded data. |
media |
MediaRef | None
|
Reference to associated media. |
Source code in agentflow/state/message_block.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
DocumentBlock
¶
Bases: BaseModel
Document content block for messages.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Literal['document']
|
Block type discriminator. |
media |
MediaRef
|
Reference to document media. |
pages |
list[int] | None
|
List of page numbers. |
excerpt |
str | None
|
Excerpt from the document. |
Source code in agentflow/state/message_block.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
ErrorBlock
¶
Bases: BaseModel
Error content block for messages.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Literal['error']
|
Block type discriminator. |
message |
str
|
Error message. |
code |
str | None
|
Error code. |
data |
dict[str, Any] | None
|
Additional error data. |
Source code in agentflow/state/message_block.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | |
ImageBlock
¶
Bases: BaseModel
Image content block for messages.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Literal['image']
|
Block type discriminator. |
media |
MediaRef
|
Reference to image media. |
alt_text |
str | None
|
Alternative text for accessibility. |
bbox |
list[float] | None
|
Bounding box coordinates [x1, y1, x2, y2]. |
Source code in agentflow/state/message_block.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
MediaRef
¶
Bases: BaseModel
Reference to media content (image/audio/video/document/data).
Prefer referencing by URL or provider file_id over inlining base64 for large payloads.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
Literal['url', 'file_id', 'data']
|
Type of reference. |
url |
str | None
|
URL to media content. |
file_id |
str | None
|
Provider-managed file ID. |
data_base64 |
str | None
|
Base64-encoded data (small payloads only). |
mime_type |
str | None
|
MIME type of the media. |
size_bytes |
int | None
|
Size in bytes. |
sha256 |
str | None
|
SHA256 hash of the media. |
filename |
str | None
|
Filename of the media. |
width |
int | None
|
Image width (if applicable). |
height |
int | None
|
Image height (if applicable). |
duration_ms |
int | None
|
Duration in milliseconds (if applicable). |
page |
int | None
|
Page number (if applicable). |
Source code in agentflow/state/message_block.py
6 7 8 9 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 | |
Attributes¶
ReasoningBlock
¶
Bases: BaseModel
Reasoning content block for messages.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Literal['reasoning']
|
Block type discriminator. |
summary |
str
|
Summary of reasoning. |
details |
list[str] | None
|
Detailed reasoning steps. |
Source code in agentflow/state/message_block.py
218 219 220 221 222 223 224 225 226 227 228 229 230 | |
RemoteToolCallBlock
¶
Bases: BaseModel
Remote Tool call content block for messages.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Literal['remote_tool_call']
|
Block type discriminator. |
id |
str
|
Tool call ID. |
name |
str
|
Tool name. |
args |
dict[str, Any]
|
Arguments for the tool call. |
tool_type |
str | None
|
Type of tool (e.g., web_search, file_search). |
Source code in agentflow/state/message_block.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
TextBlock
¶
Bases: BaseModel
Text content block for messages.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Literal['text']
|
Block type discriminator. |
text |
str
|
Text content. |
annotations |
list[AnnotationRef]
|
List of annotation references. |
Source code in agentflow/state/message_block.py
61 62 63 64 65 66 67 68 69 70 71 72 73 | |
ToolCallBlock
¶
Bases: BaseModel
Tool call content block for messages.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Literal['tool_call']
|
Block type discriminator. |
id |
str
|
Tool call ID. |
name |
str
|
Tool name. |
args |
dict[str, Any]
|
Arguments for the tool call. |
tool_type |
str | None
|
Type of tool (e.g., web_search, file_search). |
Source code in agentflow/state/message_block.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
ToolResultBlock
¶
Bases: BaseModel
Tool result content block for messages.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Literal['tool_result']
|
Block type discriminator. |
call_id |
str
|
Tool call ID. |
output |
Any
|
Output from the tool (str, dict, MediaRef, or list of blocks). |
is_error |
bool
|
Whether the result is an error. |
status |
Literal['completed', 'failed'] | None
|
Status of the tool call. |
Source code in agentflow/state/message_block.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
VideoBlock
¶
Bases: BaseModel
Video content block for messages.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Literal['video']
|
Block type discriminator. |
media |
MediaRef
|
Reference to video media. |
thumbnail |
MediaRef | None
|
Reference to thumbnail image. |
Source code in agentflow/state/message_block.py
112 113 114 115 116 117 118 119 120 121 122 123 124 | |
message_context_manager
¶
Message context management for agent state in TAF.
This module provides MessageContextManager, which trims and manages the message history (context) for agent interactions, ensuring efficient context window usage.
Classes:
| Name | Description |
|---|---|
MessageContextManager |
Manages the context field for AI interactions. |
Attributes:
| Name | Type | Description |
|---|---|---|
S |
|
|
logger |
|
Attributes¶
Classes¶
MessageContextManager
¶
Bases: BaseContextManager[S]
Manages the context field for AI interactions.
This class trims the context (message history) based on a maximum number of user messages, ensuring the first message (usually a system prompt) is always preserved. Optionally removes tool-related messages (AI messages with tool calls and tool result messages). Generic over AgentState or its subclasses.
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the MessageContextManager. |
atrim_context |
Asynchronous version of trim_context. |
trim_context |
Trim the context in the given AgentState based on the maximum number of user messages. |
Attributes:
| Name | Type | Description |
|---|---|---|
max_messages |
|
|
remove_tool_msgs |
|
Source code in agentflow/state/message_context_manager.py
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 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 | |
Attributes¶
Functions¶
__init__
¶__init__(max_messages=10, remove_tool_msgs=False)
Initialize the MessageContextManager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_messages
¶ |
int
|
Maximum number of user messages to keep in context. Default is 10. |
10
|
remove_tool_msgs
¶ |
bool
|
Whether to remove tool messages from context. Default is False. |
False
|
Source code in agentflow/state/message_context_manager.py
33 34 35 36 37 38 39 40 41 42 43 44 45 | |
atrim_context
async
¶atrim_context(state)
Asynchronous version of trim_context.
If remove_tool_msgs is True, also removes:
- AI messages that contain tool calls (intermediate tool-calling messages)
- Tool result messages (role="tool")
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
¶ |
AgentState
|
The agent state containing the context to trim. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
S |
S
|
The updated agent state with trimmed context. |
Source code in agentflow/state/message_context_manager.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
trim_context
¶trim_context(state)
Trim the context in the given AgentState based on the maximum number of user messages.
The first message (typically a system prompt) is always preserved. Only the most recent
user messages up to max_messages are kept, along with the first message.
If remove_tool_msgs is True, also removes:
- AI messages that contain tool calls (intermediate tool-calling messages)
- Tool result messages (role="tool")
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
¶ |
AgentState
|
The agent state containing the context to trim. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
S |
S
|
The updated agent state with trimmed context. |
Source code in agentflow/state/message_context_manager.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
Functions¶
reducers
¶
Reducer utilities for merging and replacing lists and values in agent state.
This module provides generic and message-specific reducers for combining lists, replacing values, and appending items while avoiding duplicates.
Functions:
| Name | Description |
|---|---|
add_messages |
Adds messages to a list, avoiding duplicates by message_id. |
replace_messages |
Replaces the entire message list. |
append_items |
Appends items to a list, avoiding duplicates by id. |
replace_value |
Replaces a value with another. |
Classes¶
Functions¶
add_messages
¶
add_messages(left, right)
Adds messages to the list, avoiding duplicates by message_id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[Message]
|
Existing list of messages. |
required |
|
list[Message]
|
New messages to add. |
required |
Returns:
| Type | Description |
|---|---|
list[Message]
|
list[Message]: Combined list with unique messages. |
Example
add_messages([msg1], [msg2, msg1]) [msg1, msg2]
Source code in agentflow/state/reducers.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
append_items
¶
append_items(left, right)
Appends items to a list, avoiding duplicates by item.id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list
|
Existing list of items (must have .id attribute). |
required |
|
list
|
New items to add. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
Combined list with unique items. |
Example
append_items([item1], [item2, item1]) [item1, item2]
Source code in agentflow/state/reducers.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
remove_tool_messages
¶
remove_tool_messages(messages)
Remove COMPLETED tool interaction sequences from the message list.
A tool sequence is only removed if it's COMPLETE: 1. AI message with tool_calls (triggering tools) 2. One or more tool result messages (role="tool") 3. AI message WITHOUT tool_calls (final response using tool results)
If a sequence is incomplete (e.g., tool call made but no final AI response yet), ALL messages are kept to maintain conversation continuity.
Edge cases handled: - Incomplete sequences (AI called tool, waiting for results): Keep everything - Partial sequences (AI called tool, got results, but no final response): Keep everything - Multiple tool calls in one AI message: Handles correctly - Consecutive tool sequences: Each evaluated independently
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[Message]
|
List of messages to filter. |
required |
Returns:
| Type | Description |
|---|---|
list[Message]
|
list[Message]: Filtered list with only COMPLETED tool sequences removed. |
Example
Complete sequence (will be cleaned):
messages = [user_msg, ai_with_tools, tool_result, ai_final] remove_tool_messages(messages) [user_msg, ai_final]
Incomplete sequence (will be kept):
messages = [user_msg, ai_with_tools] remove_tool_messages(messages) [user_msg, ai_with_tools] # Keep everything - sequence incomplete!
Partial sequence (will be kept):
messages = [user_msg, ai_with_tools, tool_result] remove_tool_messages(messages) [user_msg, ai_with_tools, tool_result] # Keep - no final AI response!
Source code in agentflow/state/reducers.py
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 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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
replace_messages
¶
replace_messages(left, right)
Replaces the entire message list with a new one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[Message]
|
Existing list of messages (ignored). |
required |
|
list[Message]
|
New list of messages. |
required |
Returns:
| Type | Description |
|---|---|
list[Message]
|
list[Message]: The new message list. |
Example
replace_messages([msg1], [msg2]) [msg2]
Source code in agentflow/state/reducers.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
replace_value
¶
replace_value(left, right)
Replaces a value with another.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Existing value (ignored). |
required | |
|
New value to use. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
The new value. |
Example
replace_value(1, 2) 2
Source code in agentflow/state/reducers.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
stream_chunks
¶
Stream chunk primitives for unified streaming data handling.
This module provides a unified StreamChunk class that can encapsulate different types of streaming data (Messages, EventModels, etc.) in a type-safe manner. This enables clean separation between conversation content and execution state while providing a consistent interface for streaming consumers.
Classes:
| Name | Description |
|---|---|
StreamChunk |
Unified wrapper for streaming data with type discrimination. |
Classes¶
StreamChunk
¶
Bases: BaseModel
Unified wrapper for different types of streaming data.
This class provides a single interface for handling various streaming chunk types (messages, events, state updates, errors) with type-safe discrimination.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
The type of streaming chunk. |
|
data |
dict | None
|
The actual chunk data (Message, EventModel, dict, etc.). |
metadata |
dict | None
|
Optional additional metadata for the chunk. |
Classes:
| Name | Description |
|---|---|
Config |
Pydantic configuration for EventModel. |
Source code in agentflow/state/stream_chunks.py
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 | |
Attributes¶
timestamp
class-attribute
instance-attribute
¶timestamp = Field(default_factory=timestamp, description='UNIX timestamp of when chunk was created')
Classes¶
Config
¶Pydantic configuration for EventModel.
Attributes:
| Name | Type | Description |
|---|---|---|
use_enum_values |
Output enums as strings. |
Source code in agentflow/state/stream_chunks.py
59 60 61 62 63 64 65 66 | |