10xScale Agentflow: A lightweight Python framework for building intelligent agents and multi-agent workflows.
Modules:
| Name | Description |
|---|---|
adapters |
Integration adapters for optional third-party SDKs. |
checkpointer |
Checkpointer adapters for agent state persistence in agentflow. |
exceptions |
Custom exception classes for graph operations in agentflowntflow. |
graph |
Agentflow Graph Module - Core Workflow Engine. |
prebuilt |
|
publisher |
Publisher module for TAF events. |
state |
State management for TAF agent graphs. |
store |
|
utils |
Unified utility exports for TAF agent graphs. |
Modules¶
adapters
¶
Integration adapters for optional third-party SDKs.
This package provides unified wrappers and converters for integrating external tool registries, LLM SDKs, and other third-party services with agentflow agent graphs. Adapters expose registry-based discovery, function-calling schemas, and normalized execution for supported providers.
Modules:
| Name | Description |
|---|---|
llm |
Integration adapters for optional third-party LLM SDKs. |
tools |
Integration adapters for optional third-party SDKs. |
Modules¶
llm
¶
Integration adapters for optional third-party LLM SDKs.
This module exposes universal converter APIs to normalize responses and streaming outputs from popular LLM SDKs (e.g., LiteLLM, OpenAI) for use in agentflow agent graphs. Adapters provide unified conversion, streaming, and message normalization for agent workflows.
Exports
BaseConverter: Abstract base class for LLM response converters. ConverterType: Enum of supported converter types. LiteLLMConverter: Converter for LiteLLM responses and streams.
OpenAIConverter: (commented, available if implemented)¶
Modules:
| Name | Description |
|---|---|
base_converter |
|
litellm_converter |
|
model_response_converter |
|
Classes:
| Name | Description |
|---|---|
BaseConverter |
Abstract base class for all LLM response converters. |
ConverterType |
Enumeration of supported converter types for LLM responses. |
LiteLLMConverter |
Converter for LiteLLM responses to agentflow Message format. |
Attributes¶
Classes¶
BaseConverter
¶
Bases: ABC
Abstract base class for all LLM response converters.
Subclasses should implement methods to convert standard and streaming LLM responses into agentflow's internal message/event formats.
Attributes:
| Name | Type | Description |
|---|---|---|
state |
AgentState | None
|
Optional agent state for context during conversion. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the converter. |
convert_response |
Convert a standard agent response to a Message. |
convert_streaming_response |
Convert a streaming agent response to an async generator of EventModel or Message. |
Source code in agentflow/adapters/llm/base_converter.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 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 | |
__init__
¶__init__(state=None)
Initialize the converter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
¶ |
AgentState | None
|
Optional agent state for context during conversion. |
None
|
Source code in agentflow/adapters/llm/base_converter.py
31 32 33 34 35 36 37 38 | |
convert_response
abstractmethod
async
¶convert_response(response)
Convert a standard agent response to a Message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
¶ |
Any
|
The raw response from the LLM or agent. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Message |
Message
|
The converted message object. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If not implemented in subclass. |
Source code in agentflow/adapters/llm/base_converter.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
convert_streaming_response
abstractmethod
async
¶convert_streaming_response(config, node_name, response, meta=None)
Convert a streaming agent response to an async generator of EventModel or Message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Node configuration parameters. |
required |
node_name
¶ |
str
|
Name of the node processing the response. |
required |
response
¶ |
Any
|
The raw streaming response from the LLM or agent. |
required |
meta
¶ |
dict | None
|
Optional metadata for conversion. |
None
|
Yields:
| Type | Description |
|---|---|
AsyncGenerator[EventModel | Message, None]
|
EventModel | Message: Chunks of the converted streaming response. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If not implemented in subclass. |
Source code in agentflow/adapters/llm/base_converter.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
ConverterType
¶
Bases: Enum
Enumeration of supported converter types for LLM responses.
Attributes:
| Name | Type | Description |
|---|---|---|
ANTHROPIC |
|
|
CUSTOM |
|
|
GOOGLE |
|
|
LITELLM |
|
|
OPENAI |
|
Source code in agentflow/adapters/llm/base_converter.py
10 11 12 13 14 15 16 17 | |
LiteLLMConverter
¶
Bases: BaseConverter
Converter for LiteLLM responses to agentflow Message format.
Handles both standard and streaming responses, extracting content, reasoning, tool calls, and token usage details.
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the converter. |
convert_response |
Convert a LiteLLM ModelResponse to a Message. |
convert_streaming_response |
Convert a LiteLLM streaming or standard response to Message(s). |
Attributes:
| Name | Type | Description |
|---|---|---|
state |
|
Source code in agentflow/adapters/llm/litellm_converter.py
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 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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 | |
__init__
¶__init__(state=None)
Initialize the converter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
¶ |
AgentState | None
|
Optional agent state for context during conversion. |
None
|
Source code in agentflow/adapters/llm/base_converter.py
31 32 33 34 35 36 37 38 | |
convert_response
async
¶convert_response(response)
Convert a LiteLLM ModelResponse to a Message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
¶ |
ModelResponse
|
The LiteLLM model response object. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Message |
Message
|
The converted message object. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If LiteLLM is not installed. |
Source code in agentflow/adapters/llm/litellm_converter.py
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 | |
convert_streaming_response
async
¶convert_streaming_response(config, node_name, response, meta=None)
Convert a LiteLLM streaming or standard response to Message(s).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Node configuration parameters. |
required |
node_name
¶ |
str
|
Name of the node processing the response. |
required |
response
¶ |
Any
|
The LiteLLM response object (stream or standard). |
required |
meta
¶ |
dict | None
|
Optional metadata for conversion. |
None
|
Yields:
| Name | Type | Description |
|---|---|---|
Message |
AsyncGenerator[Message]
|
Converted message(s) from the response. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If LiteLLM is not installed. |
Exception
|
If response type is unsupported. |
Source code in agentflow/adapters/llm/litellm_converter.py
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 | |
Modules¶
base_converter
¶Classes:
| Name | Description |
|---|---|
BaseConverter |
Abstract base class for all LLM response converters. |
ConverterType |
Enumeration of supported converter types for LLM responses. |
BaseConverter
¶
Bases: ABC
Abstract base class for all LLM response converters.
Subclasses should implement methods to convert standard and streaming LLM responses into agentflow's internal message/event formats.
Attributes:
| Name | Type | Description |
|---|---|---|
state |
AgentState | None
|
Optional agent state for context during conversion. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the converter. |
convert_response |
Convert a standard agent response to a Message. |
convert_streaming_response |
Convert a streaming agent response to an async generator of EventModel or Message. |
Source code in agentflow/adapters/llm/base_converter.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 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 | |
__init__
¶__init__(state=None)
Initialize the converter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
¶ |
AgentState | None
|
Optional agent state for context during conversion. |
None
|
Source code in agentflow/adapters/llm/base_converter.py
31 32 33 34 35 36 37 38 | |
convert_response
abstractmethod
async
¶convert_response(response)
Convert a standard agent response to a Message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
¶ |
Any
|
The raw response from the LLM or agent. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Message |
Message
|
The converted message object. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If not implemented in subclass. |
Source code in agentflow/adapters/llm/base_converter.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
convert_streaming_response
abstractmethod
async
¶convert_streaming_response(config, node_name, response, meta=None)
Convert a streaming agent response to an async generator of EventModel or Message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Node configuration parameters. |
required |
node_name
¶ |
str
|
Name of the node processing the response. |
required |
response
¶ |
Any
|
The raw streaming response from the LLM or agent. |
required |
meta
¶ |
dict | None
|
Optional metadata for conversion. |
None
|
Yields:
| Type | Description |
|---|---|
AsyncGenerator[EventModel | Message, None]
|
EventModel | Message: Chunks of the converted streaming response. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If not implemented in subclass. |
Source code in agentflow/adapters/llm/base_converter.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
ConverterType
¶
Bases: Enum
Enumeration of supported converter types for LLM responses.
Attributes:
| Name | Type | Description |
|---|---|---|
ANTHROPIC |
|
|
CUSTOM |
|
|
GOOGLE |
|
|
LITELLM |
|
|
OPENAI |
|
Source code in agentflow/adapters/llm/base_converter.py
10 11 12 13 14 15 16 17 | |
litellm_converter
¶Classes:
| Name | Description |
|---|---|
LiteLLMConverter |
Converter for LiteLLM responses to agentflow Message format. |
Attributes:
| Name | Type | Description |
|---|---|---|
HAS_LITELLM |
|
|
logger |
|
LiteLLMConverter
¶
Bases: BaseConverter
Converter for LiteLLM responses to agentflow Message format.
Handles both standard and streaming responses, extracting content, reasoning, tool calls, and token usage details.
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the converter. |
convert_response |
Convert a LiteLLM ModelResponse to a Message. |
convert_streaming_response |
Convert a LiteLLM streaming or standard response to Message(s). |
Attributes:
| Name | Type | Description |
|---|---|---|
state |
|
Source code in agentflow/adapters/llm/litellm_converter.py
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 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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 | |
__init__
¶__init__(state=None)
Initialize the converter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
¶ |
AgentState | None
|
Optional agent state for context during conversion. |
None
|
Source code in agentflow/adapters/llm/base_converter.py
31 32 33 34 35 36 37 38 | |
convert_response
async
¶convert_response(response)
Convert a LiteLLM ModelResponse to a Message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
¶ |
ModelResponse
|
The LiteLLM model response object. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Message |
Message
|
The converted message object. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If LiteLLM is not installed. |
Source code in agentflow/adapters/llm/litellm_converter.py
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 | |
convert_streaming_response
async
¶convert_streaming_response(config, node_name, response, meta=None)
Convert a LiteLLM streaming or standard response to Message(s).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Node configuration parameters. |
required |
node_name
¶ |
str
|
Name of the node processing the response. |
required |
response
¶ |
Any
|
The LiteLLM response object (stream or standard). |
required |
meta
¶ |
dict | None
|
Optional metadata for conversion. |
None
|
Yields:
| Name | Type | Description |
|---|---|---|
Message |
AsyncGenerator[Message]
|
Converted message(s) from the response. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If LiteLLM is not installed. |
Exception
|
If response type is unsupported. |
Source code in agentflow/adapters/llm/litellm_converter.py
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 | |
model_response_converter
¶Classes:
| Name | Description |
|---|---|
ModelResponseConverter |
Wrap an LLM SDK call and normalize its output via a converter. |
ModelResponseConverter
¶Wrap an LLM SDK call and normalize its output via a converter.
Supports sync/async invocation and streaming. Use invoke() for
non-streaming calls and stream() for streaming calls.
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize ModelResponseConverter. |
invoke |
Call the underlying function and convert a non-streaming response to Message. |
stream |
Call the underlying function and yield normalized streaming events and final Message. |
Attributes:
| Name | Type | Description |
|---|---|---|
converter |
|
|
response |
|
Source code in agentflow/adapters/llm/model_response_converter.py
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 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 | |
__init__
¶__init__(response, converter)
Initialize ModelResponseConverter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
¶ |
Any | Callable[..., Any]
|
The LLM response or a callable returning a response. |
required |
converter
¶ |
BaseConverter | str
|
Converter instance or string identifier (e.g., "litellm"). |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the converter is not supported. |
Source code in agentflow/adapters/llm/model_response_converter.py
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 | |
invoke
async
¶invoke()
Call the underlying function and convert a non-streaming response to Message.
Returns:
| Name | Type | Description |
|---|---|---|
Message |
Message
|
The normalized message from the LLM response. |
Raises:
| Type | Description |
|---|---|
Exception
|
If the underlying function or converter fails. |
Source code in agentflow/adapters/llm/model_response_converter.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
stream
async
¶stream(config, node_name, meta=None)
Call the underlying function and yield normalized streaming events and final Message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Node configuration parameters for streaming. |
required |
node_name
¶ |
str
|
Name of the node processing the response. |
required |
meta
¶ |
dict | None
|
Optional metadata for conversion. |
None
|
Yields:
| Name | Type | Description |
|---|---|---|
Message |
AsyncGenerator[Message]
|
Normalized streaming message events from the LLM response. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If config is not provided. |
Exception
|
If the underlying function or converter fails. |
Source code in agentflow/adapters/llm/model_response_converter.py
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 | |
tools
¶
Integration adapters for optional third-party SDKs.
This module exposes unified wrappers for integrating external tool registries and SDKs with agentflow agent graphs. The adapters provide registry-based discovery, function-calling schemas, and normalized execution for supported tool providers.
Exports
ComposioAdapter: Adapter for the Composio Python SDK. LangChainAdapter: Adapter for LangChain tool registry and execution.
Modules:
| Name | Description |
|---|---|
composio_adapter |
Composio adapter for agentflow. |
langchain_adapter |
LangChain adapter for agentflow (generic wrapper, registry-based). |
Classes:
| Name | Description |
|---|---|
ComposioAdapter |
Adapter around Composio Python SDK. |
LangChainAdapter |
Generic registry-based LangChain adapter. |
Attributes¶
Classes¶
ComposioAdapter
¶Adapter around Composio Python SDK.
Notes on SDK methods used (from docs): - composio.tools.get(user_id=..., tools=[...]/toolkits=[...]/search=..., scopes=..., limit=...) Returns tools formatted for providers or agent frameworks; includes schema. - composio.tools.get_raw_composio_tools(...) Returns raw tool schemas including input_parameters. - composio.tools.execute(slug, arguments, user_id=..., connected_account_id=..., ...) Executes a tool and returns a dict like {data, successful, error}.
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the ComposioAdapter. |
execute |
Execute a Composio tool and return a normalized response dict. |
is_available |
Return True if composio SDK is importable. |
list_raw_tools_for_llm |
Return raw Composio tool schemas mapped to function-calling format. |
list_tools_for_llm |
Return tools formatted for LLM function-calling. |
Source code in agentflow/adapters/tools/composio_adapter.py
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 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 | |
__init__
¶__init__(*, api_key=None, provider=None, file_download_dir=None, toolkit_versions=None)
Initialize the ComposioAdapter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
¶ |
str | None
|
Optional API key for Composio. |
None
|
provider
¶ |
Any | None
|
Optional provider integration. |
None
|
file_download_dir
¶ |
str | None
|
Directory for auto file handling. |
None
|
toolkit_versions
¶ |
Any | None
|
Toolkit version overrides. |
None
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If composio SDK is not installed. |
Source code in agentflow/adapters/tools/composio_adapter.py
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 | |
execute
¶execute(*, slug, arguments, user_id=None, connected_account_id=None, custom_auth_params=None, custom_connection_data=None, text=None, version=None, toolkit_versions=None, modifiers=None)
Execute a Composio tool and return a normalized response dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slug
¶ |
str
|
Tool slug to execute. |
required |
arguments
¶ |
dict[str, Any]
|
Arguments for the tool. |
required |
user_id
¶ |
str | None
|
Optional user ID. |
None
|
connected_account_id
¶ |
str | None
|
Optional connected account ID. |
None
|
custom_auth_params
¶ |
dict[str, Any] | None
|
Optional custom auth params. |
None
|
custom_connection_data
¶ |
dict[str, Any] | None
|
Optional custom connection data. |
None
|
text
¶ |
str | None
|
Optional text input. |
None
|
version
¶ |
str | None
|
Optional version. |
None
|
toolkit_versions
¶ |
Any | None
|
Optional toolkit versions. |
None
|
modifiers
¶ |
Any | None
|
Optional modifiers. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Normalized response dict with keys: successful, data, error. |
Source code in agentflow/adapters/tools/composio_adapter.py
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 | |
is_available
staticmethod
¶is_available()
Return True if composio SDK is importable.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if composio SDK is available, False otherwise. |
Source code in agentflow/adapters/tools/composio_adapter.py
83 84 85 86 87 88 89 90 91 | |
list_raw_tools_for_llm
¶list_raw_tools_for_llm(*, tool_slugs=None, toolkits=None, search=None, scopes=None, limit=None)
Return raw Composio tool schemas mapped to function-calling format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_slugs
¶ |
list[str] | None
|
Optional list of tool slugs. |
None
|
toolkits
¶ |
list[str] | None
|
Optional list of toolkits. |
None
|
search
¶ |
str | None
|
Optional search string. |
None
|
scopes
¶ |
list[str] | None
|
Optional scopes. |
None
|
limit
¶ |
int | None
|
Optional limit on number of tools. |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: List of raw tool schemas in function-calling format. |
Source code in agentflow/adapters/tools/composio_adapter.py
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 | |
list_tools_for_llm
¶list_tools_for_llm(*, user_id, tool_slugs=None, toolkits=None, search=None, scopes=None, limit=None)
Return tools formatted for LLM function-calling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
¶ |
str
|
User ID for tool discovery. |
required |
tool_slugs
¶ |
list[str] | None
|
Optional list of tool slugs. |
None
|
toolkits
¶ |
list[str] | None
|
Optional list of toolkits. |
None
|
search
¶ |
str | None
|
Optional search string. |
None
|
scopes
¶ |
list[str] | None
|
Optional scopes. |
None
|
limit
¶ |
int | None
|
Optional limit on number of tools. |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: List of tools in function-calling format. |
Source code in agentflow/adapters/tools/composio_adapter.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 | |
LangChainAdapter
¶Generic registry-based LangChain adapter.
Notes
- Avoids importing heavy integrations until needed (lazy default autoload).
- Normalizes schemas and execution results into simple dicts.
- Allows arbitrary tool registration instead of hardcoding a tiny set.
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize LangChainAdapter. |
execute |
Execute a supported LangChain tool and normalize the response. |
is_available |
Return True if langchain-core is importable. |
list_tools_for_llm |
Return a list of function-calling formatted tool schemas. |
register_tool |
Register a tool instance and return the resolved name used for exposure. |
register_tools |
Register multiple tool instances. |
Source code in agentflow/adapters/tools/langchain_adapter.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | |
__init__
¶__init__(*, autoload_default_tools=True)
Initialize LangChainAdapter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
autoload_default_tools
¶ |
bool
|
Whether to autoload default tools if registry is empty. |
True
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If langchain-core is not installed. |
Source code in agentflow/adapters/tools/langchain_adapter.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
execute
¶execute(*, name, arguments)
Execute a supported LangChain tool and normalize the response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
¶ |
str
|
Name of the tool to execute. |
required |
arguments
¶ |
dict[str, Any]
|
Arguments for the tool. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Normalized response dict with keys: successful, data, error. |
Source code in agentflow/adapters/tools/langchain_adapter.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
is_available
staticmethod
¶is_available()
Return True if langchain-core is importable.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if langchain-core is available, False otherwise. |
Source code in agentflow/adapters/tools/langchain_adapter.py
257 258 259 260 261 262 263 264 265 | |
list_tools_for_llm
¶list_tools_for_llm()
Return a list of function-calling formatted tool schemas.
If registry is empty and autoload is enabled, attempt to autoload a couple of common tools for convenience (tavily_search, requests_get).
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: List of tool schemas in function-calling format. |
Source code in agentflow/adapters/tools/langchain_adapter.py
270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
register_tool
¶register_tool(tool, *, name=None, description=None)
Register a tool instance and return the resolved name used for exposure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool
¶ |
Any
|
Tool instance to register. |
required |
name
¶ |
str | None
|
Optional override for tool name. |
None
|
description
¶ |
str | None
|
Optional override for tool description. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The resolved name used for exposure. |
Source code in agentflow/adapters/tools/langchain_adapter.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | |
register_tools
¶register_tools(tools)
Register multiple tool instances.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tools
¶ |
list[Any]
|
List of tool instances to register. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: List of resolved names for the registered tools. |
Source code in agentflow/adapters/tools/langchain_adapter.py
333 334 335 336 337 338 339 340 341 342 343 344 345 346 | |
Modules¶
composio_adapter
¶Composio adapter for agentflow.
This module provides a thin wrapper around the Composio Python SDK to: - Fetch tools formatted for LLM function calling (matching ToolNode format) - Execute Composio tools directly
The dependency is optional. Install with: pip install 10xscale-agentflow[composio]
Usage outline
adapter = ComposioAdapter(api_key=os.environ["COMPOSIO_API_KEY"]) # optional key result = adapter.execute( slug="GITHUB_LIST_STARGAZERS", arguments={"owner": "ComposioHQ", "repo": "composio"}, user_id="user-123", )
Classes:
| Name | Description |
|---|---|
ComposioAdapter |
Adapter around Composio Python SDK. |
Attributes:
| Name | Type | Description |
|---|---|---|
HAS_COMPOSIO |
|
|
logger |
|
ComposioAdapter
¶Adapter around Composio Python SDK.
Notes on SDK methods used (from docs): - composio.tools.get(user_id=..., tools=[...]/toolkits=[...]/search=..., scopes=..., limit=...) Returns tools formatted for providers or agent frameworks; includes schema. - composio.tools.get_raw_composio_tools(...) Returns raw tool schemas including input_parameters. - composio.tools.execute(slug, arguments, user_id=..., connected_account_id=..., ...) Executes a tool and returns a dict like {data, successful, error}.
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the ComposioAdapter. |
execute |
Execute a Composio tool and return a normalized response dict. |
is_available |
Return True if composio SDK is importable. |
list_raw_tools_for_llm |
Return raw Composio tool schemas mapped to function-calling format. |
list_tools_for_llm |
Return tools formatted for LLM function-calling. |
Source code in agentflow/adapters/tools/composio_adapter.py
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 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 | |
__init__
¶__init__(*, api_key=None, provider=None, file_download_dir=None, toolkit_versions=None)
Initialize the ComposioAdapter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
¶ |
str | None
|
Optional API key for Composio. |
None
|
provider
¶ |
Any | None
|
Optional provider integration. |
None
|
file_download_dir
¶ |
str | None
|
Directory for auto file handling. |
None
|
toolkit_versions
¶ |
Any | None
|
Toolkit version overrides. |
None
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If composio SDK is not installed. |
Source code in agentflow/adapters/tools/composio_adapter.py
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 | |
execute
¶execute(*, slug, arguments, user_id=None, connected_account_id=None, custom_auth_params=None, custom_connection_data=None, text=None, version=None, toolkit_versions=None, modifiers=None)
Execute a Composio tool and return a normalized response dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slug
¶ |
str
|
Tool slug to execute. |
required |
arguments
¶ |
dict[str, Any]
|
Arguments for the tool. |
required |
user_id
¶ |
str | None
|
Optional user ID. |
None
|
connected_account_id
¶ |
str | None
|
Optional connected account ID. |
None
|
custom_auth_params
¶ |
dict[str, Any] | None
|
Optional custom auth params. |
None
|
custom_connection_data
¶ |
dict[str, Any] | None
|
Optional custom connection data. |
None
|
text
¶ |
str | None
|
Optional text input. |
None
|
version
¶ |
str | None
|
Optional version. |
None
|
toolkit_versions
¶ |
Any | None
|
Optional toolkit versions. |
None
|
modifiers
¶ |
Any | None
|
Optional modifiers. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Normalized response dict with keys: successful, data, error. |
Source code in agentflow/adapters/tools/composio_adapter.py
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 | |
is_available
staticmethod
¶is_available()
Return True if composio SDK is importable.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if composio SDK is available, False otherwise. |
Source code in agentflow/adapters/tools/composio_adapter.py
83 84 85 86 87 88 89 90 91 | |
list_raw_tools_for_llm
¶list_raw_tools_for_llm(*, tool_slugs=None, toolkits=None, search=None, scopes=None, limit=None)
Return raw Composio tool schemas mapped to function-calling format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_slugs
¶ |
list[str] | None
|
Optional list of tool slugs. |
None
|
toolkits
¶ |
list[str] | None
|
Optional list of toolkits. |
None
|
search
¶ |
str | None
|
Optional search string. |
None
|
scopes
¶ |
list[str] | None
|
Optional scopes. |
None
|
limit
¶ |
int | None
|
Optional limit on number of tools. |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: List of raw tool schemas in function-calling format. |
Source code in agentflow/adapters/tools/composio_adapter.py
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 | |
list_tools_for_llm
¶list_tools_for_llm(*, user_id, tool_slugs=None, toolkits=None, search=None, scopes=None, limit=None)
Return tools formatted for LLM function-calling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
¶ |
str
|
User ID for tool discovery. |
required |
tool_slugs
¶ |
list[str] | None
|
Optional list of tool slugs. |
None
|
toolkits
¶ |
list[str] | None
|
Optional list of toolkits. |
None
|
search
¶ |
str | None
|
Optional search string. |
None
|
scopes
¶ |
list[str] | None
|
Optional scopes. |
None
|
limit
¶ |
int | None
|
Optional limit on number of tools. |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: List of tools in function-calling format. |
Source code in agentflow/adapters/tools/composio_adapter.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 | |
langchain_adapter
¶LangChain adapter for agentflow (generic wrapper, registry-based).
This adapter mirrors the spirit of Google's ADK LangChain wrapper by allowing
you to register any LangChain tool (BaseTool/StructuredTool) or a duck-typed
object that exposes a run/_run method, then exposing it to agentflow in
the uniform function-calling schema that ToolNode expects.
Key points:
- Register arbitrary tools at runtime via register_tool / register_tools.
- Tool schemas are derived from tool.args (when available) or inferred from
the tool's pydantic args_schema; otherwise, we fallback to a minimal
best-effort schema inferred from the wrapped function signature.
- Execution prefers invoke (Runnable interface) and falls back to run/
_run or calling a wrapped function with kwargs.
Optional install
pip install 10xscale-agentflow[langchain]
Backward-compat convenience:
- For continuity with prior versions, the adapter can auto-register two common
tools (tavily_search and requests_get) if autoload_default_tools is
True and no user-registered tools exist. You can disable this by passing
autoload_default_tools=False to the constructor.
Classes:
| Name | Description |
|---|---|
LangChainAdapter |
Generic registry-based LangChain adapter. |
LangChainToolWrapper |
Wrap a LangChain tool or a duck-typed tool into a uniform interface. |
Attributes:
| Name | Type | Description |
|---|---|---|
HAS_LANGCHAIN |
|
|
logger |
|
LangChainAdapter
¶Generic registry-based LangChain adapter.
Notes
- Avoids importing heavy integrations until needed (lazy default autoload).
- Normalizes schemas and execution results into simple dicts.
- Allows arbitrary tool registration instead of hardcoding a tiny set.
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize LangChainAdapter. |
execute |
Execute a supported LangChain tool and normalize the response. |
is_available |
Return True if langchain-core is importable. |
list_tools_for_llm |
Return a list of function-calling formatted tool schemas. |
register_tool |
Register a tool instance and return the resolved name used for exposure. |
register_tools |
Register multiple tool instances. |
Source code in agentflow/adapters/tools/langchain_adapter.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | |
__init__
¶__init__(*, autoload_default_tools=True)
Initialize LangChainAdapter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
autoload_default_tools
¶ |
bool
|
Whether to autoload default tools if registry is empty. |
True
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If langchain-core is not installed. |
Source code in agentflow/adapters/tools/langchain_adapter.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
execute
¶execute(*, name, arguments)
Execute a supported LangChain tool and normalize the response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
¶ |
str
|
Name of the tool to execute. |
required |
arguments
¶ |
dict[str, Any]
|
Arguments for the tool. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Normalized response dict with keys: successful, data, error. |
Source code in agentflow/adapters/tools/langchain_adapter.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
is_available
staticmethod
¶is_available()
Return True if langchain-core is importable.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if langchain-core is available, False otherwise. |
Source code in agentflow/adapters/tools/langchain_adapter.py
257 258 259 260 261 262 263 264 265 | |
list_tools_for_llm
¶list_tools_for_llm()
Return a list of function-calling formatted tool schemas.
If registry is empty and autoload is enabled, attempt to autoload a couple of common tools for convenience (tavily_search, requests_get).
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: List of tool schemas in function-calling format. |
Source code in agentflow/adapters/tools/langchain_adapter.py
270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
register_tool
¶register_tool(tool, *, name=None, description=None)
Register a tool instance and return the resolved name used for exposure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool
¶ |
Any
|
Tool instance to register. |
required |
name
¶ |
str | None
|
Optional override for tool name. |
None
|
description
¶ |
str | None
|
Optional override for tool description. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The resolved name used for exposure. |
Source code in agentflow/adapters/tools/langchain_adapter.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | |
register_tools
¶register_tools(tools)
Register multiple tool instances.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tools
¶ |
list[Any]
|
List of tool instances to register. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: List of resolved names for the registered tools. |
Source code in agentflow/adapters/tools/langchain_adapter.py
333 334 335 336 337 338 339 340 341 342 343 344 345 346 | |
LangChainToolWrapper
¶Wrap a LangChain tool or a duck-typed tool into a uniform interface.
Responsibilities
- Resolve execution entrypoint (invoke/run/_run/callable func)
- Provide a function-calling schema {name, description, parameters}
- Execute with dict arguments and return a JSON-serializable result
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize LangChainToolWrapper. |
execute |
Execute the wrapped tool with the provided arguments. |
to_schema |
Return the function-calling schema for the wrapped tool. |
Attributes:
| Name | Type | Description |
|---|---|---|
description |
|
|
name |
|
Source code in agentflow/adapters/tools/langchain_adapter.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 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 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 | |
description
instance-attribute
¶description = description or getattr(tool, 'description', None) or f'LangChain tool wrapper for {__name__}'
__init__
¶__init__(tool, *, name=None, description=None)
Initialize LangChainToolWrapper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool
¶ |
Any
|
The LangChain tool or duck-typed object to wrap. |
required |
name
¶ |
str | None
|
Optional override for tool name. |
None
|
description
¶ |
str | None
|
Optional override for tool description. |
None
|
Source code in agentflow/adapters/tools/langchain_adapter.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
execute
¶execute(arguments)
Execute the wrapped tool with the provided arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arguments
¶ |
dict[str, Any]
|
Arguments to pass to the tool. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Normalized response dict with keys: successful, data, error. |
Source code in agentflow/adapters/tools/langchain_adapter.py
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 | |
to_schema
¶to_schema()
Return the function-calling schema for the wrapped tool.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Function-calling schema with name, description, parameters. |
Source code in agentflow/adapters/tools/langchain_adapter.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
checkpointer
¶
Checkpointer adapters for agent state persistence in agentflow.
This module exposes unified checkpointing interfaces for agent graphs, supporting in-memory and Postgres-backed persistence. PgCheckpointer is only exported if its dependencies (asyncpg, redis) are available.
Exports
BaseCheckpointer: Abstract base class for checkpointing implementations. InMemoryCheckpointer: In-memory checkpointing for development/testing. PgCheckpointer: Postgres+Redis checkpointing (optional, requires extras).
Usage
PgCheckpointer requires: pip install 10xscale-agentflow[pg_checkpoint]
Modules:
| Name | Description |
|---|---|
base_checkpointer |
|
in_memory_checkpointer |
|
pg_checkpointer |
|
Classes:
| Name | Description |
|---|---|
BaseCheckpointer |
Abstract base class for checkpointing agent state, messages, and threads. |
InMemoryCheckpointer |
In-memory implementation of BaseCheckpointer. |
PgCheckpointer |
Implements a checkpointer using PostgreSQL and Redis for persistent and cached state management. |
Attributes¶
Classes¶
BaseCheckpointer
¶
Bases: ABC
Abstract base class for checkpointing agent state, messages, and threads.
This class defines the contract for all checkpointer implementations, supporting both async and sync methods. Subclasses should implement async methods for optimal performance. Sync methods are provided for compatibility.
Usage
- Async-first design: subclasses should implement
async defmethods. - If a subclass provides only a sync
def, it will be executed in a worker thread automatically usingasyncio.run. - Callers always use the async APIs (
await cp.put_state(...), etc.).
Class Type Parameters:
| Name | Bound or Constraints | Description | Default |
|---|---|---|---|
StateT
|
AgentState
|
Type of agent state (must inherit from AgentState). |
required |
Methods:
| Name | Description |
|---|---|
aclean_thread |
Clean/delete thread asynchronously. |
aclear_state |
Clear agent state asynchronously. |
adelete_message |
Delete a specific message asynchronously. |
aget_message |
Retrieve a specific message asynchronously. |
aget_state |
Retrieve agent state asynchronously. |
aget_state_cache |
Retrieve agent state from cache asynchronously. |
aget_thread |
Retrieve thread info asynchronously. |
alist_messages |
List messages asynchronously with optional filtering. |
alist_threads |
List threads asynchronously with optional filtering. |
aput_messages |
Store messages asynchronously. |
aput_state |
Store agent state asynchronously. |
aput_state_cache |
Store agent state in cache asynchronously. |
aput_thread |
Store thread info asynchronously. |
arelease |
Release resources asynchronously. |
asetup |
Asynchronous setup method for checkpointer. |
clean_thread |
Clean/delete thread synchronously. |
clear_state |
Clear agent state synchronously. |
delete_message |
Delete a specific message synchronously. |
get_message |
Retrieve a specific message synchronously. |
get_state |
Retrieve agent state synchronously. |
get_state_cache |
Retrieve agent state from cache synchronously. |
get_thread |
Retrieve thread info synchronously. |
list_messages |
List messages synchronously with optional filtering. |
list_threads |
List threads synchronously with optional filtering. |
put_messages |
Store messages synchronously. |
put_state |
Store agent state synchronously. |
put_state_cache |
Store agent state in cache synchronously. |
put_thread |
Store thread info synchronously. |
release |
Release resources synchronously. |
setup |
Synchronous setup method for checkpointer. |
Source code in agentflow/checkpointer/base_checkpointer.py
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 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 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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 | |
Functions¶
aclean_thread
abstractmethod
async
¶aclean_thread(config)
Clean/delete thread asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
395 396 397 398 399 400 401 402 403 404 405 406 | |
aclear_state
abstractmethod
async
¶aclear_state(config)
Clear agent state asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
90 91 92 93 94 95 96 97 98 99 100 101 | |
adelete_message
abstractmethod
async
¶adelete_message(config, message_id)
Delete a specific message asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
message_id
¶ |
str | int
|
Message identifier. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
254 255 256 257 258 259 260 261 262 263 264 265 266 | |
aget_message
abstractmethod
async
¶aget_message(config, message_id)
Retrieve a specific message asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
message_id
¶ |
str | int
|
Message identifier. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Message |
Message
|
Retrieved message object. |
Source code in agentflow/checkpointer/base_checkpointer.py
218 219 220 221 222 223 224 225 226 227 228 229 230 | |
aget_state
abstractmethod
async
¶aget_state(config)
Retrieve agent state asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
StateT | None
|
StateT | None: Retrieved state or None. |
Source code in agentflow/checkpointer/base_checkpointer.py
77 78 79 80 81 82 83 84 85 86 87 88 | |
aget_state_cache
abstractmethod
async
¶aget_state_cache(config)
Retrieve agent state from cache asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
StateT | None
|
StateT | None: Cached state or None. |
Source code in agentflow/checkpointer/base_checkpointer.py
117 118 119 120 121 122 123 124 125 126 127 128 | |
aget_thread
abstractmethod
async
¶aget_thread(config)
Retrieve thread info asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
ThreadInfo | None
|
ThreadInfo | None: Thread information object or None. |
Source code in agentflow/checkpointer/base_checkpointer.py
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 | |
alist_messages
abstractmethod
async
¶alist_messages(config, search=None, offset=None, limit=None)
List messages asynchronously with optional filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
search
¶ |
str
|
Search string. |
None
|
offset
¶ |
int
|
Offset for pagination. |
None
|
limit
¶ |
int
|
Limit for pagination. |
None
|
Returns:
| Type | Description |
|---|---|
list[Message]
|
list[Message]: List of message objects. |
Source code in agentflow/checkpointer/base_checkpointer.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
alist_threads
abstractmethod
async
¶alist_threads(config, search=None, offset=None, limit=None)
List threads asynchronously with optional filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
search
¶ |
str
|
Search string. |
None
|
offset
¶ |
int
|
Offset for pagination. |
None
|
limit
¶ |
int
|
Limit for pagination. |
None
|
Returns:
| Type | Description |
|---|---|
list[ThreadInfo]
|
list[ThreadInfo]: List of thread information objects. |
Source code in agentflow/checkpointer/base_checkpointer.py
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | |
aput_messages
abstractmethod
async
¶aput_messages(config, messages, metadata=None)
Store messages asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
messages
¶ |
list[Message]
|
List of messages to store. |
required |
metadata
¶ |
dict
|
Additional metadata. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
aput_state
abstractmethod
async
¶aput_state(config, state)
Store agent state asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
state
¶ |
StateT
|
State object to store. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
StateT |
StateT
|
The stored state object. |
Source code in agentflow/checkpointer/base_checkpointer.py
63 64 65 66 67 68 69 70 71 72 73 74 75 | |
aput_state_cache
abstractmethod
async
¶aput_state_cache(config, state)
Store agent state in cache asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
state
¶ |
StateT
|
State object to cache. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
103 104 105 106 107 108 109 110 111 112 113 114 115 | |
aput_thread
abstractmethod
async
¶aput_thread(config, thread_info)
Store thread info asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
thread_info
¶ |
ThreadInfo
|
Thread information object. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | |
arelease
abstractmethod
async
¶arelease()
Release resources asynchronously.
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
481 482 483 484 485 486 487 488 489 | |
asetup
abstractmethod
async
¶asetup()
Asynchronous setup method for checkpointer.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Implementation-defined setup result. |
Source code in agentflow/checkpointer/base_checkpointer.py
50 51 52 53 54 55 56 57 58 | |
clean_thread
¶clean_thread(config)
Clean/delete thread synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
457 458 459 460 461 462 463 464 465 466 467 | |
clear_state
¶clear_state(config)
Clear agent state synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
158 159 160 161 162 163 164 165 166 167 168 | |
delete_message
¶delete_message(config, message_id)
Delete a specific message synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
message_id
¶ |
str | int
|
Message identifier. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
323 324 325 326 327 328 329 330 331 332 333 334 | |
get_message
¶get_message(config, message_id)
Retrieve a specific message synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Message |
Message
|
Retrieved message object. |
Source code in agentflow/checkpointer/base_checkpointer.py
290 291 292 293 294 295 296 297 298 299 300 | |
get_state
¶get_state(config)
Retrieve agent state synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
StateT | None
|
StateT | None: Retrieved state or None. |
Source code in agentflow/checkpointer/base_checkpointer.py
146 147 148 149 150 151 152 153 154 155 156 | |
get_state_cache
¶get_state_cache(config)
Retrieve agent state from cache synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
StateT | None
|
StateT | None: Cached state or None. |
Source code in agentflow/checkpointer/base_checkpointer.py
183 184 185 186 187 188 189 190 191 192 193 | |
get_thread
¶get_thread(config)
Retrieve thread info synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
ThreadInfo | None
|
ThreadInfo | None: Thread information object or None. |
Source code in agentflow/checkpointer/base_checkpointer.py
424 425 426 427 428 429 430 431 432 433 434 | |
list_messages
¶list_messages(config, search=None, offset=None, limit=None)
List messages synchronously with optional filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
search
¶ |
str
|
Search string. |
None
|
offset
¶ |
int
|
Offset for pagination. |
None
|
limit
¶ |
int
|
Limit for pagination. |
None
|
Returns:
| Type | Description |
|---|---|
list[Message]
|
list[Message]: List of message objects. |
Source code in agentflow/checkpointer/base_checkpointer.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
list_threads
¶list_threads(config, search=None, offset=None, limit=None)
List threads synchronously with optional filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
search
¶ |
str
|
Search string. |
None
|
offset
¶ |
int
|
Offset for pagination. |
None
|
limit
¶ |
int
|
Limit for pagination. |
None
|
Returns:
| Type | Description |
|---|---|
list[ThreadInfo]
|
list[ThreadInfo]: List of thread information objects. |
Source code in agentflow/checkpointer/base_checkpointer.py
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 | |
put_messages
¶put_messages(config, messages, metadata=None)
Store messages synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
messages
¶ |
list[Message]
|
List of messages to store. |
required |
metadata
¶ |
dict
|
Additional metadata. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | |
put_state
¶put_state(config, state)
Store agent state synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
state
¶ |
StateT
|
State object to store. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
StateT |
StateT
|
The stored state object. |
Source code in agentflow/checkpointer/base_checkpointer.py
133 134 135 136 137 138 139 140 141 142 143 144 | |
put_state_cache
¶put_state_cache(config, state)
Store agent state in cache synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
state
¶ |
StateT
|
State object to cache. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
170 171 172 173 174 175 176 177 178 179 180 181 | |
put_thread
¶put_thread(config, thread_info)
Store thread info synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
thread_info
¶ |
ThreadInfo
|
Thread information object. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
411 412 413 414 415 416 417 418 419 420 421 422 | |
release
¶release()
Release resources synchronously.
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
472 473 474 475 476 477 478 479 | |
setup
¶setup()
Synchronous setup method for checkpointer.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Implementation-defined setup result. |
Source code in agentflow/checkpointer/base_checkpointer.py
41 42 43 44 45 46 47 48 | |
InMemoryCheckpointer
¶
Bases: BaseCheckpointer[StateT]
In-memory implementation of BaseCheckpointer.
Stores all agent state, messages, and thread info in memory using Python dictionaries. Data is lost when the process ends. Designed for testing and ephemeral use cases. Async-first design using asyncio locks for concurrent access.
Attributes:
| Name | Type | Description |
|---|---|---|
_states |
dict
|
Stores agent states by thread key. |
_state_cache |
dict
|
Stores cached agent states by thread key. |
_messages |
dict
|
Stores messages by thread key. |
_message_metadata |
dict
|
Stores message metadata by thread key. |
_threads |
dict
|
Stores thread info by thread key. |
_state_lock |
Lock
|
Lock for state operations. |
_messages_lock |
Lock
|
Lock for message operations. |
_threads_lock |
Lock
|
Lock for thread operations. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize all in-memory storage and locks. |
aclean_thread |
Clean/delete thread asynchronously. |
aclear_state |
Clear state asynchronously. |
adelete_message |
Delete a specific message asynchronously. |
aget_message |
Retrieve a specific message asynchronously. |
aget_state |
Retrieve state asynchronously. |
aget_state_cache |
Retrieve state cache asynchronously. |
aget_thread |
Retrieve thread info asynchronously. |
alist_messages |
List messages asynchronously with optional filtering. |
alist_threads |
List all threads asynchronously with optional filtering. |
aput_messages |
Store messages asynchronously. |
aput_state |
Store state asynchronously. |
aput_state_cache |
Store state cache asynchronously. |
aput_thread |
Store thread info asynchronously. |
arelease |
Release resources asynchronously. |
asetup |
Asynchronous setup method. No setup required for in-memory checkpointer. |
clean_thread |
Clean/delete thread synchronously. |
clear_state |
Clear state synchronously. |
delete_message |
Delete a specific message synchronously. |
get_message |
Retrieve a specific message synchronously. |
get_state |
Retrieve state synchronously. |
get_state_cache |
Retrieve state cache synchronously. |
get_thread |
Retrieve thread info synchronously. |
list_messages |
List messages synchronously with optional filtering. |
list_threads |
List all threads synchronously with optional filtering. |
put_messages |
Store messages synchronously. |
put_state |
Store state synchronously. |
put_state_cache |
Store state cache synchronously. |
put_thread |
Store thread info synchronously. |
release |
Release resources synchronously. |
setup |
Synchronous setup method. No setup required for in-memory checkpointer. |
Source code in agentflow/checkpointer/in_memory_checkpointer.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 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 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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 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 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 | |
Functions¶
__init__
¶__init__()
Initialize all in-memory storage and locks.
Source code in agentflow/checkpointer/in_memory_checkpointer.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
aclean_thread
async
¶aclean_thread(config)
Clean/delete thread asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if cleaned. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 | |
aclear_state
async
¶aclear_state(config)
Clear state asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if cleared. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
adelete_message
async
¶adelete_message(config, message_id)
Delete a specific message asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
message_id
¶ |
str | int
|
Message identifier. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if deleted. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If message not found. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 | |
aget_message
async
¶aget_message(config, message_id)
Retrieve a specific message asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
message_id
¶ |
str | int
|
Message identifier. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Message |
Message
|
Retrieved message object. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If message not found. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | |
aget_state
async
¶aget_state(config)
Retrieve state asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
StateT | None
|
StateT | None: Retrieved state or None. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
aget_state_cache
async
¶aget_state_cache(config)
Retrieve state cache asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
StateT | None
|
StateT | None: Cached state or None. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
aget_thread
async
¶aget_thread(config)
Retrieve thread info asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
ThreadInfo | None
|
ThreadInfo | None: Thread information object or None. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 | |
alist_messages
async
¶alist_messages(config, search=None, offset=None, limit=None)
List messages asynchronously with optional filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
search
¶ |
str
|
Search string. |
None
|
offset
¶ |
int
|
Offset for pagination. |
None
|
limit
¶ |
int
|
Limit for pagination. |
None
|
Returns:
| Type | Description |
|---|---|
list[Message]
|
list[Message]: List of message objects. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
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 | |
alist_threads
async
¶alist_threads(config, search=None, offset=None, limit=None)
List all threads asynchronously with optional filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
search
¶ |
str
|
Search string. |
None
|
offset
¶ |
int
|
Offset for pagination. |
None
|
limit
¶ |
int
|
Limit for pagination. |
None
|
Returns:
| Type | Description |
|---|---|
list[ThreadInfo]
|
list[ThreadInfo]: List of thread information objects. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 | |
aput_messages
async
¶aput_messages(config, messages, metadata=None)
Store messages asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
messages
¶ |
list[Message]
|
List of messages to store. |
required |
metadata
¶ |
dict
|
Additional metadata. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if stored. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
aput_state
async
¶aput_state(config, state)
Store state asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
state
¶ |
StateT
|
State object to store. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
StateT |
StateT
|
The stored state object. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
aput_state_cache
async
¶aput_state_cache(config, state)
Store state cache asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
state
¶ |
StateT
|
State object to cache. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
StateT |
StateT
|
The cached state object. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
aput_thread
async
¶aput_thread(config, thread_info)
Store thread info asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
thread_info
¶ |
ThreadInfo
|
Thread information object. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if stored. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 | |
arelease
async
¶arelease()
Release resources asynchronously.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if released. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 | |
asetup
async
¶asetup()
Asynchronous setup method. No setup required for in-memory checkpointer.
Source code in agentflow/checkpointer/in_memory_checkpointer.py
68 69 70 71 72 | |
clean_thread
¶clean_thread(config)
Clean/delete thread synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if cleaned. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 | |
clear_state
¶clear_state(config)
Clear state synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if cleared. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
delete_message
¶delete_message(config, message_id)
Delete a specific message synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
message_id
¶ |
str | int
|
Message identifier. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if deleted. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If message not found. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 | |
get_message
¶get_message(config, message_id)
Retrieve a specific message synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Message |
Message
|
Latest message object. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If no messages found. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | |
get_state
¶get_state(config)
Retrieve state synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
StateT | None
|
StateT | None: Retrieved state or None. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
get_state_cache
¶get_state_cache(config)
Retrieve state cache synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
StateT | None
|
StateT | None: Cached state or None. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
get_thread
¶get_thread(config)
Retrieve thread info synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
ThreadInfo | None
|
ThreadInfo | None: Thread information object or None. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 | |
list_messages
¶list_messages(config, search=None, offset=None, limit=None)
List messages synchronously with optional filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
search
¶ |
str
|
Search string. |
None
|
offset
¶ |
int
|
Offset for pagination. |
None
|
limit
¶ |
int
|
Limit for pagination. |
None
|
Returns:
| Type | Description |
|---|---|
list[Message]
|
list[Message]: List of message objects. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | |
list_threads
¶list_threads(config, search=None, offset=None, limit=None)
List all threads synchronously with optional filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
search
¶ |
str
|
Search string. |
None
|
offset
¶ |
int
|
Offset for pagination. |
None
|
limit
¶ |
int
|
Limit for pagination. |
None
|
Returns:
| Type | Description |
|---|---|
list[ThreadInfo]
|
list[ThreadInfo]: List of thread information objects. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 | |
put_messages
¶put_messages(config, messages, metadata=None)
Store messages synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
messages
¶ |
list[Message]
|
List of messages to store. |
required |
metadata
¶ |
dict
|
Additional metadata. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if stored. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 | |
put_state
¶put_state(config, state)
Store state synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
state
¶ |
StateT
|
State object to store. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
StateT |
StateT
|
The stored state object. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
put_state_cache
¶put_state_cache(config, state)
Store state cache synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
state
¶ |
StateT
|
State object to cache. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
StateT |
StateT
|
The cached state object. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |
put_thread
¶put_thread(config, thread_info)
Store thread info synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
thread_info
¶ |
ThreadInfo
|
Thread information object. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if stored. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 | |
release
¶release()
Release resources synchronously.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if released. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 | |
setup
¶setup()
Synchronous setup method. No setup required for in-memory checkpointer.
Source code in agentflow/checkpointer/in_memory_checkpointer.py
62 63 64 65 66 | |
PgCheckpointer
¶
Bases: BaseCheckpointer[StateT]
Implements a checkpointer using PostgreSQL and Redis for persistent and cached state management.
This class provides asynchronous and synchronous methods for storing, retrieving, and managing agent states, messages, and threads. PostgreSQL is used for durable storage, while Redis provides fast caching with TTL.
Features
- Async-first design with sync fallbacks
- Configurable ID types (string, int, bigint)
- Connection pooling for both PostgreSQL and Redis
- Proper error handling and resource management
- Schema migration support
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
PostgreSQL connection string. |
None
|
|
Any
|
Existing asyncpg Pool instance. |
None
|
|
dict
|
Configuration for new pg pool creation. |
None
|
|
str
|
Redis connection URL. |
None
|
|
Any
|
Existing Redis instance. |
None
|
|
Any
|
Existing Redis ConnectionPool. |
None
|
|
dict
|
Configuration for new redis pool creation. |
None
|
|
Additional configuration options: - user_id_type: Type for user_id fields ('string', 'int', 'bigint') - cache_ttl: Redis cache TTL in seconds - release_resources: Whether to release resources on cleanup |
{}
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If required dependencies are missing. |
ValueError
|
If required connection details are missing. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes PgCheckpointer with PostgreSQL and Redis connections. |
aclean_thread |
Clean/delete a thread and all associated data. |
aclear_state |
Clear state from PostgreSQL and Redis cache. |
adelete_message |
Delete a message by ID. |
aget_message |
Retrieve a single message by ID. |
aget_state |
Retrieve state from PostgreSQL. |
aget_state_cache |
Get state from Redis cache, fallback to PostgreSQL if miss. |
aget_thread |
Get thread information. |
alist_messages |
List messages for a thread with optional search and pagination. |
alist_threads |
List threads for a user with optional search and pagination. |
aput_messages |
Store messages in PostgreSQL. |
aput_state |
Store state in PostgreSQL and optionally cache in Redis. |
aput_state_cache |
Cache state in Redis with TTL. |
aput_thread |
Create or update thread information. |
arelease |
Clean up connections and resources. |
asetup |
Asynchronous setup method. Initializes database schema. |
clean_thread |
Clean/delete thread synchronously. |
clear_state |
Clear agent state synchronously. |
delete_message |
Delete a specific message synchronously. |
get_message |
Retrieve a specific message synchronously. |
get_state |
Retrieve agent state synchronously. |
get_state_cache |
Retrieve agent state from cache synchronously. |
get_thread |
Retrieve thread info synchronously. |
list_messages |
List messages synchronously with optional filtering. |
list_threads |
List threads synchronously with optional filtering. |
put_messages |
Store messages synchronously. |
put_state |
Store agent state synchronously. |
put_state_cache |
Store agent state in cache synchronously. |
put_thread |
Store thread info synchronously. |
release |
Release resources synchronously. |
setup |
Synchronous setup method for checkpointer. |
Attributes:
| Name | Type | Description |
|---|---|---|
cache_ttl |
|
|
id_type |
|
|
redis |
|
|
release_resources |
|
|
schema |
|
|
user_id_type |
|
Source code in agentflow/checkpointer/pg_checkpointer.py
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 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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 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 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 | |
Attributes¶
redis
instance-attribute
¶redis = _create_redis_pool(redis, redis_pool, redis_url, redis_pool_config or {})
Functions¶
__init__
¶__init__(postgres_dsn=None, pg_pool=None, pool_config=None, redis_url=None, redis=None, redis_pool=None, redis_pool_config=None, schema='public', **kwargs)
Initializes PgCheckpointer with PostgreSQL and Redis connections.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
postgres_dsn
¶ |
str
|
PostgreSQL connection string. |
None
|
pg_pool
¶ |
Any
|
Existing asyncpg Pool instance. |
None
|
pool_config
¶ |
dict
|
Configuration for new pg pool creation. |
None
|
redis_url
¶ |
str
|
Redis connection URL. |
None
|
redis
¶ |
Any
|
Existing Redis instance. |
None
|
redis_pool
¶ |
Any
|
Existing Redis ConnectionPool. |
None
|
redis_pool_config
¶ |
dict
|
Configuration for new redis pool creation. |
None
|
schema
¶ |
str
|
PostgreSQL schema name. Defaults to "public". |
'public'
|
**kwargs
¶ |
Additional configuration options. |
{}
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If required dependencies are missing. |
ValueError
|
If required connection details are missing. |
Source code in agentflow/checkpointer/pg_checkpointer.py
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 | |
aclean_thread
async
¶aclean_thread(config)
Clean/delete a thread and all associated data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: None |
Raises:
| Type | Description |
|---|---|
Exception
|
If cleaning fails. |
Source code in agentflow/checkpointer/pg_checkpointer.py
1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 | |
aclear_state
async
¶aclear_state(config)
Clear state from PostgreSQL and Redis cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
None |
Raises:
| Type | Description |
|---|---|
Exception
|
If clearing fails. |
Source code in agentflow/checkpointer/pg_checkpointer.py
782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 | |
adelete_message
async
¶adelete_message(config, message_id)
Delete a message by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
message_id
¶ |
str | int
|
Message identifier. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: None |
Raises:
| Type | Description |
|---|---|
Exception
|
If deletion fails. |
Source code in agentflow/checkpointer/pg_checkpointer.py
1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 | |
aget_message
async
¶aget_message(config, message_id)
Retrieve a single message by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
message_id
¶ |
str | int
|
Message identifier. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Message |
Message
|
Retrieved message object. |
Raises:
| Type | Description |
|---|---|
Exception
|
If retrieval fails. |
Source code in agentflow/checkpointer/pg_checkpointer.py
1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 | |
aget_state
async
¶aget_state(config)
Retrieve state from PostgreSQL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
StateT | None
|
StateT | None: Retrieved state or None. |
Raises:
| Type | Description |
|---|---|
Exception
|
If retrieval fails. |
Source code in agentflow/checkpointer/pg_checkpointer.py
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 | |
aget_state_cache
async
¶aget_state_cache(config)
Get state from Redis cache, fallback to PostgreSQL if miss.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
StateT | None
|
StateT | None: State object or None. |
Source code in agentflow/checkpointer/pg_checkpointer.py
852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 | |
aget_thread
async
¶aget_thread(config)
Get thread information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
ThreadInfo | None
|
ThreadInfo | None: Thread information object or None. |
Raises:
| Type | Description |
|---|---|
Exception
|
If retrieval fails. |
Source code in agentflow/checkpointer/pg_checkpointer.py
1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 | |
alist_messages
async
¶alist_messages(config, search=None, offset=None, limit=None)
List messages for a thread with optional search and pagination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
search
¶ |
str
|
Search string. |
None
|
offset
¶ |
int
|
Offset for pagination. |
None
|
limit
¶ |
int
|
Limit for pagination. |
None
|
Returns:
| Type | Description |
|---|---|
list[Message]
|
list[Message]: List of message objects. |
Raises:
| Type | Description |
|---|---|
Exception
|
If listing fails. |
Source code in agentflow/checkpointer/pg_checkpointer.py
1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 | |
alist_threads
async
¶alist_threads(config, search=None, offset=None, limit=None)
List threads for a user with optional search and pagination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
search
¶ |
str
|
Search string. |
None
|
offset
¶ |
int
|
Offset for pagination. |
None
|
limit
¶ |
int
|
Limit for pagination. |
None
|
Returns:
| Type | Description |
|---|---|
list[ThreadInfo]
|
list[ThreadInfo]: List of thread information objects. |
Raises:
| Type | Description |
|---|---|
Exception
|
If listing fails. |
Source code in agentflow/checkpointer/pg_checkpointer.py
1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 | |
aput_messages
async
¶aput_messages(config, messages, metadata=None)
Store messages in PostgreSQL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
messages
¶ |
list[Message]
|
List of messages to store. |
required |
metadata
¶ |
dict
|
Additional metadata. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
None |
Raises:
| Type | Description |
|---|---|
Exception
|
If storing fails. |
Source code in agentflow/checkpointer/pg_checkpointer.py
954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 | |
aput_state
async
¶aput_state(config, state)
Store state in PostgreSQL and optionally cache in Redis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
state
¶ |
StateT
|
State object to store. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
StateT |
StateT
|
The stored state object. |
Raises:
| Type | Description |
|---|---|
StorageError
|
If storing fails. |
Source code in agentflow/checkpointer/pg_checkpointer.py
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 | |
aput_state_cache
async
¶aput_state_cache(config, state)
Cache state in Redis with TTL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
state
¶ |
StateT
|
State object to cache. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: True if cached, None if failed. |
Source code in agentflow/checkpointer/pg_checkpointer.py
823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 | |
aput_thread
async
¶aput_thread(config, thread_info)
Create or update thread information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
thread_info
¶ |
ThreadInfo
|
Thread information object. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: None |
Raises:
| Type | Description |
|---|---|
Exception
|
If storing fails. |
Source code in agentflow/checkpointer/pg_checkpointer.py
1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 | |
arelease
async
¶arelease()
Clean up connections and resources.
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: None |
Source code in agentflow/checkpointer/pg_checkpointer.py
1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 | |
asetup
async
¶asetup()
Asynchronous setup method. Initializes database schema.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
True if setup completed. |
Source code in agentflow/checkpointer/pg_checkpointer.py
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 | |
clean_thread
¶clean_thread(config)
Clean/delete thread synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
457 458 459 460 461 462 463 464 465 466 467 | |
clear_state
¶clear_state(config)
Clear agent state synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
158 159 160 161 162 163 164 165 166 167 168 | |
delete_message
¶delete_message(config, message_id)
Delete a specific message synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
message_id
¶ |
str | int
|
Message identifier. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
323 324 325 326 327 328 329 330 331 332 333 334 | |
get_message
¶get_message(config, message_id)
Retrieve a specific message synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Message |
Message
|
Retrieved message object. |
Source code in agentflow/checkpointer/base_checkpointer.py
290 291 292 293 294 295 296 297 298 299 300 | |
get_state
¶get_state(config)
Retrieve agent state synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
StateT | None
|
StateT | None: Retrieved state or None. |
Source code in agentflow/checkpointer/base_checkpointer.py
146 147 148 149 150 151 152 153 154 155 156 | |
get_state_cache
¶get_state_cache(config)
Retrieve agent state from cache synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
StateT | None
|
StateT | None: Cached state or None. |
Source code in agentflow/checkpointer/base_checkpointer.py
183 184 185 186 187 188 189 190 191 192 193 | |
get_thread
¶get_thread(config)
Retrieve thread info synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
ThreadInfo | None
|
ThreadInfo | None: Thread information object or None. |
Source code in agentflow/checkpointer/base_checkpointer.py
424 425 426 427 428 429 430 431 432 433 434 | |
list_messages
¶list_messages(config, search=None, offset=None, limit=None)
List messages synchronously with optional filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
search
¶ |
str
|
Search string. |
None
|
offset
¶ |
int
|
Offset for pagination. |
None
|
limit
¶ |
int
|
Limit for pagination. |
None
|
Returns:
| Type | Description |
|---|---|
list[Message]
|
list[Message]: List of message objects. |
Source code in agentflow/checkpointer/base_checkpointer.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
list_threads
¶list_threads(config, search=None, offset=None, limit=None)
List threads synchronously with optional filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
search
¶ |
str
|
Search string. |
None
|
offset
¶ |
int
|
Offset for pagination. |
None
|
limit
¶ |
int
|
Limit for pagination. |
None
|
Returns:
| Type | Description |
|---|---|
list[ThreadInfo]
|
list[ThreadInfo]: List of thread information objects. |
Source code in agentflow/checkpointer/base_checkpointer.py
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 | |
put_messages
¶put_messages(config, messages, metadata=None)
Store messages synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
messages
¶ |
list[Message]
|
List of messages to store. |
required |
metadata
¶ |
dict
|
Additional metadata. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | |
put_state
¶put_state(config, state)
Store agent state synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
state
¶ |
StateT
|
State object to store. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
StateT |
StateT
|
The stored state object. |
Source code in agentflow/checkpointer/base_checkpointer.py
133 134 135 136 137 138 139 140 141 142 143 144 | |
put_state_cache
¶put_state_cache(config, state)
Store agent state in cache synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
state
¶ |
StateT
|
State object to cache. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
170 171 172 173 174 175 176 177 178 179 180 181 | |
put_thread
¶put_thread(config, thread_info)
Store thread info synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
thread_info
¶ |
ThreadInfo
|
Thread information object. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
411 412 413 414 415 416 417 418 419 420 421 422 | |
release
¶release()
Release resources synchronously.
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
472 473 474 475 476 477 478 479 | |
setup
¶setup()
Synchronous setup method for checkpointer.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Implementation-defined setup result. |
Source code in agentflow/checkpointer/base_checkpointer.py
41 42 43 44 45 46 47 48 | |
Modules¶
base_checkpointer
¶
Classes:
| Name | Description |
|---|---|
BaseCheckpointer |
Abstract base class for checkpointing agent state, messages, and threads. |
Attributes:
| Name | Type | Description |
|---|---|---|
StateT |
|
|
logger |
|
Attributes¶
Classes¶
BaseCheckpointer
¶
Bases: ABC
Abstract base class for checkpointing agent state, messages, and threads.
This class defines the contract for all checkpointer implementations, supporting both async and sync methods. Subclasses should implement async methods for optimal performance. Sync methods are provided for compatibility.
Usage
- Async-first design: subclasses should implement
async defmethods. - If a subclass provides only a sync
def, it will be executed in a worker thread automatically usingasyncio.run. - Callers always use the async APIs (
await cp.put_state(...), etc.).
Class Type Parameters:
| Name | Bound or Constraints | Description | Default |
|---|---|---|---|
StateT
|
AgentState
|
Type of agent state (must inherit from AgentState). |
required |
Methods:
| Name | Description |
|---|---|
aclean_thread |
Clean/delete thread asynchronously. |
aclear_state |
Clear agent state asynchronously. |
adelete_message |
Delete a specific message asynchronously. |
aget_message |
Retrieve a specific message asynchronously. |
aget_state |
Retrieve agent state asynchronously. |
aget_state_cache |
Retrieve agent state from cache asynchronously. |
aget_thread |
Retrieve thread info asynchronously. |
alist_messages |
List messages asynchronously with optional filtering. |
alist_threads |
List threads asynchronously with optional filtering. |
aput_messages |
Store messages asynchronously. |
aput_state |
Store agent state asynchronously. |
aput_state_cache |
Store agent state in cache asynchronously. |
aput_thread |
Store thread info asynchronously. |
arelease |
Release resources asynchronously. |
asetup |
Asynchronous setup method for checkpointer. |
clean_thread |
Clean/delete thread synchronously. |
clear_state |
Clear agent state synchronously. |
delete_message |
Delete a specific message synchronously. |
get_message |
Retrieve a specific message synchronously. |
get_state |
Retrieve agent state synchronously. |
get_state_cache |
Retrieve agent state from cache synchronously. |
get_thread |
Retrieve thread info synchronously. |
list_messages |
List messages synchronously with optional filtering. |
list_threads |
List threads synchronously with optional filtering. |
put_messages |
Store messages synchronously. |
put_state |
Store agent state synchronously. |
put_state_cache |
Store agent state in cache synchronously. |
put_thread |
Store thread info synchronously. |
release |
Release resources synchronously. |
setup |
Synchronous setup method for checkpointer. |
Source code in agentflow/checkpointer/base_checkpointer.py
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 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 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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 | |
aclean_thread
abstractmethod
async
¶aclean_thread(config)
Clean/delete thread asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
395 396 397 398 399 400 401 402 403 404 405 406 | |
aclear_state
abstractmethod
async
¶aclear_state(config)
Clear agent state asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
90 91 92 93 94 95 96 97 98 99 100 101 | |
adelete_message
abstractmethod
async
¶adelete_message(config, message_id)
Delete a specific message asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
message_id
¶ |
str | int
|
Message identifier. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
254 255 256 257 258 259 260 261 262 263 264 265 266 | |
aget_message
abstractmethod
async
¶aget_message(config, message_id)
Retrieve a specific message asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
message_id
¶ |
str | int
|
Message identifier. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Message |
Message
|
Retrieved message object. |
Source code in agentflow/checkpointer/base_checkpointer.py
218 219 220 221 222 223 224 225 226 227 228 229 230 | |
aget_state
abstractmethod
async
¶aget_state(config)
Retrieve agent state asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
StateT | None
|
StateT | None: Retrieved state or None. |
Source code in agentflow/checkpointer/base_checkpointer.py
77 78 79 80 81 82 83 84 85 86 87 88 | |
aget_state_cache
abstractmethod
async
¶aget_state_cache(config)
Retrieve agent state from cache asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
StateT | None
|
StateT | None: Cached state or None. |
Source code in agentflow/checkpointer/base_checkpointer.py
117 118 119 120 121 122 123 124 125 126 127 128 | |
aget_thread
abstractmethod
async
¶aget_thread(config)
Retrieve thread info asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
ThreadInfo | None
|
ThreadInfo | None: Thread information object or None. |
Source code in agentflow/checkpointer/base_checkpointer.py
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 | |
alist_messages
abstractmethod
async
¶alist_messages(config, search=None, offset=None, limit=None)
List messages asynchronously with optional filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
search
¶ |
str
|
Search string. |
None
|
offset
¶ |
int
|
Offset for pagination. |
None
|
limit
¶ |
int
|
Limit for pagination. |
None
|
Returns:
| Type | Description |
|---|---|
list[Message]
|
list[Message]: List of message objects. |
Source code in agentflow/checkpointer/base_checkpointer.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
alist_threads
abstractmethod
async
¶alist_threads(config, search=None, offset=None, limit=None)
List threads asynchronously with optional filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
search
¶ |
str
|
Search string. |
None
|
offset
¶ |
int
|
Offset for pagination. |
None
|
limit
¶ |
int
|
Limit for pagination. |
None
|
Returns:
| Type | Description |
|---|---|
list[ThreadInfo]
|
list[ThreadInfo]: List of thread information objects. |
Source code in agentflow/checkpointer/base_checkpointer.py
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | |
aput_messages
abstractmethod
async
¶aput_messages(config, messages, metadata=None)
Store messages asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
messages
¶ |
list[Message]
|
List of messages to store. |
required |
metadata
¶ |
dict
|
Additional metadata. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
aput_state
abstractmethod
async
¶aput_state(config, state)
Store agent state asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
state
¶ |
StateT
|
State object to store. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
StateT |
StateT
|
The stored state object. |
Source code in agentflow/checkpointer/base_checkpointer.py
63 64 65 66 67 68 69 70 71 72 73 74 75 | |
aput_state_cache
abstractmethod
async
¶aput_state_cache(config, state)
Store agent state in cache asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
state
¶ |
StateT
|
State object to cache. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
103 104 105 106 107 108 109 110 111 112 113 114 115 | |
aput_thread
abstractmethod
async
¶aput_thread(config, thread_info)
Store thread info asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
thread_info
¶ |
ThreadInfo
|
Thread information object. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | |
arelease
abstractmethod
async
¶arelease()
Release resources asynchronously.
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
481 482 483 484 485 486 487 488 489 | |
asetup
abstractmethod
async
¶asetup()
Asynchronous setup method for checkpointer.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Implementation-defined setup result. |
Source code in agentflow/checkpointer/base_checkpointer.py
50 51 52 53 54 55 56 57 58 | |
clean_thread
¶clean_thread(config)
Clean/delete thread synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
457 458 459 460 461 462 463 464 465 466 467 | |
clear_state
¶clear_state(config)
Clear agent state synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
158 159 160 161 162 163 164 165 166 167 168 | |
delete_message
¶delete_message(config, message_id)
Delete a specific message synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
message_id
¶ |
str | int
|
Message identifier. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
323 324 325 326 327 328 329 330 331 332 333 334 | |
get_message
¶get_message(config, message_id)
Retrieve a specific message synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Message |
Message
|
Retrieved message object. |
Source code in agentflow/checkpointer/base_checkpointer.py
290 291 292 293 294 295 296 297 298 299 300 | |
get_state
¶get_state(config)
Retrieve agent state synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
StateT | None
|
StateT | None: Retrieved state or None. |
Source code in agentflow/checkpointer/base_checkpointer.py
146 147 148 149 150 151 152 153 154 155 156 | |
get_state_cache
¶get_state_cache(config)
Retrieve agent state from cache synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
StateT | None
|
StateT | None: Cached state or None. |
Source code in agentflow/checkpointer/base_checkpointer.py
183 184 185 186 187 188 189 190 191 192 193 | |
get_thread
¶get_thread(config)
Retrieve thread info synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
ThreadInfo | None
|
ThreadInfo | None: Thread information object or None. |
Source code in agentflow/checkpointer/base_checkpointer.py
424 425 426 427 428 429 430 431 432 433 434 | |
list_messages
¶list_messages(config, search=None, offset=None, limit=None)
List messages synchronously with optional filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
search
¶ |
str
|
Search string. |
None
|
offset
¶ |
int
|
Offset for pagination. |
None
|
limit
¶ |
int
|
Limit for pagination. |
None
|
Returns:
| Type | Description |
|---|---|
list[Message]
|
list[Message]: List of message objects. |
Source code in agentflow/checkpointer/base_checkpointer.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
list_threads
¶list_threads(config, search=None, offset=None, limit=None)
List threads synchronously with optional filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
search
¶ |
str
|
Search string. |
None
|
offset
¶ |
int
|
Offset for pagination. |
None
|
limit
¶ |
int
|
Limit for pagination. |
None
|
Returns:
| Type | Description |
|---|---|
list[ThreadInfo]
|
list[ThreadInfo]: List of thread information objects. |
Source code in agentflow/checkpointer/base_checkpointer.py
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 | |
put_messages
¶put_messages(config, messages, metadata=None)
Store messages synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
messages
¶ |
list[Message]
|
List of messages to store. |
required |
metadata
¶ |
dict
|
Additional metadata. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | |
put_state
¶put_state(config, state)
Store agent state synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
state
¶ |
StateT
|
State object to store. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
StateT |
StateT
|
The stored state object. |
Source code in agentflow/checkpointer/base_checkpointer.py
133 134 135 136 137 138 139 140 141 142 143 144 | |
put_state_cache
¶put_state_cache(config, state)
Store agent state in cache synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
state
¶ |
StateT
|
State object to cache. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
170 171 172 173 174 175 176 177 178 179 180 181 | |
put_thread
¶put_thread(config, thread_info)
Store thread info synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
thread_info
¶ |
ThreadInfo
|
Thread information object. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
411 412 413 414 415 416 417 418 419 420 421 422 | |
release
¶release()
Release resources synchronously.
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
472 473 474 475 476 477 478 479 | |
setup
¶setup()
Synchronous setup method for checkpointer.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Implementation-defined setup result. |
Source code in agentflow/checkpointer/base_checkpointer.py
41 42 43 44 45 46 47 48 | |
Functions¶
in_memory_checkpointer
¶
Classes:
| Name | Description |
|---|---|
InMemoryCheckpointer |
In-memory implementation of BaseCheckpointer. |
Attributes:
| Name | Type | Description |
|---|---|---|
StateT |
|
|
logger |
|
Attributes¶
Classes¶
InMemoryCheckpointer
¶
Bases: BaseCheckpointer[StateT]
In-memory implementation of BaseCheckpointer.
Stores all agent state, messages, and thread info in memory using Python dictionaries. Data is lost when the process ends. Designed for testing and ephemeral use cases. Async-first design using asyncio locks for concurrent access.
Attributes:
| Name | Type | Description |
|---|---|---|
_states |
dict
|
Stores agent states by thread key. |
_state_cache |
dict
|
Stores cached agent states by thread key. |
_messages |
dict
|
Stores messages by thread key. |
_message_metadata |
dict
|
Stores message metadata by thread key. |
_threads |
dict
|
Stores thread info by thread key. |
_state_lock |
Lock
|
Lock for state operations. |
_messages_lock |
Lock
|
Lock for message operations. |
_threads_lock |
Lock
|
Lock for thread operations. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize all in-memory storage and locks. |
aclean_thread |
Clean/delete thread asynchronously. |
aclear_state |
Clear state asynchronously. |
adelete_message |
Delete a specific message asynchronously. |
aget_message |
Retrieve a specific message asynchronously. |
aget_state |
Retrieve state asynchronously. |
aget_state_cache |
Retrieve state cache asynchronously. |
aget_thread |
Retrieve thread info asynchronously. |
alist_messages |
List messages asynchronously with optional filtering. |
alist_threads |
List all threads asynchronously with optional filtering. |
aput_messages |
Store messages asynchronously. |
aput_state |
Store state asynchronously. |
aput_state_cache |
Store state cache asynchronously. |
aput_thread |
Store thread info asynchronously. |
arelease |
Release resources asynchronously. |
asetup |
Asynchronous setup method. No setup required for in-memory checkpointer. |
clean_thread |
Clean/delete thread synchronously. |
clear_state |
Clear state synchronously. |
delete_message |
Delete a specific message synchronously. |
get_message |
Retrieve a specific message synchronously. |
get_state |
Retrieve state synchronously. |
get_state_cache |
Retrieve state cache synchronously. |
get_thread |
Retrieve thread info synchronously. |
list_messages |
List messages synchronously with optional filtering. |
list_threads |
List all threads synchronously with optional filtering. |
put_messages |
Store messages synchronously. |
put_state |
Store state synchronously. |
put_state_cache |
Store state cache synchronously. |
put_thread |
Store thread info synchronously. |
release |
Release resources synchronously. |
setup |
Synchronous setup method. No setup required for in-memory checkpointer. |
Source code in agentflow/checkpointer/in_memory_checkpointer.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 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 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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 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 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 | |
__init__
¶__init__()
Initialize all in-memory storage and locks.
Source code in agentflow/checkpointer/in_memory_checkpointer.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
aclean_thread
async
¶aclean_thread(config)
Clean/delete thread asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if cleaned. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 | |
aclear_state
async
¶aclear_state(config)
Clear state asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if cleared. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
adelete_message
async
¶adelete_message(config, message_id)
Delete a specific message asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
message_id
¶ |
str | int
|
Message identifier. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if deleted. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If message not found. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 | |
aget_message
async
¶aget_message(config, message_id)
Retrieve a specific message asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
message_id
¶ |
str | int
|
Message identifier. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Message |
Message
|
Retrieved message object. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If message not found. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | |
aget_state
async
¶aget_state(config)
Retrieve state asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
StateT | None
|
StateT | None: Retrieved state or None. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
aget_state_cache
async
¶aget_state_cache(config)
Retrieve state cache asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
StateT | None
|
StateT | None: Cached state or None. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
aget_thread
async
¶aget_thread(config)
Retrieve thread info asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
ThreadInfo | None
|
ThreadInfo | None: Thread information object or None. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 | |
alist_messages
async
¶alist_messages(config, search=None, offset=None, limit=None)
List messages asynchronously with optional filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
search
¶ |
str
|
Search string. |
None
|
offset
¶ |
int
|
Offset for pagination. |
None
|
limit
¶ |
int
|
Limit for pagination. |
None
|
Returns:
| Type | Description |
|---|---|
list[Message]
|
list[Message]: List of message objects. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
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 | |
alist_threads
async
¶alist_threads(config, search=None, offset=None, limit=None)
List all threads asynchronously with optional filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
search
¶ |
str
|
Search string. |
None
|
offset
¶ |
int
|
Offset for pagination. |
None
|
limit
¶ |
int
|
Limit for pagination. |
None
|
Returns:
| Type | Description |
|---|---|
list[ThreadInfo]
|
list[ThreadInfo]: List of thread information objects. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 | |
aput_messages
async
¶aput_messages(config, messages, metadata=None)
Store messages asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
messages
¶ |
list[Message]
|
List of messages to store. |
required |
metadata
¶ |
dict
|
Additional metadata. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if stored. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
aput_state
async
¶aput_state(config, state)
Store state asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
state
¶ |
StateT
|
State object to store. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
StateT |
StateT
|
The stored state object. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
aput_state_cache
async
¶aput_state_cache(config, state)
Store state cache asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
state
¶ |
StateT
|
State object to cache. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
StateT |
StateT
|
The cached state object. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
aput_thread
async
¶aput_thread(config, thread_info)
Store thread info asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
thread_info
¶ |
ThreadInfo
|
Thread information object. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if stored. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 | |
arelease
async
¶arelease()
Release resources asynchronously.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if released. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 | |
asetup
async
¶asetup()
Asynchronous setup method. No setup required for in-memory checkpointer.
Source code in agentflow/checkpointer/in_memory_checkpointer.py
68 69 70 71 72 | |
clean_thread
¶clean_thread(config)
Clean/delete thread synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if cleaned. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 | |
clear_state
¶clear_state(config)
Clear state synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if cleared. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
delete_message
¶delete_message(config, message_id)
Delete a specific message synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
message_id
¶ |
str | int
|
Message identifier. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if deleted. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If message not found. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 | |
get_message
¶get_message(config, message_id)
Retrieve a specific message synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Message |
Message
|
Latest message object. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If no messages found. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | |
get_state
¶get_state(config)
Retrieve state synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
StateT | None
|
StateT | None: Retrieved state or None. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
get_state_cache
¶get_state_cache(config)
Retrieve state cache synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
StateT | None
|
StateT | None: Cached state or None. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
get_thread
¶get_thread(config)
Retrieve thread info synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
ThreadInfo | None
|
ThreadInfo | None: Thread information object or None. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 | |
list_messages
¶list_messages(config, search=None, offset=None, limit=None)
List messages synchronously with optional filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
search
¶ |
str
|
Search string. |
None
|
offset
¶ |
int
|
Offset for pagination. |
None
|
limit
¶ |
int
|
Limit for pagination. |
None
|
Returns:
| Type | Description |
|---|---|
list[Message]
|
list[Message]: List of message objects. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | |
list_threads
¶list_threads(config, search=None, offset=None, limit=None)
List all threads synchronously with optional filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
search
¶ |
str
|
Search string. |
None
|
offset
¶ |
int
|
Offset for pagination. |
None
|
limit
¶ |
int
|
Limit for pagination. |
None
|
Returns:
| Type | Description |
|---|---|
list[ThreadInfo]
|
list[ThreadInfo]: List of thread information objects. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 | |
put_messages
¶put_messages(config, messages, metadata=None)
Store messages synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
messages
¶ |
list[Message]
|
List of messages to store. |
required |
metadata
¶ |
dict
|
Additional metadata. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if stored. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 | |
put_state
¶put_state(config, state)
Store state synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
state
¶ |
StateT
|
State object to store. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
StateT |
StateT
|
The stored state object. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
put_state_cache
¶put_state_cache(config, state)
Store state cache synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
state
¶ |
StateT
|
State object to cache. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
StateT |
StateT
|
The cached state object. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |
put_thread
¶put_thread(config, thread_info)
Store thread info synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
thread_info
¶ |
ThreadInfo
|
Thread information object. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if stored. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 | |
release
¶release()
Release resources synchronously.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if released. |
Source code in agentflow/checkpointer/in_memory_checkpointer.py
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 | |
setup
¶setup()
Synchronous setup method. No setup required for in-memory checkpointer.
Source code in agentflow/checkpointer/in_memory_checkpointer.py
62 63 64 65 66 | |
pg_checkpointer
¶
Classes:
| Name | Description |
|---|---|
PgCheckpointer |
Implements a checkpointer using PostgreSQL and Redis for persistent and cached state management. |
Attributes:
| Name | Type | Description |
|---|---|---|
DEFAULT_CACHE_TTL |
|
|
HAS_ASYNCPG |
|
|
HAS_REDIS |
|
|
ID_TYPE_MAP |
|
|
StateT |
|
|
logger |
|
Attributes¶
ID_TYPE_MAP
module-attribute
¶ID_TYPE_MAP = {'string': 'VARCHAR(255)', 'int': 'SERIAL', 'bigint': 'BIGSERIAL'}
Classes¶
PgCheckpointer
¶
Bases: BaseCheckpointer[StateT]
Implements a checkpointer using PostgreSQL and Redis for persistent and cached state management.
This class provides asynchronous and synchronous methods for storing, retrieving, and managing agent states, messages, and threads. PostgreSQL is used for durable storage, while Redis provides fast caching with TTL.
Features
- Async-first design with sync fallbacks
- Configurable ID types (string, int, bigint)
- Connection pooling for both PostgreSQL and Redis
- Proper error handling and resource management
- Schema migration support
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
postgres_dsn
¶ |
str
|
PostgreSQL connection string. |
None
|
pg_pool
¶ |
Any
|
Existing asyncpg Pool instance. |
None
|
pool_config
¶ |
dict
|
Configuration for new pg pool creation. |
None
|
redis_url
¶ |
str
|
Redis connection URL. |
None
|
redis
¶ |
Any
|
Existing Redis instance. |
None
|
redis_pool
¶ |
Any
|
Existing Redis ConnectionPool. |
None
|
redis_pool_config
¶ |
dict
|
Configuration for new redis pool creation. |
None
|
**kwargs
¶ |
Additional configuration options: - user_id_type: Type for user_id fields ('string', 'int', 'bigint') - cache_ttl: Redis cache TTL in seconds - release_resources: Whether to release resources on cleanup |
{}
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If required dependencies are missing. |
ValueError
|
If required connection details are missing. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes PgCheckpointer with PostgreSQL and Redis connections. |
aclean_thread |
Clean/delete a thread and all associated data. |
aclear_state |
Clear state from PostgreSQL and Redis cache. |
adelete_message |
Delete a message by ID. |
aget_message |
Retrieve a single message by ID. |
aget_state |
Retrieve state from PostgreSQL. |
aget_state_cache |
Get state from Redis cache, fallback to PostgreSQL if miss. |
aget_thread |
Get thread information. |
alist_messages |
List messages for a thread with optional search and pagination. |
alist_threads |
List threads for a user with optional search and pagination. |
aput_messages |
Store messages in PostgreSQL. |
aput_state |
Store state in PostgreSQL and optionally cache in Redis. |
aput_state_cache |
Cache state in Redis with TTL. |
aput_thread |
Create or update thread information. |
arelease |
Clean up connections and resources. |
asetup |
Asynchronous setup method. Initializes database schema. |
clean_thread |
Clean/delete thread synchronously. |
clear_state |
Clear agent state synchronously. |
delete_message |
Delete a specific message synchronously. |
get_message |
Retrieve a specific message synchronously. |
get_state |
Retrieve agent state synchronously. |
get_state_cache |
Retrieve agent state from cache synchronously. |
get_thread |
Retrieve thread info synchronously. |
list_messages |
List messages synchronously with optional filtering. |
list_threads |
List threads synchronously with optional filtering. |
put_messages |
Store messages synchronously. |
put_state |
Store agent state synchronously. |
put_state_cache |
Store agent state in cache synchronously. |
put_thread |
Store thread info synchronously. |
release |
Release resources synchronously. |
setup |
Synchronous setup method for checkpointer. |
Attributes:
| Name | Type | Description |
|---|---|---|
cache_ttl |
|
|
id_type |
|
|
redis |
|
|
release_resources |
|
|
schema |
|
|
user_id_type |
|
Source code in agentflow/checkpointer/pg_checkpointer.py
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 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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 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 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 | |
redis
instance-attribute
¶redis = _create_redis_pool(redis, redis_pool, redis_url, redis_pool_config or {})
__init__
¶__init__(postgres_dsn=None, pg_pool=None, pool_config=None, redis_url=None, redis=None, redis_pool=None, redis_pool_config=None, schema='public', **kwargs)
Initializes PgCheckpointer with PostgreSQL and Redis connections.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
postgres_dsn
¶ |
str
|
PostgreSQL connection string. |
None
|
pg_pool
¶ |
Any
|
Existing asyncpg Pool instance. |
None
|
pool_config
¶ |
dict
|
Configuration for new pg pool creation. |
None
|
redis_url
¶ |
str
|
Redis connection URL. |
None
|
redis
¶ |
Any
|
Existing Redis instance. |
None
|
redis_pool
¶ |
Any
|
Existing Redis ConnectionPool. |
None
|
redis_pool_config
¶ |
dict
|
Configuration for new redis pool creation. |
None
|
schema
¶ |
str
|
PostgreSQL schema name. Defaults to "public". |
'public'
|
**kwargs
¶ |
Additional configuration options. |
{}
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If required dependencies are missing. |
ValueError
|
If required connection details are missing. |
Source code in agentflow/checkpointer/pg_checkpointer.py
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 | |
aclean_thread
async
¶aclean_thread(config)
Clean/delete a thread and all associated data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: None |
Raises:
| Type | Description |
|---|---|
Exception
|
If cleaning fails. |
Source code in agentflow/checkpointer/pg_checkpointer.py
1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 | |
aclear_state
async
¶aclear_state(config)
Clear state from PostgreSQL and Redis cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
None |
Raises:
| Type | Description |
|---|---|
Exception
|
If clearing fails. |
Source code in agentflow/checkpointer/pg_checkpointer.py
782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 | |
adelete_message
async
¶adelete_message(config, message_id)
Delete a message by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
message_id
¶ |
str | int
|
Message identifier. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: None |
Raises:
| Type | Description |
|---|---|
Exception
|
If deletion fails. |
Source code in agentflow/checkpointer/pg_checkpointer.py
1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 | |
aget_message
async
¶aget_message(config, message_id)
Retrieve a single message by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
message_id
¶ |
str | int
|
Message identifier. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Message |
Message
|
Retrieved message object. |
Raises:
| Type | Description |
|---|---|
Exception
|
If retrieval fails. |
Source code in agentflow/checkpointer/pg_checkpointer.py
1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 | |
aget_state
async
¶aget_state(config)
Retrieve state from PostgreSQL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
StateT | None
|
StateT | None: Retrieved state or None. |
Raises:
| Type | Description |
|---|---|
Exception
|
If retrieval fails. |
Source code in agentflow/checkpointer/pg_checkpointer.py
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 | |
aget_state_cache
async
¶aget_state_cache(config)
Get state from Redis cache, fallback to PostgreSQL if miss.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
StateT | None
|
StateT | None: State object or None. |
Source code in agentflow/checkpointer/pg_checkpointer.py
852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 | |
aget_thread
async
¶aget_thread(config)
Get thread information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
ThreadInfo | None
|
ThreadInfo | None: Thread information object or None. |
Raises:
| Type | Description |
|---|---|
Exception
|
If retrieval fails. |
Source code in agentflow/checkpointer/pg_checkpointer.py
1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 | |
alist_messages
async
¶alist_messages(config, search=None, offset=None, limit=None)
List messages for a thread with optional search and pagination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
search
¶ |
str
|
Search string. |
None
|
offset
¶ |
int
|
Offset for pagination. |
None
|
limit
¶ |
int
|
Limit for pagination. |
None
|
Returns:
| Type | Description |
|---|---|
list[Message]
|
list[Message]: List of message objects. |
Raises:
| Type | Description |
|---|---|
Exception
|
If listing fails. |
Source code in agentflow/checkpointer/pg_checkpointer.py
1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 | |
alist_threads
async
¶alist_threads(config, search=None, offset=None, limit=None)
List threads for a user with optional search and pagination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
search
¶ |
str
|
Search string. |
None
|
offset
¶ |
int
|
Offset for pagination. |
None
|
limit
¶ |
int
|
Limit for pagination. |
None
|
Returns:
| Type | Description |
|---|---|
list[ThreadInfo]
|
list[ThreadInfo]: List of thread information objects. |
Raises:
| Type | Description |
|---|---|
Exception
|
If listing fails. |
Source code in agentflow/checkpointer/pg_checkpointer.py
1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 | |
aput_messages
async
¶aput_messages(config, messages, metadata=None)
Store messages in PostgreSQL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
messages
¶ |
list[Message]
|
List of messages to store. |
required |
metadata
¶ |
dict
|
Additional metadata. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
None |
Raises:
| Type | Description |
|---|---|
Exception
|
If storing fails. |
Source code in agentflow/checkpointer/pg_checkpointer.py
954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 | |
aput_state
async
¶aput_state(config, state)
Store state in PostgreSQL and optionally cache in Redis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
state
¶ |
StateT
|
State object to store. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
StateT |
StateT
|
The stored state object. |
Raises:
| Type | Description |
|---|---|
StorageError
|
If storing fails. |
Source code in agentflow/checkpointer/pg_checkpointer.py
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 | |
aput_state_cache
async
¶aput_state_cache(config, state)
Cache state in Redis with TTL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
state
¶ |
StateT
|
State object to cache. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: True if cached, None if failed. |
Source code in agentflow/checkpointer/pg_checkpointer.py
823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 | |
aput_thread
async
¶aput_thread(config, thread_info)
Create or update thread information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
thread_info
¶ |
ThreadInfo
|
Thread information object. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: None |
Raises:
| Type | Description |
|---|---|
Exception
|
If storing fails. |
Source code in agentflow/checkpointer/pg_checkpointer.py
1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 | |
arelease
async
¶arelease()
Clean up connections and resources.
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: None |
Source code in agentflow/checkpointer/pg_checkpointer.py
1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 | |
asetup
async
¶asetup()
Asynchronous setup method. Initializes database schema.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
True if setup completed. |
Source code in agentflow/checkpointer/pg_checkpointer.py
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 | |
clean_thread
¶clean_thread(config)
Clean/delete thread synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
457 458 459 460 461 462 463 464 465 466 467 | |
clear_state
¶clear_state(config)
Clear agent state synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
158 159 160 161 162 163 164 165 166 167 168 | |
delete_message
¶delete_message(config, message_id)
Delete a specific message synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
message_id
¶ |
str | int
|
Message identifier. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
323 324 325 326 327 328 329 330 331 332 333 334 | |
get_message
¶get_message(config, message_id)
Retrieve a specific message synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Message |
Message
|
Retrieved message object. |
Source code in agentflow/checkpointer/base_checkpointer.py
290 291 292 293 294 295 296 297 298 299 300 | |
get_state
¶get_state(config)
Retrieve agent state synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
StateT | None
|
StateT | None: Retrieved state or None. |
Source code in agentflow/checkpointer/base_checkpointer.py
146 147 148 149 150 151 152 153 154 155 156 | |
get_state_cache
¶get_state_cache(config)
Retrieve agent state from cache synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
StateT | None
|
StateT | None: Cached state or None. |
Source code in agentflow/checkpointer/base_checkpointer.py
183 184 185 186 187 188 189 190 191 192 193 | |
get_thread
¶get_thread(config)
Retrieve thread info synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
Returns:
| Type | Description |
|---|---|
ThreadInfo | None
|
ThreadInfo | None: Thread information object or None. |
Source code in agentflow/checkpointer/base_checkpointer.py
424 425 426 427 428 429 430 431 432 433 434 | |
list_messages
¶list_messages(config, search=None, offset=None, limit=None)
List messages synchronously with optional filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
search
¶ |
str
|
Search string. |
None
|
offset
¶ |
int
|
Offset for pagination. |
None
|
limit
¶ |
int
|
Limit for pagination. |
None
|
Returns:
| Type | Description |
|---|---|
list[Message]
|
list[Message]: List of message objects. |
Source code in agentflow/checkpointer/base_checkpointer.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
list_threads
¶list_threads(config, search=None, offset=None, limit=None)
List threads synchronously with optional filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
search
¶ |
str
|
Search string. |
None
|
offset
¶ |
int
|
Offset for pagination. |
None
|
limit
¶ |
int
|
Limit for pagination. |
None
|
Returns:
| Type | Description |
|---|---|
list[ThreadInfo]
|
list[ThreadInfo]: List of thread information objects. |
Source code in agentflow/checkpointer/base_checkpointer.py
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 | |
put_messages
¶put_messages(config, messages, metadata=None)
Store messages synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
messages
¶ |
list[Message]
|
List of messages to store. |
required |
metadata
¶ |
dict
|
Additional metadata. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | |
put_state
¶put_state(config, state)
Store agent state synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
state
¶ |
StateT
|
State object to store. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
StateT |
StateT
|
The stored state object. |
Source code in agentflow/checkpointer/base_checkpointer.py
133 134 135 136 137 138 139 140 141 142 143 144 | |
put_state_cache
¶put_state_cache(config, state)
Store agent state in cache synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
state
¶ |
StateT
|
State object to cache. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
170 171 172 173 174 175 176 177 178 179 180 181 | |
put_thread
¶put_thread(config, thread_info)
Store thread info synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Configuration dictionary. |
required |
thread_info
¶ |
ThreadInfo
|
Thread information object. |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
411 412 413 414 415 416 417 418 419 420 421 422 | |
release
¶release()
Release resources synchronously.
Returns:
| Type | Description |
|---|---|
Any | None
|
Any | None: Implementation-defined result. |
Source code in agentflow/checkpointer/base_checkpointer.py
472 473 474 475 476 477 478 479 | |
setup
¶setup()
Synchronous setup method for checkpointer.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Implementation-defined setup result. |
Source code in agentflow/checkpointer/base_checkpointer.py
41 42 43 44 45 46 47 48 | |
Modules¶
exceptions
¶
Custom exception classes for graph operations in agentflowntflow.
This package provides
- GraphError: Base exception for graph-related errors.
- NodeError: Exception for node-specific errors.
- GraphRecursionError: Exception for recursion limit errors in graphs.
Modules:
| Name | Description |
|---|---|
graph_error |
|
node_error |
|
recursion_error |
|
storage_exceptions |
Structured exception taxonomy for persistence & runtime layers. |
Classes:
| Name | Description |
|---|---|
GraphError |
Base exception for graph-related errors. |
GraphRecursionError |
Exception raised when graph execution exceeds the recursion limit. |
NodeError |
Exception raised when a node encounters an error. |
Attributes¶
Classes¶
GraphError
¶
Bases: Exception
Base exception for graph-related errors.
This exception is raised when an error related to graph operations occurs.
Example
from agentflow.exceptions.graph_error import GraphError raise GraphError("Invalid graph structure")
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes a GraphError with the given message. |
Source code in agentflow/exceptions/graph_error.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | |
Functions¶
__init__
¶__init__(message)
Initializes a GraphError with the given message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
¶ |
str
|
Description of the error. |
required |
Source code in agentflow/exceptions/graph_error.py
18 19 20 21 22 23 24 25 26 | |
GraphRecursionError
¶
Bases: GraphError
Exception raised when graph execution exceeds the recursion limit.
This exception is used to indicate that a graph operation has recursed too deeply.
Example
from agentflow.exceptions.recursion_error import GraphRecursionError raise GraphRecursionError("Recursion limit exceeded in graph execution")
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes a GraphRecursionError with the given message. |
Source code in agentflow/exceptions/recursion_error.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | |
Functions¶
__init__
¶__init__(message)
Initializes a GraphRecursionError with the given message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
¶ |
str
|
Description of the recursion error. |
required |
Source code in agentflow/exceptions/recursion_error.py
20 21 22 23 24 25 26 27 28 | |
NodeError
¶
Bases: GraphError
Exception raised when a node encounters an error.
This exception is used for errors specific to nodes within a graph.
Example
from agentflow.exceptions.node_error import NodeError raise NodeError("Node failed to execute")
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes a NodeError with the given message. |
Source code in agentflow/exceptions/node_error.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | |
Functions¶
__init__
¶__init__(message)
Initializes a NodeError with the given message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
¶ |
str
|
Description of the node error. |
required |
Source code in agentflow/exceptions/node_error.py
20 21 22 23 24 25 26 27 28 | |
Modules¶
graph_error
¶
Classes:
| Name | Description |
|---|---|
GraphError |
Base exception for graph-related errors. |
Attributes:
| Name | Type | Description |
|---|---|---|
logger |
|
Attributes¶
Classes¶
GraphError
¶
Bases: Exception
Base exception for graph-related errors.
This exception is raised when an error related to graph operations occurs.
Example
from agentflow.exceptions.graph_error import GraphError raise GraphError("Invalid graph structure")
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes a GraphError with the given message. |
Source code in agentflow/exceptions/graph_error.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | |
__init__
¶__init__(message)
Initializes a GraphError with the given message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
¶ |
str
|
Description of the error. |
required |
Source code in agentflow/exceptions/graph_error.py
18 19 20 21 22 23 24 25 26 | |
node_error
¶
Classes:
| Name | Description |
|---|---|
NodeError |
Exception raised when a node encounters an error. |
Attributes:
| Name | Type | Description |
|---|---|---|
logger |
|
Attributes¶
Classes¶
NodeError
¶
Bases: GraphError
Exception raised when a node encounters an error.
This exception is used for errors specific to nodes within a graph.
Example
from agentflow.exceptions.node_error import NodeError raise NodeError("Node failed to execute")
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes a NodeError with the given message. |
Source code in agentflow/exceptions/node_error.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | |
__init__
¶__init__(message)
Initializes a NodeError with the given message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
¶ |
str
|
Description of the node error. |
required |
Source code in agentflow/exceptions/node_error.py
20 21 22 23 24 25 26 27 28 | |
recursion_error
¶
Classes:
| Name | Description |
|---|---|
GraphRecursionError |
Exception raised when graph execution exceeds the recursion limit. |
Attributes:
| Name | Type | Description |
|---|---|---|
logger |
|
Attributes¶
Classes¶
GraphRecursionError
¶
Bases: GraphError
Exception raised when graph execution exceeds the recursion limit.
This exception is used to indicate that a graph operation has recursed too deeply.
Example
from agentflow.exceptions.recursion_error import GraphRecursionError raise GraphRecursionError("Recursion limit exceeded in graph execution")
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes a GraphRecursionError with the given message. |
Source code in agentflow/exceptions/recursion_error.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | |
__init__
¶__init__(message)
Initializes a GraphRecursionError with the given message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
¶ |
str
|
Description of the recursion error. |
required |
Source code in agentflow/exceptions/recursion_error.py
20 21 22 23 24 25 26 27 28 | |
storage_exceptions
¶
Structured exception taxonomy for persistence & runtime layers.
These exceptions let higher-level orchestration decide retry / fail-fast logic
instead of relying on broad except Exception blocks.
Classes:
| Name | Description |
|---|---|
MetricsError |
Raised when metrics emission fails (should normally be swallowed/logged). |
SchemaVersionError |
Raised when schema version detection or migration application fails. |
SerializationError |
Raised when (de)serialization of state/messages fails deterministically. |
StorageError |
Base class for non-retryable storage layer errors. |
TransientStorageError |
Retryable storage error (connection drops, timeouts). |
Classes¶
MetricsError
¶
Bases: Exception
Raised when metrics emission fails (should normally be swallowed/logged).
Source code in agentflow/exceptions/storage_exceptions.py
26 27 | |
SchemaVersionError
¶
Bases: StorageError
Raised when schema version detection or migration application fails.
Source code in agentflow/exceptions/storage_exceptions.py
22 23 | |
SerializationError
¶
Bases: StorageError
Raised when (de)serialization of state/messages fails deterministically.
Source code in agentflow/exceptions/storage_exceptions.py
18 19 | |
StorageError
¶
Bases: Exception
Base class for non-retryable storage layer errors.
Source code in agentflow/exceptions/storage_exceptions.py
10 11 | |
TransientStorageError
¶
Bases: StorageError
Retryable storage error (connection drops, timeouts).
Source code in agentflow/exceptions/storage_exceptions.py
14 15 | |
graph
¶
Agentflow Graph Module - Core Workflow Engine.
This module provides the foundational components for building and executing agent workflows in TAF. It implements a graph-based execution model similar to LangGraph, where workflows are defined as directed graphs of interconnected nodes that process state and execute business logic.
Architecture Overview:¶
The graph module follows a builder pattern for workflow construction and provides a compiled execution environment for runtime performance. The core components work together to enable complex, stateful agent interactions:
- StateGraph: The primary builder class for constructing workflows
- Node: Executable units that encapsulate functions or tool operations
- Edge: Connections between nodes that define execution flow
- CompiledGraph: The executable runtime form of a constructed graph
- ToolNode: Specialized node for managing and executing tools
Core Components:¶
StateGraph
The main entry point for building workflows. Provides a fluent API for adding nodes, connecting them with edges, and configuring execution behavior. Supports both static and conditional routing between nodes.
Node
Represents an executable unit within the graph. Wraps functions or ToolNode instances and handles dependency injection, parameter mapping, and execution context. Supports both regular and streaming execution modes.
Edge
Defines connections between nodes, supporting both static (always followed) and conditional (state-dependent) routing. Enables complex branching logic and decision trees within workflows.
CompiledGraph
The executable runtime form created by compiling a StateGraph. Provides synchronous and asynchronous execution methods, state persistence, event publishing, and comprehensive error handling.
ToolNode
A specialized registry and executor for callable functions from various sources including local functions, MCP tools, Composio integrations, and LangChain tools. Supports automatic schema generation and unified tool execution.
Key Features:¶
- State Management: Persistent, typed state that flows between nodes
- Dependency Injection: Automatic injection of framework services
- Event Publishing: Comprehensive execution monitoring and debugging
- Streaming Support: Real-time incremental result processing
- Interrupts & Resume: Pauseable execution with checkpointing
- Tool Integration: Unified interface for various tool providers
- Type Safety: Generic typing for custom state classes
- Error Handling: Robust error recovery and callback mechanisms
Usage Example:¶
```python
from agentflow.graph import StateGraph, ToolNode
from agentflow.utils import START, END
# Define workflow functions
def process_input(state, config):
# Process user input
result = analyze_input(state.context[-1].content)
return [Message.text_message(f"Analysis: {result}")]
def generate_response(state, config):
# Generate final response
response = create_response(state.context)
return [Message.text_message(response)]
# Create tools
def search_tool(query: str) -> str:
return f"Search results for: {query}"
tools = ToolNode([search_tool])
# Build the graph
graph = StateGraph()
graph.add_node("process", process_input)
graph.add_node("search", tools)
graph.add_node("respond", generate_response)
# Define flow
graph.add_edge(START, "process")
graph.add_edge("process", "search")
graph.add_edge("search", "respond")
graph.add_edge("respond", END)
# Compile and execute
compiled = graph.compile()
result = compiled.invoke({"messages": [Message.text_message("Hello, world!")]})
# Cleanup
await compiled.aclose()
```
Integration Points:¶
The graph module integrates with other TAF components:
- State Module: Provides AgentState and context management
- Utils Module: Supplies constants, messages, and helper functions
- Checkpointer Module: Enables state persistence and recovery
- Publisher Module: Handles event publishing and monitoring
- Adapters Module: Connects with external tools and services
This architecture provides a flexible, extensible foundation for building sophisticated agent workflows while maintaining simplicity for common use cases.
Modules:
| Name | Description |
|---|---|
compiled_graph |
|
edge |
Graph edge representation and routing logic for TAF workflows. |
node |
Node execution and management for TAF graph workflows. |
state_graph |
|
tool_node |
ToolNode package. |
utils |
|
Classes:
| Name | Description |
|---|---|
CompiledGraph |
A fully compiled and executable graph ready for workflow execution. |
Edge |
Represents a connection between two nodes in a graph workflow. |
Node |
Represents a node in the graph workflow. |
StateGraph |
Main graph class for orchestrating multi-agent workflows. |
ToolNode |
A unified registry and executor for callable functions from various tool providers. |
Attributes¶
Classes¶
CompiledGraph
¶
A fully compiled and executable graph ready for workflow execution.
CompiledGraph represents the final executable form of a StateGraph after compilation. It encapsulates all the execution logic, handlers, and services needed to run agent workflows. The graph supports both synchronous and asynchronous execution with comprehensive state management, checkpointing, event publishing, and streaming capabilities.
This class is generic over state types to support custom AgentState subclasses, ensuring type safety throughout the execution process.
Key Features: - Synchronous and asynchronous execution methods - Real-time streaming with incremental results - State persistence and checkpointing - Interrupt and resume capabilities - Event publishing for monitoring and debugging - Background task management - Graceful error handling and recovery
Attributes:
| Name | Type | Description |
|---|---|---|
_state |
The initial/template state for graph executions. |
|
_invoke_handler |
InvokeHandler[StateT]
|
Handler for non-streaming graph execution. |
_stream_handler |
StreamHandler[StateT]
|
Handler for streaming graph execution. |
_checkpointer |
BaseCheckpointer[StateT] | None
|
Optional state persistence backend. |
_publisher |
BasePublisher | None
|
Optional event publishing backend. |
_store |
BaseStore | None
|
Optional data storage backend. |
_state_graph |
StateGraph[StateT]
|
Reference to the source StateGraph. |
_interrupt_before |
list[str]
|
Nodes where execution should pause before execution. |
_interrupt_after |
list[str]
|
Nodes where execution should pause after execution. |
_task_manager |
Manager for background async tasks. |
Example
# After building and compiling a StateGraph
compiled = graph.compile()
# Synchronous execution
result = compiled.invoke({"messages": [Message.text_message("Hello")]})
# Asynchronous execution with streaming
async for chunk in compiled.astream({"messages": [message]}):
print(f"Streamed: {chunk.content}")
# Graceful cleanup
await compiled.aclose()
Note
CompiledGraph instances should be properly closed using aclose() to release resources like database connections, background tasks, and event publishers.
Methods:
| Name | Description |
|---|---|
__init__ |
|
aclose |
Close the graph and release any resources. |
ainvoke |
Execute the graph asynchronously. |
astop |
Request the current graph execution to stop (async). |
astream |
Execute the graph asynchronously with streaming support. |
generate_graph |
Generate the graph representation. |
invoke |
Execute the graph synchronously and return the final results. |
stop |
Request the current graph execution to stop (sync helper). |
stream |
Execute the graph synchronously with streaming support. |
Source code in agentflow/graph/compiled_graph.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 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 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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 | |
Functions¶
__init__
¶__init__(state, checkpointer, publisher, store, state_graph, interrupt_before, interrupt_after, task_manager)
Source code in agentflow/graph/compiled_graph.py
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 | |
aclose
async
¶aclose()
Close the graph and release any resources.
Source code in agentflow/graph/compiled_graph.py
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | |
ainvoke
async
¶ainvoke(input_data, config=None, response_granularity=ResponseGranularity.LOW)
Execute the graph asynchronously.
Auto-detects whether to start fresh execution or resume from interrupted state based on the AgentState's execution metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_data
¶ |
dict[str, Any]
|
Input dict with 'messages' key (for new execution) or additional data for resuming |
required |
config
¶ |
dict[str, Any] | None
|
Configuration dictionary |
None
|
response_granularity
¶ |
ResponseGranularity
|
Response parsing granularity |
LOW
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Response dict based on granularity |
Source code in agentflow/graph/compiled_graph.py
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 | |
astop
async
¶astop(config)
Request the current graph execution to stop (async).
Contract: - Requires a valid thread_id in config - If no active thread or no checkpointer, returns not-running - If state exists and is running, set stop_requested flag in thread info
Source code in agentflow/graph/compiled_graph.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
astream
async
¶astream(input_data, config=None, response_granularity=ResponseGranularity.LOW)
Execute the graph asynchronously with streaming support.
Yields Message objects containing incremental responses. If nodes return streaming responses, yields them directly. If nodes return complete responses, simulates streaming by chunking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_data
¶ |
dict[str, Any]
|
Input dict |
required |
config
¶ |
dict[str, Any] | None
|
Configuration dictionary |
None
|
response_granularity
¶ |
ResponseGranularity
|
Response parsing granularity |
LOW
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[StreamChunk]
|
Message objects with incremental content |
Source code in agentflow/graph/compiled_graph.py
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | |
generate_graph
¶generate_graph()
Generate the graph representation.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary representing the graph structure. |
Source code in agentflow/graph/compiled_graph.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 | |
invoke
¶invoke(input_data, config=None, response_granularity=ResponseGranularity.LOW)
Execute the graph synchronously and return the final results.
Runs the complete graph workflow from start to finish, handling state management, node execution, and result formatting. This method automatically detects whether to start a fresh execution or resume from an interrupted state.
The execution is synchronous but internally uses async operations, making it suitable for use in non-async contexts while still benefiting from async capabilities for I/O operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_data
¶ |
dict[str, Any]
|
Input dictionary for graph execution. For new executions, should contain 'messages' key with list of initial messages. For resumed executions, can contain additional data to merge. |
required |
config
¶ |
dict[str, Any] | None
|
Optional configuration dictionary containing execution settings: - user_id: Identifier for the user/session - thread_id: Unique identifier for this execution thread - run_id: Unique identifier for this specific run - recursion_limit: Maximum steps before stopping (default: 25) |
None
|
response_granularity
¶ |
ResponseGranularity
|
Level of detail in the response: - LOW: Returns only messages (default) - PARTIAL: Returns context, summary, and messages - FULL: Returns complete state and messages |
LOW
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing execution results formatted according to the |
dict[str, Any]
|
specified granularity level. Always includes execution messages |
dict[str, Any]
|
and may include additional state information. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If input_data is invalid for new execution. |
GraphRecursionError
|
If execution exceeds recursion limit. |
Various exceptions
|
Depending on node execution failures. |
Example
# Basic execution
result = compiled.invoke({"messages": [Message.text_message("Process this data")]})
print(result["messages"]) # Final execution messages
# With configuration and full details
result = compiled.invoke(
input_data={"messages": [message]},
config={"user_id": "user123", "thread_id": "session456", "recursion_limit": 50},
response_granularity=ResponseGranularity.FULL,
)
print(result["state"]) # Complete final state
Note
This method uses asyncio.run() internally, so it should not be called from within an async context. Use ainvoke() instead for async execution.
Source code in agentflow/graph/compiled_graph.py
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 | |
stop
¶stop(config)
Request the current graph execution to stop (sync helper).
This sets a stop flag in the checkpointer's thread store keyed by thread_id. Handlers periodically check this flag and interrupt execution. Returns a small status dict.
Source code in agentflow/graph/compiled_graph.py
251 252 253 254 255 256 257 258 | |
stream
¶stream(input_data, config=None, response_granularity=ResponseGranularity.LOW)
Execute the graph synchronously with streaming support.
Yields Message objects containing incremental responses. If nodes return streaming responses, yields them directly. If nodes return complete responses, simulates streaming by chunking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_data
¶ |
dict[str, Any]
|
Input dict |
required |
config
¶ |
dict[str, Any] | None
|
Configuration dictionary |
None
|
response_granularity
¶ |
ResponseGranularity
|
Response parsing granularity |
LOW
|
Yields:
| Type | Description |
|---|---|
Generator[StreamChunk]
|
Message objects with incremental content |
Source code in agentflow/graph/compiled_graph.py
300 301 302 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 | |
Edge
¶
Represents a connection between two nodes in a graph workflow.
An Edge defines the relationship and routing logic between nodes, specifying how execution should flow from one node to another. Edges can be either static (unconditional) or conditional based on runtime state evaluation.
Edges support complex routing scenarios including: - Simple static connections between nodes - Conditional routing based on state evaluation - Dynamic routing with multiple possible destinations - Decision trees and branching logic
Attributes:
| Name | Type | Description |
|---|---|---|
from_node |
Name of the source node where execution originates. |
|
to_node |
Name of the destination node where execution continues. |
|
condition |
Optional callable that determines if this edge should be followed. If None, the edge is always followed (static edge). |
|
condition_result |
str | None
|
Optional value to match against condition result for mapped conditional edges. |
Example
# Static edge - always followed
static_edge = Edge("start", "process")
# Conditional edge - followed only if condition returns True
def needs_approval(state):
return state.data.get("requires_approval", False)
conditional_edge = Edge("process", "approval", condition=needs_approval)
# Mapped conditional edge - follows based on specific condition result
def get_priority(state):
return state.data.get("priority", "normal")
high_priority_edge = Edge("triage", "urgent", condition=get_priority)
high_priority_edge.condition_result = "high"
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize a new Edge with source, destination, and optional condition. |
Source code in agentflow/graph/edge.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 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 | |
Attributes¶
Functions¶
__init__
¶__init__(from_node, to_node, condition=None)
Initialize a new Edge with source, destination, and optional condition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_node
¶ |
str
|
Name of the source node. Must match a node name in the graph. |
required |
to_node
¶ |
str
|
Name of the destination node. Must match a node name in the graph or be a special constant like END. |
required |
condition
¶ |
Callable | None
|
Optional callable that takes an AgentState as argument and returns a value to determine if this edge should be followed. If None, this is a static edge that's always followed. |
None
|
Note
The condition function should be deterministic and side-effect free for predictable execution behavior. It receives the current AgentState and should return a boolean (for simple conditions) or a string/value (for mapped conditional routing).
Source code in agentflow/graph/edge.py
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 | |
Node
¶
Represents a node in the graph workflow.
A Node encapsulates a function or ToolNode that can be executed as part of a graph workflow. It handles dependency injection, parameter mapping, and execution context management.
The Node class supports both regular callable functions and ToolNode instances for handling tool-based operations. It automatically injects dependencies based on function signatures and provides legacy parameter support.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Unique identifier for the node within the graph. |
func |
Union[Callable, ToolNode]
|
The function or ToolNode to execute. |
Example
def my_function(state, config): ... return {"result": "processed"} node = Node("processor", my_function) result = await node.execute(state, config)
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize a new Node instance with function and dependencies. |
execute |
Execute the node function with comprehensive context and callback support. |
stream |
Execute the node function with streaming output support. |
Source code in agentflow/graph/node.py
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 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 | |
Attributes¶
Functions¶
__init__
¶__init__(name, func, publisher=Inject[BasePublisher])
Initialize a new Node instance with function and dependencies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
¶ |
str
|
Unique identifier for the node within the graph. This name is used for routing, logging, and referencing the node in graph configuration. |
required |
func
¶ |
Union[Callable, ToolNode]
|
The function or ToolNode to execute when this node is called. Functions should accept at least 'state' and 'config' parameters. ToolNode instances handle tool-based operations and provide their own execution logic. |
required |
publisher
¶ |
BasePublisher | None
|
Optional event publisher for execution monitoring. Injected via dependency injection if not explicitly provided. Used for publishing node execution events and status updates. |
Inject[BasePublisher]
|
Note
The function signature is automatically analyzed to determine required parameters and dependency injection points. Parameters matching injectable service names will be automatically provided by the framework during execution.
Source code in agentflow/graph/node.py
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 | |
execute
async
¶execute(config, state, callback_mgr=Inject[CallbackManager])
Execute the node function with comprehensive context and callback support.
Executes the node's function or ToolNode with full dependency injection, callback hook execution, and error handling. This method provides the complete execution environment including state access, configuration, and injected services.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict[str, Any]
|
Configuration dictionary containing execution context, user settings, thread identification, and runtime parameters. |
required |
state
¶ |
AgentState
|
Current AgentState providing workflow context, message history, and shared state information accessible to the node function. |
required |
callback_mgr
¶ |
CallbackManager
|
Callback manager for executing pre/post execution hooks. Injected via dependency injection if not explicitly provided. |
Inject[CallbackManager]
|
Returns:
| Type | Description |
|---|---|
dict[str, Any] | list[Message]
|
Either a dictionary containing updated state and execution results, |
dict[str, Any] | list[Message]
|
or a list of Message objects representing the node's output. |
dict[str, Any] | list[Message]
|
The return type depends on the node function's implementation. |
Example
# Node function that returns messages
def process_data(state, config):
result = process(state.data)
return [Message.text_message(f"Processed: {result}")]
node = Node("processor", process_data)
messages = await node.execute(config, state)
Note
The node function receives dependency-injected parameters based on its signature. Common injectable parameters include 'state', 'config', 'context_manager', 'publisher', and other framework services.
Source code in agentflow/graph/node.py
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 | |
stream
async
¶stream(config, state, callback_mgr=Inject[CallbackManager])
Execute the node function with streaming output support.
Similar to execute() but designed for streaming scenarios where the node function can produce incremental results. This method provides an async iterator interface over the node's outputs, allowing for real-time processing and response streaming.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict[str, Any]
|
Configuration dictionary with execution context and settings. |
required |
state
¶ |
AgentState
|
Current AgentState providing workflow context and shared state. |
required |
callback_mgr
¶ |
CallbackManager
|
Callback manager for pre/post execution hook handling. |
Inject[CallbackManager]
|
Yields:
| Type | Description |
|---|---|
AsyncIterable[dict[str, Any] | Message | StreamChunk]
|
Dictionary objects or Message instances representing incremental |
AsyncIterable[dict[str, Any] | Message | StreamChunk]
|
outputs from the node function. The exact type and frequency of |
AsyncIterable[dict[str, Any] | Message | StreamChunk]
|
yields depends on the node function's streaming implementation. |
Example
async def streaming_processor(state, config):
for item in large_dataset:
result = process_item(item)
yield Message.text_message(f"Processed item: {result}")
node = Node("stream_processor", streaming_processor)
async for output in node.stream(config, state):
print(f"Streamed: {output.content}")
Note
Not all node functions support streaming. For non-streaming functions, this method will yield a single result equivalent to calling execute(). The streaming capability is determined by the node function's implementation.
Source code in agentflow/graph/node.py
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 | |
StateGraph
¶
Main graph class for orchestrating multi-agent workflows.
This class provides the core functionality for building and managing stateful agent workflows. It is similar to LangGraph's StateGraph integration with support for dependency injection.
The graph is generic over state types to support custom AgentState subclasses, allowing for type-safe state management throughout the workflow execution.
Attributes:
| Name | Type | Description |
|---|---|---|
state |
StateT
|
The current state of the graph workflow. |
nodes |
dict[str, Node]
|
Collection of nodes in the graph. |
edges |
list[Edge]
|
Collection of edges connecting nodes. |
entry_point |
str | None
|
Name of the starting node for execution. |
context_manager |
BaseContextManager[StateT] | None
|
Optional context manager for handling cross-node state operations. |
dependency_container |
DependencyContainer
|
Container for managing dependencies that can be injected into node functions. |
compiled |
bool
|
Whether the graph has been compiled for execution. |
Example
graph = StateGraph() graph.add_node("process", process_function) graph.add_edge(START, "process") graph.add_edge("process", END) compiled = graph.compile() result = compiled.invoke({"input": "data"})
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize a new StateGraph instance. |
add_conditional_edges |
Add conditional routing between nodes based on runtime evaluation. |
add_edge |
Add a static edge between two nodes. |
add_node |
Add a node to the graph. |
compile |
Compile the graph for execution. |
set_entry_point |
Set the entry point for the graph. |
Source code in agentflow/graph/state_graph.py
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 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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | |
Attributes¶
Functions¶
__init__
¶__init__(state=None, context_manager=None, publisher=None, id_generator=DefaultIDGenerator(), container=None, thread_name_generator=None)
Initialize a new StateGraph instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
¶ |
StateT | None
|
Initial state for the graph. If None, a default AgentState will be created. |
None
|
context_manager
¶ |
BaseContextManager[StateT] | None
|
Optional context manager for handling cross-node state operations and advanced state management patterns. |
None
|
dependency_container
¶ |
Container for managing dependencies that can be injected into node functions. If None, a new empty container will be created. |
required | |
publisher
¶ |
BasePublisher | None
|
Publisher for emitting events during execution |
None
|
Note
START and END nodes are automatically added to the graph upon initialization and accept the full node signature including dependencies.
Example
Basic usage with default AgentState¶
graph = StateGraph()
With custom state¶
custom_state = MyCustomState() graph = StateGraph(custom_state)
Or using type hints for clarity¶
graph = StateGraphMyCustomState
Source code in agentflow/graph/state_graph.py
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 | |
add_conditional_edges
¶add_conditional_edges(from_node, condition, path_map=None)
Add conditional routing between nodes based on runtime evaluation.
Creates dynamic routing logic where the next node is determined by evaluating a condition function against the current state. This enables complex branching logic, decision trees, and adaptive workflow routing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_node
¶ |
str
|
Name of the source node where the condition is evaluated. |
required |
condition
¶ |
Callable
|
Callable function that takes the current AgentState and returns a value used for routing decisions. Should be deterministic and side-effect free. |
required |
path_map
¶ |
dict[str, str] | None
|
Optional dictionary mapping condition results to destination nodes. If provided, the condition's return value is looked up in this mapping. If None, the condition should return the destination node name directly. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
StateGraph |
StateGraph
|
The graph instance for method chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the condition function or path_map configuration is invalid. |
Example
# Direct routing - condition returns node name
def route_by_priority(state):
priority = state.data.get("priority", "normal")
return "urgent_handler" if priority == "high" else "normal_handler"
graph.add_conditional_edges("classifier", route_by_priority)
# Mapped routing - condition result mapped to nodes
def get_category(state):
return state.data.get("category", "default")
category_map = {
"finance": "finance_processor",
"legal": "legal_processor",
"default": "general_processor",
}
graph.add_conditional_edges("categorizer", get_category, category_map)
Note
The condition function receives the current AgentState and should return consistent results for the same state. If using path_map, ensure the condition's return values match the map keys exactly.
Source code in agentflow/graph/state_graph.py
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 | |
add_edge
¶add_edge(from_node, to_node)
Add a static edge between two nodes.
Creates a direct connection from one node to another. If the source node is START, the target node becomes the entry point for the graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_node
¶ |
str
|
Name of the source node. |
required |
to_node
¶ |
str
|
Name of the target node. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
StateGraph |
StateGraph
|
The graph instance for method chaining. |
Example
graph.add_edge("node1", "node2") graph.add_edge(START, "entry_node") # Sets entry point
Source code in agentflow/graph/state_graph.py
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 | |
add_node
¶add_node(name_or_func, func=None)
Add a node to the graph.
This method supports two calling patterns: 1. Pass a callable as the first argument (name inferred from function name) 2. Pass a name string and callable/ToolNode as separate arguments
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name_or_func
¶ |
str | Callable
|
Either the node name (str) or a callable function. If callable, the function name will be used as the node name. |
required |
func
¶ |
Union[Callable, ToolNode, None]
|
The function or ToolNode to execute. Required if name_or_func is a string, ignored if name_or_func is callable. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
StateGraph |
StateGraph
|
The graph instance for method chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If invalid arguments are provided. |
Example
Method 1: Function name inferred¶
graph.add_node(my_function)
Method 2: Explicit name and function¶
graph.add_node("process", my_function)
Source code in agentflow/graph/state_graph.py
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 | |
compile
¶compile(checkpointer=None, store=None, interrupt_before=None, interrupt_after=None, callback_manager=CallbackManager())
Compile the graph for execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checkpointer
¶ |
BaseCheckpointer[StateT] | None
|
Checkpointer for state persistence |
None
|
store
¶ |
BaseStore | None
|
Store for additional data |
None
|
debug
¶ |
Enable debug mode |
required | |
interrupt_before
¶ |
list[str] | None
|
List of node names to interrupt before execution |
None
|
interrupt_after
¶ |
list[str] | None
|
List of node names to interrupt after execution |
None
|
callback_manager
¶ |
CallbackManager
|
Callback manager for executing hooks |
CallbackManager()
|
Source code in agentflow/graph/state_graph.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 | |
set_entry_point
¶set_entry_point(node_name)
Set the entry point for the graph.
Source code in agentflow/graph/state_graph.py
381 382 383 384 385 386 | |
ToolNode
¶
Bases: SchemaMixin, LocalExecMixin, MCPMixin, ComposioMixin, LangChainMixin, KwargsResolverMixin
A unified registry and executor for callable functions from various tool providers.
ToolNode serves as the central hub for managing and executing tools from multiple sources: - Local Python functions - MCP (Model Context Protocol) tools - Composio adapter tools - LangChain tools
The class uses a mixin-based architecture to separate concerns and maintain clean integration with different tool providers. It provides both synchronous and asynchronous execution methods with comprehensive event publishing and error handling.
Attributes:
| Name | Type | Description |
|---|---|---|
_funcs |
dict[str, Callable]
|
Dictionary mapping function names to callable functions. |
_client |
Client | None
|
Optional MCP client for remote tool execution. |
_composio |
ComposioAdapter | None
|
Optional Composio adapter for external integrations. |
_langchain |
Any | None
|
Optional LangChain adapter for LangChain tools. |
mcp_tools |
list[str]
|
List of available MCP tool names. |
composio_tools |
list[str]
|
List of available Composio tool names. |
langchain_tools |
list[str]
|
List of available LangChain tool names. |
Example
# Define local tools
def weather_tool(location: str) -> str:
return f"Weather in {location}: Sunny, 25°C"
def calculator(a: int, b: int) -> int:
return a + b
# Create ToolNode with local functions
tools = ToolNode([weather_tool, calculator])
# Execute a tool
result = await tools.invoke(
name="weather_tool",
args={"location": "New York"},
tool_call_id="call_123",
config={"user_id": "user1"},
state=agent_state,
)
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize ToolNode with functions and optional tool adapters. |
all_tools |
Get all available tools from all configured providers. |
all_tools_sync |
Synchronously get all available tools from all configured providers. |
get_local_tool |
Generate OpenAI-compatible tool definitions for all registered local functions. |
invoke |
Execute a specific tool by name with the provided arguments. |
set_local_tool |
|
stream |
Execute a tool with streaming support, yielding incremental results. |
Source code in agentflow/graph/tool_node/base.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 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 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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 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 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 | |
Attributes¶
Functions¶
__init__
¶__init__(functions, client=None, composio_adapter=None, langchain_adapter=None)
Initialize ToolNode with functions and optional tool adapters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
functions
¶ |
Iterable[Callable]
|
Iterable of callable functions to register as tools. Each function
will be registered with its |
required |
client
¶ |
Client | None
|
Optional MCP (Model Context Protocol) client for remote tool access. Requires 'fastmcp' and 'mcp' packages to be installed. |
None
|
composio_adapter
¶ |
ComposioAdapter | None
|
Optional Composio adapter for external integrations and third-party API access. |
None
|
langchain_adapter
¶ |
Any | None
|
Optional LangChain adapter for accessing LangChain tools and integrations. |
None
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If MCP client is provided but required packages are not installed. |
TypeError
|
If any item in functions is not callable. |
Note
When using MCP client functionality, ensure you have installed the required
dependencies with: pip install 10xscale-agentflow[mcp]
Source code in agentflow/graph/tool_node/base.py
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 | |
all_tools
async
¶all_tools()
Get all available tools from all configured providers.
Retrieves and combines tool definitions from local functions, MCP client, Composio adapter, and LangChain adapter. Each tool definition includes the function schema with parameters and descriptions.
Returns:
| Type | Description |
|---|---|
list[dict]
|
List of tool definitions in OpenAI function calling format. Each dict |
list[dict]
|
contains 'type': 'function' and 'function' with name, description, |
list[dict]
|
and parameters schema. |
Example
tools = await tool_node.all_tools()
# Returns:
# [
# {
# "type": "function",
# "function": {
# "name": "weather_tool",
# "description": "Get weather information for a location",
# "parameters": {
# "type": "object",
# "properties": {
# "location": {"type": "string"}
# },
# "required": ["location"]
# }
# }
# }
# ]
Source code in agentflow/graph/tool_node/base.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
all_tools_sync
¶all_tools_sync()
Synchronously get all available tools from all configured providers.
This is a synchronous wrapper around the async all_tools() method. It uses asyncio.run() to handle async operations from MCP, Composio, and LangChain adapters.
Returns:
| Type | Description |
|---|---|
list[dict]
|
List of tool definitions in OpenAI function calling format. |
Note
Prefer using the async all_tools() method when possible, especially
in async contexts, to avoid potential event loop issues.
Source code in agentflow/graph/tool_node/base.py
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 | |
get_local_tool
¶get_local_tool()
Generate OpenAI-compatible tool definitions for all registered local functions.
Inspects all registered functions in _funcs and automatically generates tool schemas by analyzing function signatures, type annotations, and docstrings. Excludes injectable parameters that are provided by the framework.
Returns:
| Type | Description |
|---|---|
list[dict]
|
List of tool definitions in OpenAI function calling format. Each |
list[dict]
|
definition includes the function name, description (from docstring), |
list[dict]
|
and complete parameter schema with types and required fields. |
Example
For a function:
def calculate(a: int, b: int, operation: str = "add") -> int:
'''Perform arithmetic calculation.'''
return a + b if operation == "add" else a - b
Returns:
[
{
"type": "function",
"function": {
"name": "calculate",
"description": "Perform arithmetic calculation.",
"parameters": {
"type": "object",
"properties": {
"a": {"type": "integer"},
"b": {"type": "integer"},
"operation": {"type": "string", "default": "add"},
},
"required": ["a", "b"],
},
},
}
]
Note
Parameters listed in INJECTABLE_PARAMS (like 'state', 'config', 'tool_call_id') are automatically excluded from the generated schema as they are provided by the framework during execution.
Source code in agentflow/graph/tool_node/schema.py
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 | |
invoke
async
¶invoke(name, args, tool_call_id, config, state, callback_manager=Inject[CallbackManager])
Execute a specific tool by name with the provided arguments.
This method handles tool execution across all configured providers (local, MCP, Composio, LangChain) with comprehensive error handling, event publishing, and callback management.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
¶ |
str
|
The name of the tool to execute. |
required |
args
¶ |
dict
|
Dictionary of arguments to pass to the tool function. |
required |
tool_call_id
¶ |
str
|
Unique identifier for this tool execution, used for tracking and result correlation. |
required |
config
¶ |
dict[str, Any]
|
Configuration dictionary containing execution context and user-specific settings. |
required |
state
¶ |
AgentState
|
Current agent state for context-aware tool execution. |
required |
callback_manager
¶ |
CallbackManager
|
Manager for executing pre/post execution callbacks. Injected via dependency injection if not provided. |
Inject[CallbackManager]
|
Returns:
| Type | Description |
|---|---|
Message
|
Message object containing tool execution results, either successful |
Message
|
output or error information with appropriate status indicators. |
Example
result = await tool_node.invoke(
name="weather_tool",
args={"location": "Paris", "units": "metric"},
tool_call_id="call_abc123",
config={"user_id": "user1", "session_id": "session1"},
state=current_agent_state,
)
# result is a Message with tool execution results
print(result.content) # Tool output or error information
Note
The method publishes execution events throughout the process for monitoring and debugging purposes. Tool execution is routed based on tool provider precedence: MCP → Composio → LangChain → Local.
Source code in agentflow/graph/tool_node/base.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | |
set_local_tool
¶set_local_tool(tool_names)
Source code in agentflow/graph/tool_node/base.py
166 167 168 169 | |
stream
async
¶stream(name, args, tool_call_id, config, state, callback_manager=Inject[CallbackManager])
Execute a tool with streaming support, yielding incremental results.
Similar to invoke() but designed for tools that can provide streaming responses or when you want to process results as they become available. Currently, most tool providers return complete results, so this method typically yields a single Message with the full result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
¶ |
str
|
The name of the tool to execute. |
required |
args
¶ |
dict
|
Dictionary of arguments to pass to the tool function. |
required |
tool_call_id
¶ |
str
|
Unique identifier for this tool execution. |
required |
config
¶ |
dict[str, Any]
|
Configuration dictionary containing execution context. |
required |
state
¶ |
AgentState
|
Current agent state for context-aware tool execution. |
required |
callback_manager
¶ |
CallbackManager
|
Manager for executing pre/post execution callbacks. |
Inject[CallbackManager]
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[Message]
|
Message objects containing tool execution results or status updates. |
AsyncIterator[Message]
|
For most tools, this will yield a single complete result Message. |
Example
async for message in tool_node.stream(
name="data_processor",
args={"dataset": "large_data.csv"},
tool_call_id="call_stream123",
config={"user_id": "user1"},
state=current_state,
):
print(f"Received: {message.content}")
# Process each streamed result
Note
The streaming interface is designed for future expansion where tools may provide true streaming responses. Currently, it provides a consistent async iterator interface over tool results.
Source code in agentflow/graph/tool_node/base.py
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 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 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 | |
Modules¶
compiled_graph
¶
Classes:
| Name | Description |
|---|---|
CompiledGraph |
A fully compiled and executable graph ready for workflow execution. |
Attributes:
| Name | Type | Description |
|---|---|---|
StateT |
|
|
logger |
|
Attributes¶
Classes¶
CompiledGraph
¶A fully compiled and executable graph ready for workflow execution.
CompiledGraph represents the final executable form of a StateGraph after compilation. It encapsulates all the execution logic, handlers, and services needed to run agent workflows. The graph supports both synchronous and asynchronous execution with comprehensive state management, checkpointing, event publishing, and streaming capabilities.
This class is generic over state types to support custom AgentState subclasses, ensuring type safety throughout the execution process.
Key Features: - Synchronous and asynchronous execution methods - Real-time streaming with incremental results - State persistence and checkpointing - Interrupt and resume capabilities - Event publishing for monitoring and debugging - Background task management - Graceful error handling and recovery
Attributes:
| Name | Type | Description |
|---|---|---|
_state |
The initial/template state for graph executions. |
|
_invoke_handler |
InvokeHandler[StateT]
|
Handler for non-streaming graph execution. |
_stream_handler |
StreamHandler[StateT]
|
Handler for streaming graph execution. |
_checkpointer |
BaseCheckpointer[StateT] | None
|
Optional state persistence backend. |
_publisher |
BasePublisher | None
|
Optional event publishing backend. |
_store |
BaseStore | None
|
Optional data storage backend. |
_state_graph |
StateGraph[StateT]
|
Reference to the source StateGraph. |
_interrupt_before |
list[str]
|
Nodes where execution should pause before execution. |
_interrupt_after |
list[str]
|
Nodes where execution should pause after execution. |
_task_manager |
Manager for background async tasks. |
Example
# After building and compiling a StateGraph
compiled = graph.compile()
# Synchronous execution
result = compiled.invoke({"messages": [Message.text_message("Hello")]})
# Asynchronous execution with streaming
async for chunk in compiled.astream({"messages": [message]}):
print(f"Streamed: {chunk.content}")
# Graceful cleanup
await compiled.aclose()
Note
CompiledGraph instances should be properly closed using aclose() to release resources like database connections, background tasks, and event publishers.
Methods:
| Name | Description |
|---|---|
__init__ |
|
aclose |
Close the graph and release any resources. |
ainvoke |
Execute the graph asynchronously. |
astop |
Request the current graph execution to stop (async). |
astream |
Execute the graph asynchronously with streaming support. |
generate_graph |
Generate the graph representation. |
invoke |
Execute the graph synchronously and return the final results. |
stop |
Request the current graph execution to stop (sync helper). |
stream |
Execute the graph synchronously with streaming support. |
Source code in agentflow/graph/compiled_graph.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 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 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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 | |
__init__
¶__init__(state, checkpointer, publisher, store, state_graph, interrupt_before, interrupt_after, task_manager)
Source code in agentflow/graph/compiled_graph.py
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 | |
aclose
async
¶aclose()
Close the graph and release any resources.
Source code in agentflow/graph/compiled_graph.py
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | |
ainvoke
async
¶ainvoke(input_data, config=None, response_granularity=ResponseGranularity.LOW)
Execute the graph asynchronously.
Auto-detects whether to start fresh execution or resume from interrupted state based on the AgentState's execution metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_data
¶ |
dict[str, Any]
|
Input dict with 'messages' key (for new execution) or additional data for resuming |
required |
config
¶ |
dict[str, Any] | None
|
Configuration dictionary |
None
|
response_granularity
¶ |
ResponseGranularity
|
Response parsing granularity |
LOW
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Response dict based on granularity |
Source code in agentflow/graph/compiled_graph.py
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 | |
astop
async
¶astop(config)
Request the current graph execution to stop (async).
Contract: - Requires a valid thread_id in config - If no active thread or no checkpointer, returns not-running - If state exists and is running, set stop_requested flag in thread info
Source code in agentflow/graph/compiled_graph.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
astream
async
¶astream(input_data, config=None, response_granularity=ResponseGranularity.LOW)
Execute the graph asynchronously with streaming support.
Yields Message objects containing incremental responses. If nodes return streaming responses, yields them directly. If nodes return complete responses, simulates streaming by chunking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_data
¶ |
dict[str, Any]
|
Input dict |
required |
config
¶ |
dict[str, Any] | None
|
Configuration dictionary |
None
|
response_granularity
¶ |
ResponseGranularity
|
Response parsing granularity |
LOW
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[StreamChunk]
|
Message objects with incremental content |
Source code in agentflow/graph/compiled_graph.py
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | |
generate_graph
¶generate_graph()
Generate the graph representation.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary representing the graph structure. |
Source code in agentflow/graph/compiled_graph.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 | |
invoke
¶invoke(input_data, config=None, response_granularity=ResponseGranularity.LOW)
Execute the graph synchronously and return the final results.
Runs the complete graph workflow from start to finish, handling state management, node execution, and result formatting. This method automatically detects whether to start a fresh execution or resume from an interrupted state.
The execution is synchronous but internally uses async operations, making it suitable for use in non-async contexts while still benefiting from async capabilities for I/O operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_data
¶ |
dict[str, Any]
|
Input dictionary for graph execution. For new executions, should contain 'messages' key with list of initial messages. For resumed executions, can contain additional data to merge. |
required |
config
¶ |
dict[str, Any] | None
|
Optional configuration dictionary containing execution settings: - user_id: Identifier for the user/session - thread_id: Unique identifier for this execution thread - run_id: Unique identifier for this specific run - recursion_limit: Maximum steps before stopping (default: 25) |
None
|
response_granularity
¶ |
ResponseGranularity
|
Level of detail in the response: - LOW: Returns only messages (default) - PARTIAL: Returns context, summary, and messages - FULL: Returns complete state and messages |
LOW
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing execution results formatted according to the |
dict[str, Any]
|
specified granularity level. Always includes execution messages |
dict[str, Any]
|
and may include additional state information. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If input_data is invalid for new execution. |
GraphRecursionError
|
If execution exceeds recursion limit. |
Various exceptions
|
Depending on node execution failures. |
Example
# Basic execution
result = compiled.invoke({"messages": [Message.text_message("Process this data")]})
print(result["messages"]) # Final execution messages
# With configuration and full details
result = compiled.invoke(
input_data={"messages": [message]},
config={"user_id": "user123", "thread_id": "session456", "recursion_limit": 50},
response_granularity=ResponseGranularity.FULL,
)
print(result["state"]) # Complete final state
Note
This method uses asyncio.run() internally, so it should not be called from within an async context. Use ainvoke() instead for async execution.
Source code in agentflow/graph/compiled_graph.py
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 | |
stop
¶stop(config)
Request the current graph execution to stop (sync helper).
This sets a stop flag in the checkpointer's thread store keyed by thread_id. Handlers periodically check this flag and interrupt execution. Returns a small status dict.
Source code in agentflow/graph/compiled_graph.py
251 252 253 254 255 256 257 258 | |
stream
¶stream(input_data, config=None, response_granularity=ResponseGranularity.LOW)
Execute the graph synchronously with streaming support.
Yields Message objects containing incremental responses. If nodes return streaming responses, yields them directly. If nodes return complete responses, simulates streaming by chunking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_data
¶ |
dict[str, Any]
|
Input dict |
required |
config
¶ |
dict[str, Any] | None
|
Configuration dictionary |
None
|
response_granularity
¶ |
ResponseGranularity
|
Response parsing granularity |
LOW
|
Yields:
| Type | Description |
|---|---|
Generator[StreamChunk]
|
Message objects with incremental content |
Source code in agentflow/graph/compiled_graph.py
300 301 302 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 | |
edge
¶
Graph edge representation and routing logic for TAF workflows.
This module defines the Edge class, which represents connections between nodes in a TAF graph workflow. Edges can be either static (always followed) or conditional (followed only when certain conditions are met), enabling complex routing logic and decision-making within graph execution.
Edges are fundamental building blocks that define the flow of execution through a graph, determining which node should execute next based on the current state and any conditional logic.
Classes:
| Name | Description |
|---|---|
Edge |
Represents a connection between two nodes in a graph workflow. |
Attributes:
| Name | Type | Description |
|---|---|---|
logger |
|
Attributes¶
Classes¶
Edge
¶Represents a connection between two nodes in a graph workflow.
An Edge defines the relationship and routing logic between nodes, specifying how execution should flow from one node to another. Edges can be either static (unconditional) or conditional based on runtime state evaluation.
Edges support complex routing scenarios including: - Simple static connections between nodes - Conditional routing based on state evaluation - Dynamic routing with multiple possible destinations - Decision trees and branching logic
Attributes:
| Name | Type | Description |
|---|---|---|
from_node |
Name of the source node where execution originates. |
|
to_node |
Name of the destination node where execution continues. |
|
condition |
Optional callable that determines if this edge should be followed. If None, the edge is always followed (static edge). |
|
condition_result |
str | None
|
Optional value to match against condition result for mapped conditional edges. |
Example
# Static edge - always followed
static_edge = Edge("start", "process")
# Conditional edge - followed only if condition returns True
def needs_approval(state):
return state.data.get("requires_approval", False)
conditional_edge = Edge("process", "approval", condition=needs_approval)
# Mapped conditional edge - follows based on specific condition result
def get_priority(state):
return state.data.get("priority", "normal")
high_priority_edge = Edge("triage", "urgent", condition=get_priority)
high_priority_edge.condition_result = "high"
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize a new Edge with source, destination, and optional condition. |
Source code in agentflow/graph/edge.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 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 | |
__init__
¶__init__(from_node, to_node, condition=None)
Initialize a new Edge with source, destination, and optional condition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_node
¶ |
str
|
Name of the source node. Must match a node name in the graph. |
required |
to_node
¶ |
str
|
Name of the destination node. Must match a node name in the graph or be a special constant like END. |
required |
condition
¶ |
Callable | None
|
Optional callable that takes an AgentState as argument and returns a value to determine if this edge should be followed. If None, this is a static edge that's always followed. |
None
|
Note
The condition function should be deterministic and side-effect free for predictable execution behavior. It receives the current AgentState and should return a boolean (for simple conditions) or a string/value (for mapped conditional routing).
Source code in agentflow/graph/edge.py
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 | |
node
¶
Node execution and management for TAF graph workflows.
This module defines the Node class, which represents executable units within a TAF graph workflow. Nodes encapsulate functions or ToolNode instances that perform specific tasks, handle dependency injection, manage execution context, and support both synchronous and streaming execution modes.
Nodes are the fundamental building blocks of graph workflows, responsible for processing state, executing business logic, and producing outputs that drive the workflow forward. They integrate seamlessly with TAF's dependency injection system and callback management framework.
Classes:
| Name | Description |
|---|---|
Node |
Represents a node in the graph workflow. |
Attributes:
| Name | Type | Description |
|---|---|---|
logger |
|
Attributes¶
Classes¶
Node
¶Represents a node in the graph workflow.
A Node encapsulates a function or ToolNode that can be executed as part of a graph workflow. It handles dependency injection, parameter mapping, and execution context management.
The Node class supports both regular callable functions and ToolNode instances for handling tool-based operations. It automatically injects dependencies based on function signatures and provides legacy parameter support.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Unique identifier for the node within the graph. |
func |
Union[Callable, ToolNode]
|
The function or ToolNode to execute. |
Example
def my_function(state, config): ... return {"result": "processed"} node = Node("processor", my_function) result = await node.execute(state, config)
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize a new Node instance with function and dependencies. |
execute |
Execute the node function with comprehensive context and callback support. |
stream |
Execute the node function with streaming output support. |
Source code in agentflow/graph/node.py
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 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 | |
__init__
¶__init__(name, func, publisher=Inject[BasePublisher])
Initialize a new Node instance with function and dependencies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
¶ |
str
|
Unique identifier for the node within the graph. This name is used for routing, logging, and referencing the node in graph configuration. |
required |
func
¶ |
Union[Callable, ToolNode]
|
The function or ToolNode to execute when this node is called. Functions should accept at least 'state' and 'config' parameters. ToolNode instances handle tool-based operations and provide their own execution logic. |
required |
publisher
¶ |
BasePublisher | None
|
Optional event publisher for execution monitoring. Injected via dependency injection if not explicitly provided. Used for publishing node execution events and status updates. |
Inject[BasePublisher]
|
Note
The function signature is automatically analyzed to determine required parameters and dependency injection points. Parameters matching injectable service names will be automatically provided by the framework during execution.
Source code in agentflow/graph/node.py
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 | |
execute
async
¶execute(config, state, callback_mgr=Inject[CallbackManager])
Execute the node function with comprehensive context and callback support.
Executes the node's function or ToolNode with full dependency injection, callback hook execution, and error handling. This method provides the complete execution environment including state access, configuration, and injected services.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict[str, Any]
|
Configuration dictionary containing execution context, user settings, thread identification, and runtime parameters. |
required |
state
¶ |
AgentState
|
Current AgentState providing workflow context, message history, and shared state information accessible to the node function. |
required |
callback_mgr
¶ |
CallbackManager
|
Callback manager for executing pre/post execution hooks. Injected via dependency injection if not explicitly provided. |
Inject[CallbackManager]
|
Returns:
| Type | Description |
|---|---|
dict[str, Any] | list[Message]
|
Either a dictionary containing updated state and execution results, |
dict[str, Any] | list[Message]
|
or a list of Message objects representing the node's output. |
dict[str, Any] | list[Message]
|
The return type depends on the node function's implementation. |
Example
# Node function that returns messages
def process_data(state, config):
result = process(state.data)
return [Message.text_message(f"Processed: {result}")]
node = Node("processor", process_data)
messages = await node.execute(config, state)
Note
The node function receives dependency-injected parameters based on its signature. Common injectable parameters include 'state', 'config', 'context_manager', 'publisher', and other framework services.
Source code in agentflow/graph/node.py
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 | |
stream
async
¶stream(config, state, callback_mgr=Inject[CallbackManager])
Execute the node function with streaming output support.
Similar to execute() but designed for streaming scenarios where the node function can produce incremental results. This method provides an async iterator interface over the node's outputs, allowing for real-time processing and response streaming.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict[str, Any]
|
Configuration dictionary with execution context and settings. |
required |
state
¶ |
AgentState
|
Current AgentState providing workflow context and shared state. |
required |
callback_mgr
¶ |
CallbackManager
|
Callback manager for pre/post execution hook handling. |
Inject[CallbackManager]
|
Yields:
| Type | Description |
|---|---|
AsyncIterable[dict[str, Any] | Message | StreamChunk]
|
Dictionary objects or Message instances representing incremental |
AsyncIterable[dict[str, Any] | Message | StreamChunk]
|
outputs from the node function. The exact type and frequency of |
AsyncIterable[dict[str, Any] | Message | StreamChunk]
|
yields depends on the node function's streaming implementation. |
Example
async def streaming_processor(state, config):
for item in large_dataset:
result = process_item(item)
yield Message.text_message(f"Processed item: {result}")
node = Node("stream_processor", streaming_processor)
async for output in node.stream(config, state):
print(f"Streamed: {output.content}")
Note
Not all node functions support streaming. For non-streaming functions, this method will yield a single result equivalent to calling execute(). The streaming capability is determined by the node function's implementation.
Source code in agentflow/graph/node.py
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 | |
state_graph
¶
Classes:
| Name | Description |
|---|---|
StateGraph |
Main graph class for orchestrating multi-agent workflows. |
Attributes:
| Name | Type | Description |
|---|---|---|
StateT |
|
|
logger |
|
Attributes¶
Classes¶
StateGraph
¶Main graph class for orchestrating multi-agent workflows.
This class provides the core functionality for building and managing stateful agent workflows. It is similar to LangGraph's StateGraph integration with support for dependency injection.
The graph is generic over state types to support custom AgentState subclasses, allowing for type-safe state management throughout the workflow execution.
Attributes:
| Name | Type | Description |
|---|---|---|
state |
StateT
|
The current state of the graph workflow. |
nodes |
dict[str, Node]
|
Collection of nodes in the graph. |
edges |
list[Edge]
|
Collection of edges connecting nodes. |
entry_point |
str | None
|
Name of the starting node for execution. |
context_manager |
BaseContextManager[StateT] | None
|
Optional context manager for handling cross-node state operations. |
dependency_container |
DependencyContainer
|
Container for managing dependencies that can be injected into node functions. |
compiled |
bool
|
Whether the graph has been compiled for execution. |
Example
graph = StateGraph() graph.add_node("process", process_function) graph.add_edge(START, "process") graph.add_edge("process", END) compiled = graph.compile() result = compiled.invoke({"input": "data"})
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize a new StateGraph instance. |
add_conditional_edges |
Add conditional routing between nodes based on runtime evaluation. |
add_edge |
Add a static edge between two nodes. |
add_node |
Add a node to the graph. |
compile |
Compile the graph for execution. |
set_entry_point |
Set the entry point for the graph. |
Source code in agentflow/graph/state_graph.py
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 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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | |
__init__
¶__init__(state=None, context_manager=None, publisher=None, id_generator=DefaultIDGenerator(), container=None, thread_name_generator=None)
Initialize a new StateGraph instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
¶ |
StateT | None
|
Initial state for the graph. If None, a default AgentState will be created. |
None
|
context_manager
¶ |
BaseContextManager[StateT] | None
|
Optional context manager for handling cross-node state operations and advanced state management patterns. |
None
|
dependency_container
¶ |
Container for managing dependencies that can be injected into node functions. If None, a new empty container will be created. |
required | |
publisher
¶ |
BasePublisher | None
|
Publisher for emitting events during execution |
None
|
Note
START and END nodes are automatically added to the graph upon initialization and accept the full node signature including dependencies.
Example
Basic usage with default AgentState¶
graph = StateGraph()
With custom state¶
custom_state = MyCustomState() graph = StateGraph(custom_state)
Or using type hints for clarity¶
graph = StateGraphMyCustomState
Source code in agentflow/graph/state_graph.py
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 | |
add_conditional_edges
¶add_conditional_edges(from_node, condition, path_map=None)
Add conditional routing between nodes based on runtime evaluation.
Creates dynamic routing logic where the next node is determined by evaluating a condition function against the current state. This enables complex branching logic, decision trees, and adaptive workflow routing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_node
¶ |
str
|
Name of the source node where the condition is evaluated. |
required |
condition
¶ |
Callable
|
Callable function that takes the current AgentState and returns a value used for routing decisions. Should be deterministic and side-effect free. |
required |
path_map
¶ |
dict[str, str] | None
|
Optional dictionary mapping condition results to destination nodes. If provided, the condition's return value is looked up in this mapping. If None, the condition should return the destination node name directly. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
StateGraph |
StateGraph
|
The graph instance for method chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the condition function or path_map configuration is invalid. |
Example
# Direct routing - condition returns node name
def route_by_priority(state):
priority = state.data.get("priority", "normal")
return "urgent_handler" if priority == "high" else "normal_handler"
graph.add_conditional_edges("classifier", route_by_priority)
# Mapped routing - condition result mapped to nodes
def get_category(state):
return state.data.get("category", "default")
category_map = {
"finance": "finance_processor",
"legal": "legal_processor",
"default": "general_processor",
}
graph.add_conditional_edges("categorizer", get_category, category_map)
Note
The condition function receives the current AgentState and should return consistent results for the same state. If using path_map, ensure the condition's return values match the map keys exactly.
Source code in agentflow/graph/state_graph.py
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 | |
add_edge
¶add_edge(from_node, to_node)
Add a static edge between two nodes.
Creates a direct connection from one node to another. If the source node is START, the target node becomes the entry point for the graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_node
¶ |
str
|
Name of the source node. |
required |
to_node
¶ |
str
|
Name of the target node. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
StateGraph |
StateGraph
|
The graph instance for method chaining. |
Example
graph.add_edge("node1", "node2") graph.add_edge(START, "entry_node") # Sets entry point
Source code in agentflow/graph/state_graph.py
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 | |
add_node
¶add_node(name_or_func, func=None)
Add a node to the graph.
This method supports two calling patterns: 1. Pass a callable as the first argument (name inferred from function name) 2. Pass a name string and callable/ToolNode as separate arguments
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name_or_func
¶ |
str | Callable
|
Either the node name (str) or a callable function. If callable, the function name will be used as the node name. |
required |
func
¶ |
Union[Callable, ToolNode, None]
|
The function or ToolNode to execute. Required if name_or_func is a string, ignored if name_or_func is callable. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
StateGraph |
StateGraph
|
The graph instance for method chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If invalid arguments are provided. |
Example
Method 1: Function name inferred¶
graph.add_node(my_function)
Method 2: Explicit name and function¶
graph.add_node("process", my_function)
Source code in agentflow/graph/state_graph.py
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 | |
compile
¶compile(checkpointer=None, store=None, interrupt_before=None, interrupt_after=None, callback_manager=CallbackManager())
Compile the graph for execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checkpointer
¶ |
BaseCheckpointer[StateT] | None
|
Checkpointer for state persistence |
None
|
store
¶ |
BaseStore | None
|
Store for additional data |
None
|
debug
¶ |
Enable debug mode |
required | |
interrupt_before
¶ |
list[str] | None
|
List of node names to interrupt before execution |
None
|
interrupt_after
¶ |
list[str] | None
|
List of node names to interrupt after execution |
None
|
callback_manager
¶ |
CallbackManager
|
Callback manager for executing hooks |
CallbackManager()
|
Source code in agentflow/graph/state_graph.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 | |
set_entry_point
¶set_entry_point(node_name)
Set the entry point for the graph.
Source code in agentflow/graph/state_graph.py
381 382 383 384 385 386 | |
Functions¶
tool_node
¶
ToolNode package.
This package provides a modularized implementation of ToolNode. Public API:
- ToolNode
- HAS_FASTMCP, HAS_MCP
Backwards-compatible import path: from agentflow.graph.tool_node import ToolNode
Modules:
| Name | Description |
|---|---|
base |
Tool execution node for TAF graph workflows. |
constants |
Constants for ToolNode package. |
deps |
Dependency flags and optional imports for ToolNode. |
executors |
Executors for different tool providers and local functions. |
schema |
Schema utilities and local tool description building for ToolNode. |
Classes:
| Name | Description |
|---|---|
ToolNode |
A unified registry and executor for callable functions from various tool providers. |
Attributes:
| Name | Type | Description |
|---|---|---|
HAS_FASTMCP |
|
|
HAS_MCP |
|
Attributes¶
Classes¶
ToolNode
¶
Bases: SchemaMixin, LocalExecMixin, MCPMixin, ComposioMixin, LangChainMixin, KwargsResolverMixin
A unified registry and executor for callable functions from various tool providers.
ToolNode serves as the central hub for managing and executing tools from multiple sources: - Local Python functions - MCP (Model Context Protocol) tools - Composio adapter tools - LangChain tools
The class uses a mixin-based architecture to separate concerns and maintain clean integration with different tool providers. It provides both synchronous and asynchronous execution methods with comprehensive event publishing and error handling.
Attributes:
| Name | Type | Description |
|---|---|---|
_funcs |
dict[str, Callable]
|
Dictionary mapping function names to callable functions. |
_client |
Client | None
|
Optional MCP client for remote tool execution. |
_composio |
ComposioAdapter | None
|
Optional Composio adapter for external integrations. |
_langchain |
Any | None
|
Optional LangChain adapter for LangChain tools. |
mcp_tools |
list[str]
|
List of available MCP tool names. |
composio_tools |
list[str]
|
List of available Composio tool names. |
langchain_tools |
list[str]
|
List of available LangChain tool names. |
Example
# Define local tools
def weather_tool(location: str) -> str:
return f"Weather in {location}: Sunny, 25°C"
def calculator(a: int, b: int) -> int:
return a + b
# Create ToolNode with local functions
tools = ToolNode([weather_tool, calculator])
# Execute a tool
result = await tools.invoke(
name="weather_tool",
args={"location": "New York"},
tool_call_id="call_123",
config={"user_id": "user1"},
state=agent_state,
)
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize ToolNode with functions and optional tool adapters. |
all_tools |
Get all available tools from all configured providers. |
all_tools_sync |
Synchronously get all available tools from all configured providers. |
get_local_tool |
Generate OpenAI-compatible tool definitions for all registered local functions. |
invoke |
Execute a specific tool by name with the provided arguments. |
set_local_tool |
|
stream |
Execute a tool with streaming support, yielding incremental results. |
Source code in agentflow/graph/tool_node/base.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 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 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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 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 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 | |
__init__
¶__init__(functions, client=None, composio_adapter=None, langchain_adapter=None)
Initialize ToolNode with functions and optional tool adapters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
functions
¶ |
Iterable[Callable]
|
Iterable of callable functions to register as tools. Each function
will be registered with its |
required |
client
¶ |
Client | None
|
Optional MCP (Model Context Protocol) client for remote tool access. Requires 'fastmcp' and 'mcp' packages to be installed. |
None
|
composio_adapter
¶ |
ComposioAdapter | None
|
Optional Composio adapter for external integrations and third-party API access. |
None
|
langchain_adapter
¶ |
Any | None
|
Optional LangChain adapter for accessing LangChain tools and integrations. |
None
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If MCP client is provided but required packages are not installed. |
TypeError
|
If any item in functions is not callable. |
Note
When using MCP client functionality, ensure you have installed the required
dependencies with: pip install 10xscale-agentflow[mcp]
Source code in agentflow/graph/tool_node/base.py
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 | |
all_tools
async
¶all_tools()
Get all available tools from all configured providers.
Retrieves and combines tool definitions from local functions, MCP client, Composio adapter, and LangChain adapter. Each tool definition includes the function schema with parameters and descriptions.
Returns:
| Type | Description |
|---|---|
list[dict]
|
List of tool definitions in OpenAI function calling format. Each dict |
list[dict]
|
contains 'type': 'function' and 'function' with name, description, |
list[dict]
|
and parameters schema. |
Example
tools = await tool_node.all_tools()
# Returns:
# [
# {
# "type": "function",
# "function": {
# "name": "weather_tool",
# "description": "Get weather information for a location",
# "parameters": {
# "type": "object",
# "properties": {
# "location": {"type": "string"}
# },
# "required": ["location"]
# }
# }
# }
# ]
Source code in agentflow/graph/tool_node/base.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
all_tools_sync
¶all_tools_sync()
Synchronously get all available tools from all configured providers.
This is a synchronous wrapper around the async all_tools() method. It uses asyncio.run() to handle async operations from MCP, Composio, and LangChain adapters.
Returns:
| Type | Description |
|---|---|
list[dict]
|
List of tool definitions in OpenAI function calling format. |
Note
Prefer using the async all_tools() method when possible, especially
in async contexts, to avoid potential event loop issues.
Source code in agentflow/graph/tool_node/base.py
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 | |
get_local_tool
¶get_local_tool()
Generate OpenAI-compatible tool definitions for all registered local functions.
Inspects all registered functions in _funcs and automatically generates tool schemas by analyzing function signatures, type annotations, and docstrings. Excludes injectable parameters that are provided by the framework.
Returns:
| Type | Description |
|---|---|
list[dict]
|
List of tool definitions in OpenAI function calling format. Each |
list[dict]
|
definition includes the function name, description (from docstring), |
list[dict]
|
and complete parameter schema with types and required fields. |
Example
For a function:
def calculate(a: int, b: int, operation: str = "add") -> int:
'''Perform arithmetic calculation.'''
return a + b if operation == "add" else a - b
Returns:
[
{
"type": "function",
"function": {
"name": "calculate",
"description": "Perform arithmetic calculation.",
"parameters": {
"type": "object",
"properties": {
"a": {"type": "integer"},
"b": {"type": "integer"},
"operation": {"type": "string", "default": "add"},
},
"required": ["a", "b"],
},
},
}
]
Note
Parameters listed in INJECTABLE_PARAMS (like 'state', 'config', 'tool_call_id') are automatically excluded from the generated schema as they are provided by the framework during execution.
Source code in agentflow/graph/tool_node/schema.py
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 | |
invoke
async
¶invoke(name, args, tool_call_id, config, state, callback_manager=Inject[CallbackManager])
Execute a specific tool by name with the provided arguments.
This method handles tool execution across all configured providers (local, MCP, Composio, LangChain) with comprehensive error handling, event publishing, and callback management.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
¶ |
str
|
The name of the tool to execute. |
required |
args
¶ |
dict
|
Dictionary of arguments to pass to the tool function. |
required |
tool_call_id
¶ |
str
|
Unique identifier for this tool execution, used for tracking and result correlation. |
required |
config
¶ |
dict[str, Any]
|
Configuration dictionary containing execution context and user-specific settings. |
required |
state
¶ |
AgentState
|
Current agent state for context-aware tool execution. |
required |
callback_manager
¶ |
CallbackManager
|
Manager for executing pre/post execution callbacks. Injected via dependency injection if not provided. |
Inject[CallbackManager]
|
Returns:
| Type | Description |
|---|---|
Message
|
Message object containing tool execution results, either successful |
Message
|
output or error information with appropriate status indicators. |
Example
result = await tool_node.invoke(
name="weather_tool",
args={"location": "Paris", "units": "metric"},
tool_call_id="call_abc123",
config={"user_id": "user1", "session_id": "session1"},
state=current_agent_state,
)
# result is a Message with tool execution results
print(result.content) # Tool output or error information
Note
The method publishes execution events throughout the process for monitoring and debugging purposes. Tool execution is routed based on tool provider precedence: MCP → Composio → LangChain → Local.
Source code in agentflow/graph/tool_node/base.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | |
set_local_tool
¶set_local_tool(tool_names)
Source code in agentflow/graph/tool_node/base.py
166 167 168 169 | |
stream
async
¶stream(name, args, tool_call_id, config, state, callback_manager=Inject[CallbackManager])
Execute a tool with streaming support, yielding incremental results.
Similar to invoke() but designed for tools that can provide streaming responses or when you want to process results as they become available. Currently, most tool providers return complete results, so this method typically yields a single Message with the full result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
¶ |
str
|
The name of the tool to execute. |
required |
args
¶ |
dict
|
Dictionary of arguments to pass to the tool function. |
required |
tool_call_id
¶ |
str
|
Unique identifier for this tool execution. |
required |
config
¶ |
dict[str, Any]
|
Configuration dictionary containing execution context. |
required |
state
¶ |
AgentState
|
Current agent state for context-aware tool execution. |
required |
callback_manager
¶ |
CallbackManager
|
Manager for executing pre/post execution callbacks. |
Inject[CallbackManager]
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[Message]
|
Message objects containing tool execution results or status updates. |
AsyncIterator[Message]
|
For most tools, this will yield a single complete result Message. |
Example
async for message in tool_node.stream(
name="data_processor",
args={"dataset": "large_data.csv"},
tool_call_id="call_stream123",
config={"user_id": "user1"},
state=current_state,
):
print(f"Received: {message.content}")
# Process each streamed result
Note
The streaming interface is designed for future expansion where tools may provide true streaming responses. Currently, it provides a consistent async iterator interface over tool results.
Source code in agentflow/graph/tool_node/base.py
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 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 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 | |
Modules¶
base
¶Tool execution node for TAF graph workflows.
This module provides the ToolNode class, which serves as a unified registry and executor for callable functions from various sources including local functions, MCP (Model Context Protocol) tools, Composio adapters, and LangChain tools. The ToolNode is designed with a modular architecture using mixins to handle different tool providers.
The ToolNode maintains compatibility with TAF's dependency injection system and publishes execution events for monitoring and debugging purposes.
Typical usage example
def my_tool(query: str) -> str:
return f"Result for: {query}"
tools = ToolNode([my_tool])
result = await tools.invoke("my_tool", {"query": "test"}, "call_id", config, state)
Classes:
| Name | Description |
|---|---|
ToolNode |
A unified registry and executor for callable functions from various tool providers. |
Attributes:
| Name | Type | Description |
|---|---|---|
logger |
|
ToolNode
¶
Bases: SchemaMixin, LocalExecMixin, MCPMixin, ComposioMixin, LangChainMixin, KwargsResolverMixin
A unified registry and executor for callable functions from various tool providers.
ToolNode serves as the central hub for managing and executing tools from multiple sources: - Local Python functions - MCP (Model Context Protocol) tools - Composio adapter tools - LangChain tools
The class uses a mixin-based architecture to separate concerns and maintain clean integration with different tool providers. It provides both synchronous and asynchronous execution methods with comprehensive event publishing and error handling.
Attributes:
| Name | Type | Description |
|---|---|---|
_funcs |
dict[str, Callable]
|
Dictionary mapping function names to callable functions. |
_client |
Client | None
|
Optional MCP client for remote tool execution. |
_composio |
ComposioAdapter | None
|
Optional Composio adapter for external integrations. |
_langchain |
Any | None
|
Optional LangChain adapter for LangChain tools. |
mcp_tools |
list[str]
|
List of available MCP tool names. |
composio_tools |
list[str]
|
List of available Composio tool names. |
langchain_tools |
list[str]
|
List of available LangChain tool names. |
Example
# Define local tools
def weather_tool(location: str) -> str:
return f"Weather in {location}: Sunny, 25°C"
def calculator(a: int, b: int) -> int:
return a + b
# Create ToolNode with local functions
tools = ToolNode([weather_tool, calculator])
# Execute a tool
result = await tools.invoke(
name="weather_tool",
args={"location": "New York"},
tool_call_id="call_123",
config={"user_id": "user1"},
state=agent_state,
)
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize ToolNode with functions and optional tool adapters. |
all_tools |
Get all available tools from all configured providers. |
all_tools_sync |
Synchronously get all available tools from all configured providers. |
get_local_tool |
Generate OpenAI-compatible tool definitions for all registered local functions. |
invoke |
Execute a specific tool by name with the provided arguments. |
set_local_tool |
|
stream |
Execute a tool with streaming support, yielding incremental results. |
Source code in agentflow/graph/tool_node/base.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 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 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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 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 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 | |
__init__
¶__init__(functions, client=None, composio_adapter=None, langchain_adapter=None)
Initialize ToolNode with functions and optional tool adapters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
functions
¶ |
Iterable[Callable]
|
Iterable of callable functions to register as tools. Each function
will be registered with its |
required |
client
¶ |
Client | None
|
Optional MCP (Model Context Protocol) client for remote tool access. Requires 'fastmcp' and 'mcp' packages to be installed. |
None
|
composio_adapter
¶ |
ComposioAdapter | None
|
Optional Composio adapter for external integrations and third-party API access. |
None
|
langchain_adapter
¶ |
Any | None
|
Optional LangChain adapter for accessing LangChain tools and integrations. |
None
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If MCP client is provided but required packages are not installed. |
TypeError
|
If any item in functions is not callable. |
Note
When using MCP client functionality, ensure you have installed the required
dependencies with: pip install 10xscale-agentflow[mcp]
Source code in agentflow/graph/tool_node/base.py
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 | |
all_tools
async
¶all_tools()
Get all available tools from all configured providers.
Retrieves and combines tool definitions from local functions, MCP client, Composio adapter, and LangChain adapter. Each tool definition includes the function schema with parameters and descriptions.
Returns:
| Type | Description |
|---|---|
list[dict]
|
List of tool definitions in OpenAI function calling format. Each dict |
list[dict]
|
contains 'type': 'function' and 'function' with name, description, |
list[dict]
|
and parameters schema. |
Example
tools = await tool_node.all_tools()
# Returns:
# [
# {
# "type": "function",
# "function": {
# "name": "weather_tool",
# "description": "Get weather information for a location",
# "parameters": {
# "type": "object",
# "properties": {
# "location": {"type": "string"}
# },
# "required": ["location"]
# }
# }
# }
# ]
Source code in agentflow/graph/tool_node/base.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
all_tools_sync
¶all_tools_sync()
Synchronously get all available tools from all configured providers.
This is a synchronous wrapper around the async all_tools() method. It uses asyncio.run() to handle async operations from MCP, Composio, and LangChain adapters.
Returns:
| Type | Description |
|---|---|
list[dict]
|
List of tool definitions in OpenAI function calling format. |
Note
Prefer using the async all_tools() method when possible, especially
in async contexts, to avoid potential event loop issues.
Source code in agentflow/graph/tool_node/base.py
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 | |
get_local_tool
¶get_local_tool()
Generate OpenAI-compatible tool definitions for all registered local functions.
Inspects all registered functions in _funcs and automatically generates tool schemas by analyzing function signatures, type annotations, and docstrings. Excludes injectable parameters that are provided by the framework.
Returns:
| Type | Description |
|---|---|
list[dict]
|
List of tool definitions in OpenAI function calling format. Each |
list[dict]
|
definition includes the function name, description (from docstring), |
list[dict]
|
and complete parameter schema with types and required fields. |
Example
For a function:
def calculate(a: int, b: int, operation: str = "add") -> int:
'''Perform arithmetic calculation.'''
return a + b if operation == "add" else a - b
Returns:
[
{
"type": "function",
"function": {
"name": "calculate",
"description": "Perform arithmetic calculation.",
"parameters": {
"type": "object",
"properties": {
"a": {"type": "integer"},
"b": {"type": "integer"},
"operation": {"type": "string", "default": "add"},
},
"required": ["a", "b"],
},
},
}
]
Note
Parameters listed in INJECTABLE_PARAMS (like 'state', 'config', 'tool_call_id') are automatically excluded from the generated schema as they are provided by the framework during execution.
Source code in agentflow/graph/tool_node/schema.py
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 | |
invoke
async
¶invoke(name, args, tool_call_id, config, state, callback_manager=Inject[CallbackManager])
Execute a specific tool by name with the provided arguments.
This method handles tool execution across all configured providers (local, MCP, Composio, LangChain) with comprehensive error handling, event publishing, and callback management.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
¶ |
str
|
The name of the tool to execute. |
required |
args
¶ |
dict
|
Dictionary of arguments to pass to the tool function. |
required |
tool_call_id
¶ |
str
|
Unique identifier for this tool execution, used for tracking and result correlation. |
required |
config
¶ |
dict[str, Any]
|
Configuration dictionary containing execution context and user-specific settings. |
required |
state
¶ |
AgentState
|
Current agent state for context-aware tool execution. |
required |
callback_manager
¶ |
CallbackManager
|
Manager for executing pre/post execution callbacks. Injected via dependency injection if not provided. |
Inject[CallbackManager]
|
Returns:
| Type | Description |
|---|---|
Message
|
Message object containing tool execution results, either successful |
Message
|
output or error information with appropriate status indicators. |
Example
result = await tool_node.invoke(
name="weather_tool",
args={"location": "Paris", "units": "metric"},
tool_call_id="call_abc123",
config={"user_id": "user1", "session_id": "session1"},
state=current_agent_state,
)
# result is a Message with tool execution results
print(result.content) # Tool output or error information
Note
The method publishes execution events throughout the process for monitoring and debugging purposes. Tool execution is routed based on tool provider precedence: MCP → Composio → LangChain → Local.
Source code in agentflow/graph/tool_node/base.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | |
set_local_tool
¶set_local_tool(tool_names)
Source code in agentflow/graph/tool_node/base.py
166 167 168 169 | |
stream
async
¶stream(name, args, tool_call_id, config, state, callback_manager=Inject[CallbackManager])
Execute a tool with streaming support, yielding incremental results.
Similar to invoke() but designed for tools that can provide streaming responses or when you want to process results as they become available. Currently, most tool providers return complete results, so this method typically yields a single Message with the full result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
¶ |
str
|
The name of the tool to execute. |
required |
args
¶ |
dict
|
Dictionary of arguments to pass to the tool function. |
required |
tool_call_id
¶ |
str
|
Unique identifier for this tool execution. |
required |
config
¶ |
dict[str, Any]
|
Configuration dictionary containing execution context. |
required |
state
¶ |
AgentState
|
Current agent state for context-aware tool execution. |
required |
callback_manager
¶ |
CallbackManager
|
Manager for executing pre/post execution callbacks. |
Inject[CallbackManager]
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[Message]
|
Message objects containing tool execution results or status updates. |
AsyncIterator[Message]
|
For most tools, this will yield a single complete result Message. |
Example
async for message in tool_node.stream(
name="data_processor",
args={"dataset": "large_data.csv"},
tool_call_id="call_stream123",
config={"user_id": "user1"},
state=current_state,
):
print(f"Received: {message.content}")
# Process each streamed result
Note
The streaming interface is designed for future expansion where tools may provide true streaming responses. Currently, it provides a consistent async iterator interface over tool results.
Source code in agentflow/graph/tool_node/base.py
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 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 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 | |
constants
¶Constants for ToolNode package.
This module defines constants used throughout the ToolNode implementation, particularly parameter names that are automatically injected by the TAF framework during tool execution. These parameters are excluded from tool schema generation since they are provided by the execution context.
The constants are separated into their own module to avoid circular imports and maintain a clean public API.
Parameter names that are automatically injected during tool execution.
These parameters are provided by the TAF framework and should be excluded from tool schema generation. They represent execution context and framework services that are available to tool functions but not provided by the user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_call_id
¶ |
Unique identifier for the current tool execution. |
required | |
state
¶ |
Current AgentState instance for context-aware execution. |
required | |
config
¶ |
Configuration dictionary with execution settings. |
required | |
generated_id
¶ |
Framework-generated identifier for various purposes. |
required | |
context_manager
¶ |
BaseContextManager instance for cross-node operations. |
required | |
publisher
¶ |
BasePublisher instance for event publishing. |
required | |
checkpointer
¶ |
BaseCheckpointer instance for state persistence. |
required | |
store
¶ |
BaseStore instance for data storage operations. |
required |
Note
Tool functions can declare these parameters in their signatures to receive the corresponding services, but they should not be included in the tool schema since they're not user-provided arguments.
Attributes:
| Name | Type | Description |
|---|---|---|
INJECTABLE_PARAMS |
|
deps
¶Dependency flags and optional imports for ToolNode.
This module manages optional third-party dependencies for the ToolNode implementation, providing clean import handling and feature flags. It isolates optional imports to prevent ImportError cascades when optional dependencies are not installed.
The module handles two main optional dependency groups: 1. MCP (Model Context Protocol) support via 'fastmcp' and 'mcp' packages 2. Future extensibility for other optional tool providers
By centralizing optional imports here, other modules can safely import the flags and types without triggering ImportError exceptions, allowing graceful degradation when optional features are not available.
Typical usage
from .deps import HAS_FASTMCP, HAS_MCP, Client
if HAS_FASTMCP and HAS_MCP:
# Use MCP functionality
client = Client(...)
else:
# Graceful fallback or error message
client = None
FastMCP integration support.
Boolean flag indicating whether FastMCP is available.
True if 'fastmcp' package is installed and imports successfully.
FastMCP Client class for connecting to MCP servers.
None if FastMCP is not available.
Result type for MCP tool executions.
None if FastMCP is not available.
Attributes:
| Name | Type | Description |
|---|---|---|
HAS_FASTMCP |
|
|
HAS_MCP |
|
executors
¶Executors for different tool providers and local functions.
Classes:
| Name | Description |
|---|---|
ComposioMixin |
|
KwargsResolverMixin |
|
LangChainMixin |
|
LocalExecMixin |
|
MCPMixin |
|
Attributes:
| Name | Type | Description |
|---|---|---|
logger |
|
ComposioMixin
¶Attributes:
| Name | Type | Description |
|---|---|---|
composio_tools |
list[str]
|
|
Source code in agentflow/graph/tool_node/executors.py
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 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 196 197 198 199 200 | |
KwargsResolverMixin
¶Source code in agentflow/graph/tool_node/executors.py
838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 | |
LangChainMixin
¶Attributes:
| Name | Type | Description |
|---|---|---|
langchain_tools |
list[str]
|
|
Source code in agentflow/graph/tool_node/executors.py
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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 361 362 363 364 365 366 367 368 369 | |
LocalExecMixin
¶Source code in agentflow/graph/tool_node/executors.py
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 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 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 | |
MCPMixin
¶Attributes:
| Name | Type | Description |
|---|---|---|
mcp_tools |
list[str]
|
|
Source code in agentflow/graph/tool_node/executors.py
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 | |
schema
¶Schema utilities and local tool description building for ToolNode.
This module provides the SchemaMixin class which handles automatic schema generation for local Python functions, converting their type annotations and signatures into OpenAI-compatible function schemas. It supports various Python types including primitives, Optional types, List types, and Literal enums.
The schema generation process inspects function signatures and converts them to JSON Schema format suitable for use with language models and function calling APIs.
Classes:
| Name | Description |
|---|---|
SchemaMixin |
Mixin providing schema generation and local tool description building. |
SchemaMixin
¶Mixin providing schema generation and local tool description building.
This mixin provides functionality to automatically generate JSON Schema definitions from Python function signatures. It handles type annotation conversion, parameter analysis, and OpenAI-compatible function schema generation for local tools.
The mixin is designed to be used with ToolNode to automatically generate tool schemas without requiring manual schema definition for Python functions.
Attributes:
| Name | Type | Description |
|---|---|---|
_funcs |
dict[str, Callable]
|
Dictionary mapping function names to callable functions. This attribute is expected to be provided by the mixing class. |
Methods:
| Name | Description |
|---|---|
get_local_tool |
Generate OpenAI-compatible tool definitions for all registered local functions. |
Source code in agentflow/graph/tool_node/schema.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 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 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 | |
get_local_tool
¶get_local_tool()
Generate OpenAI-compatible tool definitions for all registered local functions.
Inspects all registered functions in _funcs and automatically generates tool schemas by analyzing function signatures, type annotations, and docstrings. Excludes injectable parameters that are provided by the framework.
Returns:
| Type | Description |
|---|---|
list[dict]
|
List of tool definitions in OpenAI function calling format. Each |
list[dict]
|
definition includes the function name, description (from docstring), |
list[dict]
|
and complete parameter schema with types and required fields. |
Example
For a function:
def calculate(a: int, b: int, operation: str = "add") -> int:
'''Perform arithmetic calculation.'''
return a + b if operation == "add" else a - b
Returns:
[
{
"type": "function",
"function": {
"name": "calculate",
"description": "Perform arithmetic calculation.",
"parameters": {
"type": "object",
"properties": {
"a": {"type": "integer"},
"b": {"type": "integer"},
"operation": {"type": "string", "default": "add"},
},
"required": ["a", "b"],
},
},
}
]
Note
Parameters listed in INJECTABLE_PARAMS (like 'state', 'config', 'tool_call_id') are automatically excluded from the generated schema as they are provided by the framework during execution.
Source code in agentflow/graph/tool_node/schema.py
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 | |
utils
¶
Modules:
| Name | Description |
|---|---|
handler_mixins |
Shared mixins for graph and node handler classes. |
invoke_handler |
|
invoke_node_handler |
InvokeNodeHandler utilities for TAF agent graph execution. |
stream_handler |
Streaming graph execution handler for TAF workflows. |
stream_node_handler |
Streaming node handler for TAF graph workflows. |
stream_utils |
Streaming utility functions for TAF graph workflows. |
utils |
Core utility functions for graph execution and state management. |
Modules¶
handler_mixins
¶Shared mixins for graph and node handler classes.
This module provides lightweight mixins that add common functionality to handler classes without changing their core runtime behavior. The mixins follow the composition pattern to keep responsibilities explicit and allow handlers to inherit only the capabilities they need.
The mixins provide structured logging, configuration management, and other cross-cutting concerns that are commonly needed across different handler types. By using mixins, the core handler logic remains focused while gaining these shared capabilities.
Typical usage
class MyHandler(BaseLoggingMixin, InterruptConfigMixin):
def __init__(self):
self._set_interrupts(["node1"], ["node2"])
self._log_start("Handler initialized")
Classes:
| Name | Description |
|---|---|
BaseLoggingMixin |
Provides structured logging helpers for handler classes. |
InterruptConfigMixin |
Manages interrupt configuration for graph-level execution handlers. |
BaseLoggingMixin
¶Provides structured logging helpers for handler classes.
This mixin adds consistent logging capabilities to handler classes without requiring them to manage logger instances directly. It automatically creates loggers based on the module name and provides convenience methods for common logging operations.
The mixin is designed to be lightweight and non-intrusive, adding only logging functionality without affecting the core behavior of the handler.
Attributes:
| Name | Type | Description |
|---|---|---|
_logger |
Logger
|
Cached logger instance for the handler class. |
Example
class MyHandler(BaseLoggingMixin):
def process(self):
self._log_start("Processing started")
try:
# Do work
self._log_debug("Work completed successfully")
except Exception as e:
self._log_error("Processing failed: %s", e)
Source code in agentflow/graph/utils/handler_mixins.py
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 | |
InterruptConfigMixin
¶Manages interrupt configuration for graph-level execution handlers.
This mixin provides functionality to store and manage interrupt points configuration for graph execution. Interrupts allow graph execution to be paused before or after specific nodes for debugging, human intervention, or checkpoint creation.
The mixin maintains separate lists for "before" and "after" interrupts, allowing fine-grained control over when graph execution should pause.
Attributes:
| Name | Type | Description |
|---|---|---|
interrupt_before |
list[str] | None
|
List of node names where execution should pause before node execution begins. |
interrupt_after |
list[str] | None
|
List of node names where execution should pause after node execution completes. |
Example
class GraphHandler(InterruptConfigMixin):
def __init__(self):
self._set_interrupts(
interrupt_before=["approval_node"], interrupt_after=["data_processing"]
)
Source code in agentflow/graph/utils/handler_mixins.py
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 | |
invoke_handler
¶Classes:
| Name | Description |
|---|---|
InvokeHandler |
|
Attributes:
| Name | Type | Description |
|---|---|---|
StateT |
|
|
logger |
|
InvokeHandler
¶
Bases: BaseLoggingMixin, InterruptConfigMixin
Methods:
| Name | Description |
|---|---|
__init__ |
|
invoke |
Execute the graph asynchronously with event publishing. |
Attributes:
| Name | Type | Description |
|---|---|---|
edges |
list[Edge]
|
|
interrupt_after |
|
|
interrupt_before |
|
|
nodes |
dict[str, Node]
|
|
Source code in agentflow/graph/utils/invoke_handler.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 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 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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 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 533 534 535 536 537 538 539 540 | |
__init__
¶__init__(nodes, edges, interrupt_before=None, interrupt_after=None)
Source code in agentflow/graph/utils/invoke_handler.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
invoke
async
¶invoke(input_data, config, default_state, response_granularity=ResponseGranularity.LOW)
Execute the graph asynchronously with event publishing.
Source code in agentflow/graph/utils/invoke_handler.py
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 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 533 534 535 536 537 538 539 540 | |
invoke_node_handler
¶InvokeNodeHandler utilities for TAF agent graph execution.
This module provides the InvokeNodeHandler class, which manages the invocation of node functions and tool nodes within the agent graph. It supports dependency injection, callback hooks, event publishing, and error recovery for both regular and tool-based nodes.
Classes:
| Name | Description |
|---|---|
InvokeNodeHandler |
Handles execution of node functions and tool nodes with DI and callbacks. |
Usage
handler = InvokeNodeHandler(name, func, publisher) result = await handler.invoke(config, state)
Attributes:
| Name | Type | Description |
|---|---|---|
logger |
|
InvokeNodeHandler
¶
Bases: BaseLoggingMixin
Handles invocation of node functions and tool nodes in the agent graph.
Supports dependency injection, callback hooks, event publishing, and error recovery.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
¶ |
str
|
Name of the node. |
required |
func
¶ |
Callable | ToolNode
|
The function or ToolNode to execute. |
required |
publisher
¶ |
BasePublisher
|
Event publisher for execution events. |
Inject[BasePublisher]
|
Methods:
| Name | Description |
|---|---|
__init__ |
|
clear_signature_cache |
Clear the function signature cache. Useful for testing or memory management. |
invoke |
Execute the node function or ToolNode with dependency injection and callback hooks. |
Attributes:
| Name | Type | Description |
|---|---|---|
func |
|
|
name |
|
|
publisher |
|
Source code in agentflow/graph/utils/invoke_node_handler.py
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 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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | |
__init__
¶__init__(name, func, publisher=Inject[BasePublisher])
Source code in agentflow/graph/utils/invoke_node_handler.py
64 65 66 67 68 69 70 71 72 | |
clear_signature_cache
classmethod
¶clear_signature_cache()
Clear the function signature cache. Useful for testing or memory management.
Source code in agentflow/graph/utils/invoke_node_handler.py
59 60 61 62 | |
invoke
async
¶invoke(config, state, callback_mgr=Inject[CallbackManager])
Execute the node function or ToolNode with dependency injection and callback hooks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict
|
Node configuration. |
required |
state
¶ |
AgentState
|
Current agent state. |
required |
callback_mgr
¶ |
CallbackManager
|
Callback manager for hooks. |
Inject[CallbackManager]
|
Returns:
| Type | Description |
|---|---|
dict[str, Any] | list[Message]
|
dict | list[Message]: Result of node execution (regular node or tool node). |
Raises:
| Type | Description |
|---|---|
NodeError
|
If execution fails or context is missing for tool nodes. |
Source code in agentflow/graph/utils/invoke_node_handler.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | |
stream_handler
¶Streaming graph execution handler for TAF workflows.
This module provides the StreamHandler class, which manages the execution of graph workflows with support for streaming output, interrupts, state persistence, and event publishing. It enables incremental result processing, pause/resume capabilities, and robust error handling for agent workflows that require real-time or chunked responses.
Classes:
| Name | Description |
|---|---|
StreamHandler |
Handles streaming execution for graph workflows in TAF. |
Attributes:
| Name | Type | Description |
|---|---|---|
StateT |
|
|
logger |
|
StreamHandler
¶
Bases: BaseLoggingMixin, InterruptConfigMixin
Handles streaming execution for graph workflows in TAF.
StreamHandler manages the execution of agent workflows as directed graphs, supporting streaming output, pause/resume via interrupts, state persistence, and event publishing for monitoring and debugging. It enables incremental result processing and robust error handling for complex agent workflows.
Attributes:
| Name | Type | Description |
|---|---|---|
nodes |
dict[str, Node]
|
Dictionary mapping node names to Node instances. |
edges |
list[Edge]
|
List of Edge instances defining graph connections and routing. |
interrupt_before |
List of node names where execution should pause before execution. |
|
interrupt_after |
List of node names where execution should pause after execution. |
Example
handler = StreamHandler(nodes, edges)
async for chunk in handler.stream(input_data, config, state):
print(chunk)
Methods:
| Name | Description |
|---|---|
__init__ |
|
stream |
Execute the graph asynchronously with streaming output. |
Source code in agentflow/graph/utils/stream_handler.py
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 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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 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 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 | |
__init__
¶__init__(nodes, edges, interrupt_before=None, interrupt_after=None)
Source code in agentflow/graph/utils/stream_handler.py
72 73 74 75 76 77 78 79 80 81 82 83 84 | |
stream
async
¶stream(input_data, config, default_state, response_granularity=ResponseGranularity.LOW)
Execute the graph asynchronously with streaming output.
Runs the graph workflow from start to finish, yielding incremental results as they become available. Automatically detects whether to start a fresh execution or resume from an interrupted state, supporting pause/resume and checkpointing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_data
¶ |
dict[str, Any]
|
Input dictionary for graph execution. For new executions, should contain 'messages' key with initial messages. For resumed executions, can contain additional data to merge. |
required |
config
¶ |
dict[str, Any]
|
Configuration dictionary containing execution settings and context. |
required |
default_state
¶ |
StateT
|
Initial or template AgentState for workflow execution. |
required |
response_granularity
¶ |
ResponseGranularity
|
Level of detail in the response (LOW, PARTIAL, FULL). |
LOW
|
Yields:
| Type | Description |
|---|---|
AsyncGenerator[StreamChunk]
|
Message objects representing incremental results from graph execution. |
AsyncGenerator[StreamChunk]
|
The exact type and frequency of yields depends on node implementations |
AsyncGenerator[StreamChunk]
|
and workflow configuration. |
Raises:
| Type | Description |
|---|---|
GraphRecursionError
|
If execution exceeds recursion limit. |
ValueError
|
If input_data is invalid for new execution. |
Various exceptions
|
Depending on node execution failures. |
Example
async for chunk in handler.stream(input_data, config, state):
print(chunk)
Source code in agentflow/graph/utils/stream_handler.py
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 | |
stream_node_handler
¶Streaming node handler for TAF graph workflows.
This module provides the StreamNodeHandler class, which manages the execution of graph nodes that support streaming output. It handles both regular function nodes and ToolNode instances, enabling incremental result processing, dependency injection, callback management, and event publishing.
StreamNodeHandler is a key component for enabling real-time, chunked, or incremental responses in agent workflows, supporting both synchronous and asynchronous execution patterns.
Classes:
| Name | Description |
|---|---|
StreamNodeHandler |
Handles streaming execution for graph nodes in TAF workflows. |
Attributes:
| Name | Type | Description |
|---|---|---|
logger |
|
StreamNodeHandler
¶
Bases: BaseLoggingMixin
Handles streaming execution for graph nodes in TAF workflows.
StreamNodeHandler manages the execution of nodes that can produce streaming output, including both regular function nodes and ToolNode instances. It supports dependency injection, callback management, event publishing, and incremental result processing.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
Unique identifier for the node within the graph. |
|
func |
The function or ToolNode to execute. Determines streaming behavior. |
Example
handler = StreamNodeHandler("process", process_function)
async for chunk in handler.stream(config, state):
print(chunk)
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize a new StreamNodeHandler instance. |
stream |
Execute the node function with streaming output and callback support. |
Source code in agentflow/graph/utils/stream_node_handler.py
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 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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 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 533 534 535 536 537 538 539 540 541 542 543 544 545 546 | |
__init__
¶__init__(name, func)
Initialize a new StreamNodeHandler instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
¶ |
str
|
Unique identifier for the node within the graph. |
required |
func
¶ |
Union[Callable, ToolNode]
|
The function or ToolNode to execute. Determines streaming behavior. |
required |
Source code in agentflow/graph/utils/stream_node_handler.py
64 65 66 67 68 69 70 71 72 73 74 75 76 | |
stream
async
¶stream(config, state, callback_mgr=Inject[CallbackManager])
Execute the node function with streaming output and callback support.
Handles both ToolNode and regular function nodes, yielding incremental results as they become available. Supports dependency injection, callback management, and event publishing for monitoring and debugging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict[str, Any]
|
Configuration dictionary containing execution context and settings. |
required |
state
¶ |
AgentState
|
Current AgentState providing workflow context and shared state. |
required |
callback_mgr
¶ |
CallbackManager
|
Callback manager for pre/post execution hook handling. |
Inject[CallbackManager]
|
Yields:
| Type | Description |
|---|---|
AsyncGenerator[dict[str, Any] | Message | StreamChunk]
|
Dictionary objects or Message instances representing incremental outputs |
AsyncGenerator[dict[str, Any] | Message | StreamChunk]
|
from the node function. The exact type and frequency of yields depends on |
AsyncGenerator[dict[str, Any] | Message | StreamChunk]
|
the node function's streaming implementation. |
Raises:
| Type | Description |
|---|---|
NodeError
|
If node execution fails or encounters an error. |
Example
async for chunk in handler.stream(config, state):
print(chunk)
Source code in agentflow/graph/utils/stream_node_handler.py
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 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 533 534 535 536 537 538 539 540 541 542 543 544 545 546 | |
stream_utils
¶Streaming utility functions for TAF graph workflows.
This module provides helper functions for determining whether a result from a node or tool execution should be treated as non-streaming (i.e., a complete result) or processed incrementally as a stream. These utilities are used throughout the graph execution engine to support both synchronous and streaming workflows.
Functions:
| Name | Description |
|---|---|
check_non_streaming |
Determine if a result should be treated as non-streaming. |
check_non_streaming
¶check_non_streaming(result)
Determine if a result should be treated as non-streaming.
Checks whether the given result is a complete, non-streaming output (such as a list, dict, string, Message, or AgentState) or if it should be processed incrementally as a stream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
¶ |
The result object returned from a node or tool execution. Can be any type. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the result is non-streaming and should be processed as a complete output; |
bool
|
False if the result should be handled as a stream. |
Example
check_non_streaming([Message.text_message("done")]) True check_non_streaming(Message.text_message("done")) True check_non_streaming({"choices": [...]}) True check_non_streaming("some text") True
Source code in agentflow/graph/utils/stream_utils.py
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 40 41 42 43 44 45 46 47 | |
utils
¶Core utility functions for graph execution and state management.
This module provides essential utilities for TAF graph execution, including state management, message processing, response formatting, and execution flow control. These functions handle the low-level operations that support graph workflow execution.
The utilities in this module are designed to work with TAF's dependency injection system and provide consistent interfaces for common operations across different execution contexts.
Key functionality areas: - State loading, creation, and synchronization - Message processing and deduplication - Response formatting based on granularity levels - Node execution result processing - Interrupt handling and execution flow control
Functions:
| Name | Description |
|---|---|
call_realtime_sync |
Call the realtime state sync hook if provided. |
check_and_handle_interrupt |
Check for interrupts and save state if needed. Returns True if interrupted. |
get_next_node |
Get the next node to execute based on edges. |
load_or_create_state |
Load existing state from checkpointer or create new state. |
parse_response |
Parse and format execution response based on specified granularity level. |
process_node_result |
Processes the result from a node execution, updating the agent state, message list, |
reload_state |
Load existing state from checkpointer or create new state. |
sync_data |
Sync the current state and messages to the checkpointer. |
Attributes:
| Name | Type | Description |
|---|---|---|
StateT |
|
|
logger |
|
call_realtime_sync
async
¶call_realtime_sync(state, config, checkpointer=Inject[BaseCheckpointer])
Call the realtime state sync hook if provided.
Source code in agentflow/graph/utils/utils.py
459 460 461 462 463 464 465 466 467 468 | |
check_and_handle_interrupt
async
¶check_and_handle_interrupt(interrupt_before, interrupt_after, current_node, interrupt_type, state, config, _sync_data)
Check for interrupts and save state if needed. Returns True if interrupted.
Source code in agentflow/graph/utils/utils.py
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 | |
get_next_node
¶get_next_node(current_node, state, edges)
Get the next node to execute based on edges.
Source code in agentflow/graph/utils/utils.py
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | |
load_or_create_state
async
¶load_or_create_state(input_data, config, old_state, checkpointer=Inject[BaseCheckpointer])
Load existing state from checkpointer or create new state.
Attempts to fetch a realtime-synced state first, then falls back to
the persistent checkpointer. If no existing state is found, creates
a new state from the StateGraph's prototype state and merges any
incoming messages. Supports partial state update via 'state' in input_data.
Source code in agentflow/graph/utils/utils.py
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 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
parse_response
async
¶parse_response(state, messages, response_granularity=ResponseGranularity.LOW)
Parse and format execution response based on specified granularity level.
Formats the final response from graph execution according to the requested granularity level, allowing clients to receive different levels of detail depending on their needs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
¶ |
AgentState
|
The final agent state after graph execution. |
required |
messages
¶ |
list[Message]
|
List of messages generated during execution. |
required |
response_granularity
¶ |
ResponseGranularity
|
Level of detail to include in the response: - FULL: Returns complete state object and all messages - PARTIAL: Returns context, summary, and messages - LOW: Returns only the messages (default) |
LOW
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing the formatted response with keys depending on |
dict[str, Any]
|
granularity level. Always includes 'messages' key with execution results. |
Example
# LOW granularity (default)
response = await parse_response(state, messages)
# Returns: {"messages": [Message(...), ...]}
# FULL granularity
response = await parse_response(state, messages, ResponseGranularity.FULL)
# Returns: {"state": AgentState(...), "messages": [Message(...), ...]}
Source code in agentflow/graph/utils/utils.py
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 | |
process_node_result
async
¶process_node_result(result, state, messages)
Processes the result from a node execution, updating the agent state, message list, and determining the next node.
Supports: - Handling results of type Command, AgentState, Message, list, str, dict, or other types. - Deduplicating messages by message_id. - Updating the agent state and its context with new messages. - Extracting navigation information (next node) from Command results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
¶ |
Any
|
The output from a node execution. Can be a Command, AgentState, Message, list, str, dict, ModelResponse, or other types. |
required |
state
¶ |
StateT
|
The current agent state. |
required |
messages
¶ |
list[Message]
|
The list of messages accumulated so far. |
required |
Returns:
| Type | Description |
|---|---|
tuple[StateT, list[Message], str | None]
|
tuple[StateT, list[Message], str | None]: - The updated agent state. - The updated list of messages (with new, unique messages added). - The identifier of the next node to execute, if specified; otherwise, None. |
Source code in agentflow/graph/utils/utils.py
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
reload_state
async
¶reload_state(config, old_state, checkpointer=Inject[BaseCheckpointer])
Load existing state from checkpointer or create new state.
Attempts to fetch a realtime-synced state first, then falls back to
the persistent checkpointer. If no existing state is found, creates
a new state from the StateGraph's prototype state and merges any
incoming messages. Supports partial state update via 'state' in input_data.
Source code in agentflow/graph/utils/utils.py
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 | |
sync_data
async
¶sync_data(state, config, messages, trim=False, checkpointer=Inject[BaseCheckpointer], context_manager=Inject[BaseContextManager])
Sync the current state and messages to the checkpointer.
Source code in agentflow/graph/utils/utils.py
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 | |
prebuilt
¶
Modules:
| Name | Description |
|---|---|
agent |
|
Modules¶
agent
¶
Modules:
| Name | Description |
|---|---|
branch_join |
|
deep_research |
|
guarded |
|
map_reduce |
|
network |
|
plan_act_reflect |
|
rag |
|
react |
|
router |
|
sequential |
|
supervisor_team |
|
swarm |
|
Classes:
| Name | Description |
|---|---|
BranchJoinAgent |
Execute multiple branches then join. |
DeepResearchAgent |
Deep Research Agent: PLAN → RESEARCH → SYNTHESIZE → CRITIQUE loop. |
GuardedAgent |
Validate output and repair until valid or attempts exhausted. |
MapReduceAgent |
Map over items then reduce. |
NetworkAgent |
Network pattern: define arbitrary node set and routing policies. |
PlanActReflectAgent |
Plan -> Act -> Reflect looping agent. |
RAGAgent |
Simple RAG: retrieve -> synthesize; optional follow-up. |
ReactAgent |
|
RouterAgent |
A configurable router-style agent. |
SequentialAgent |
A simple sequential agent that executes a fixed pipeline of nodes. |
SupervisorTeamAgent |
Supervisor routes tasks to worker nodes and aggregates results. |
SwarmAgent |
Swarm pattern: dispatch to many workers, collect, then reach consensus. |
Attributes¶
__all__
module-attribute
¶__all__ = ['BranchJoinAgent', 'DeepResearchAgent', 'GuardedAgent', 'MapReduceAgent', 'NetworkAgent', 'PlanActReflectAgent', 'RAGAgent', 'ReactAgent', 'RouterAgent', 'SequentialAgent', 'SupervisorTeamAgent', 'SwarmAgent']
Classes¶
BranchJoinAgent
¶Execute multiple branches then join.
Note: This prebuilt models branches sequentially (not true parallel execution). For each provided branch node, we add edges branch_i -> JOIN. The JOIN node decides whether more branches remain or END. A more advanced version could use BackgroundTaskManager for concurrency.
Methods:
| Name | Description |
|---|---|
__init__ |
|
compile |
|
Source code in agentflow/prebuilt/agent/branch_join.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 | |
__init__
¶__init__(state=None, context_manager=None, publisher=None, id_generator=DefaultIDGenerator(), container=None)
Source code in agentflow/prebuilt/agent/branch_join.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
compile
¶compile(branches, join_node, next_branch_condition=None, checkpointer=None, store=None, interrupt_before=None, interrupt_after=None, callback_manager=CallbackManager())
Source code in agentflow/prebuilt/agent/branch_join.py
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 | |
DeepResearchAgent
¶Deep Research Agent: PLAN → RESEARCH → SYNTHESIZE → CRITIQUE loop.
This agent mirrors modern deep-research patterns inspired by DeerFlow and Tongyi DeepResearch: plan tasks, use tools to research, synthesize findings, critique gaps and iterate a bounded number of times.
Nodes: - PLAN: Decompose problem, propose search/tool actions; may include tool calls - RESEARCH: ToolNode executes search/browse/calc/etc tools - SYNTHESIZE: Aggregate and draft a coherent report or partial answer - CRITIQUE: Identify gaps, contradictions, or follow-ups; can request more tools
Routing:
- PLAN -> conditional(_route_after_plan):
{"RESEARCH": RESEARCH, "SYNTHESIZE": SYNTHESIZE, END: END}
- RESEARCH -> SYNTHESIZE
- SYNTHESIZE -> CRITIQUE
- CRITIQUE -> conditional(_route_after_critique): {"RESEARCH": RESEARCH, END: END}
Iteration Control: - Uses execution_meta.internal_data keys: dr_max_iters (int): maximum critique→research loops (default 2) dr_iters (int): current loop count (auto-updated) dr_heavy_mode (bool): if True, bias towards one more loop when critique suggests
Methods:
| Name | Description |
|---|---|
__init__ |
|
compile |
|
Source code in agentflow/prebuilt/agent/deep_research.py
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 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 | |
__init__
¶__init__(state=None, context_manager=None, publisher=None, id_generator=DefaultIDGenerator(), container=None, max_iters=2, heavy_mode=False)
Source code in agentflow/prebuilt/agent/deep_research.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 | |
compile
¶compile(plan_node, research_tool_node, synthesize_node, critique_node, checkpointer=None, store=None, interrupt_before=None, interrupt_after=None, callback_manager=CallbackManager())
Source code in agentflow/prebuilt/agent/deep_research.py
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 | |
GuardedAgent
¶Validate output and repair until valid or attempts exhausted.
Nodes: - PRODUCE: main generation node - REPAIR: correction node when validation fails
Edges: PRODUCE -> conditional(valid? END : REPAIR) REPAIR -> PRODUCE
Methods:
| Name | Description |
|---|---|
__init__ |
|
compile |
|
Source code in agentflow/prebuilt/agent/guarded.py
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 | |
__init__
¶__init__(state=None, context_manager=None, publisher=None, id_generator=DefaultIDGenerator(), container=None)
Source code in agentflow/prebuilt/agent/guarded.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
compile
¶compile(produce_node, repair_node, validator, max_attempts=2, checkpointer=None, store=None, interrupt_before=None, interrupt_after=None, callback_manager=CallbackManager())
Source code in agentflow/prebuilt/agent/guarded.py
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 | |
MapReduceAgent
¶Map over items then reduce.
Nodes: - SPLIT: optional, prepares per-item tasks (or state already contains items) - MAP: processes one item per iteration - REDUCE: aggregates results and decides END or continue
Compile requires
map_node: Callable|ToolNode reduce_node: Callable split_node: Callable | None condition: Callable[[AgentState], str] returns "MAP" to continue or END
Methods:
| Name | Description |
|---|---|
__init__ |
|
compile |
|
Source code in agentflow/prebuilt/agent/map_reduce.py
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 | |
__init__
¶__init__(state=None, context_manager=None, publisher=None, id_generator=DefaultIDGenerator(), container=None)
Source code in agentflow/prebuilt/agent/map_reduce.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
compile
¶compile(map_node, reduce_node, split_node=None, condition=None, checkpointer=None, store=None, interrupt_before=None, interrupt_after=None, callback_manager=CallbackManager())
Source code in agentflow/prebuilt/agent/map_reduce.py
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 | |
NetworkAgent
¶Network pattern: define arbitrary node set and routing policies.
- Nodes can be callables or ToolNode.
- Edges can be static or conditional via a router function per node.
- Entry point is explicit.
Methods:
| Name | Description |
|---|---|
__init__ |
|
compile |
|
Source code in agentflow/prebuilt/agent/network.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 | |
__init__
¶__init__(state=None, context_manager=None, publisher=None, id_generator=DefaultIDGenerator(), container=None)
Source code in agentflow/prebuilt/agent/network.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
compile
¶compile(nodes, entry, static_edges=None, conditional_edges=None, checkpointer=None, store=None, interrupt_before=None, interrupt_after=None, callback_manager=CallbackManager())
Source code in agentflow/prebuilt/agent/network.py
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 | |
PlanActReflectAgent
¶Plan -> Act -> Reflect looping agent.
Pattern
PLAN -> (condition) -> ACT | REFLECT | END ACT -> REFLECT REFLECT -> PLAN
Default condition (_should_act): - If last assistant message contains tool calls -> ACT - If last message is from a tool -> REFLECT - Else -> END
Provide a custom condition to override this heuristic and implement
- Budget / depth limiting
- Confidence-based early stop
- Dynamic branch selection (e.g., different tool nodes)
Parameters (constructor): state: Optional initial state instance context_manager: Custom context manager publisher: Optional publisher for streaming / events id_generator: ID generation strategy container: InjectQ DI container
compile(...) arguments: plan_node: Callable (state -> state). Produces next thought / tool requests tool_node: ToolNode executing declared tools reflect_node: Callable (state -> state). Consumes tool results & may adjust plan condition: Optional Callable[[AgentState], str] returning next node name or END checkpointer/store/interrupt_before/interrupt_after/callback_manager: Standard graph compilation options
Returns:
| Type | Description |
|---|---|
|
CompiledGraph ready for invoke / ainvoke. |
Notes
- Node names can be customized via (callable, "NAME") tuples.
- condition must return one of: tool_node_name, reflect_node_name, END.
Methods:
| Name | Description |
|---|---|
__init__ |
|
compile |
Compile the Plan-Act-Reflect loop. |
Source code in agentflow/prebuilt/agent/plan_act_reflect.py
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 | |
__init__
¶__init__(state=None, context_manager=None, publisher=None, id_generator=DefaultIDGenerator(), container=None)
Source code in agentflow/prebuilt/agent/plan_act_reflect.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
compile
¶compile(plan_node, tool_node, reflect_node, *, condition=None, checkpointer=None, store=None, interrupt_before=None, interrupt_after=None, callback_manager=CallbackManager())
Compile the Plan-Act-Reflect loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plan_node
¶ |
Callable | tuple[Callable, str]
|
Callable or (callable, name) |
required |
tool_node
¶ |
ToolNode | tuple[ToolNode, str]
|
ToolNode or (ToolNode, name) |
required |
reflect_node
¶ |
Callable | tuple[Callable, str]
|
Callable or (callable, name) |
required |
condition
¶ |
Callable[[AgentState], str] | None
|
Optional decision function. Defaults to internal heuristic. |
None
|
checkpointer/store/interrupt_* / callback_manager
¶ |
Standard graph options. |
required |
Returns:
| Type | Description |
|---|---|
CompiledGraph
|
CompiledGraph |
Source code in agentflow/prebuilt/agent/plan_act_reflect.py
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 | |
RAGAgent
¶Simple RAG: retrieve -> synthesize; optional follow-up.
Nodes: - RETRIEVE: uses a retriever (callable or ToolNode) to fetch context - SYNTHESIZE: LLM/composer builds an answer - Optional condition: loop back to RETRIEVE for follow-up queries; else END
Methods:
| Name | Description |
|---|---|
__init__ |
|
compile |
|
compile_advanced |
Advanced RAG wiring with hybrid retrieval and optional stages. |
Source code in agentflow/prebuilt/agent/rag.py
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 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 | |
__init__
¶__init__(state=None, context_manager=None, publisher=None, id_generator=DefaultIDGenerator(), container=None)
Source code in agentflow/prebuilt/agent/rag.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
compile
¶compile(retriever_node, synthesize_node, followup_condition=None, checkpointer=None, store=None, interrupt_before=None, interrupt_after=None, callback_manager=CallbackManager())
Source code in agentflow/prebuilt/agent/rag.py
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 | |
compile_advanced
¶compile_advanced(retriever_nodes, synthesize_node, options=None, checkpointer=None, store=None, interrupt_before=None, interrupt_after=None, callback_manager=CallbackManager())
Advanced RAG wiring with hybrid retrieval and optional stages.
Chain
(QUERY_PLAN?) -> R1 -> (MERGE?) -> R2 -> (MERGE?) -> ... -> (RERANK?) -> (COMPRESS?) -> SYNTHESIZE -> cond
Each retriever may be a different modality (sparse, dense, self-query, MMR, etc.).
Source code in agentflow/prebuilt/agent/rag.py
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 | |
ReactAgent
¶Methods:
| Name | Description |
|---|---|
__init__ |
|
compile |
|
Source code in agentflow/prebuilt/agent/react.py
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 | |
__init__
¶__init__(state=None, context_manager=None, publisher=None, id_generator=DefaultIDGenerator(), container=None)
Source code in agentflow/prebuilt/agent/react.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
compile
¶compile(main_node, tool_node, checkpointer=None, store=None, interrupt_before=None, interrupt_after=None, callback_manager=CallbackManager())
Source code in agentflow/prebuilt/agent/react.py
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 | |
RouterAgent
¶A configurable router-style agent.
Pattern: - A router node runs (LLM or custom logic) and may update state/messages - A condition function inspects the state and returns a route key - Edges route to the matching node; each route returns back to ROUTER - Return END (via condition) to finish
Usage
router = RouterAgent() app = router.compile( router_node=my_router_func, # def my_router_func(state, config, ...) routes={ "search": search_node, "summarize": summarize_node, }, # Condition inspects state and returns one of the keys above or END condition=my_condition, # def my_condition(state) -> str # Optional explicit path map if returned keys differ from node names # path_map={"SEARCH": "search", "SUM": "summarize", END: END} )
Methods:
| Name | Description |
|---|---|
__init__ |
|
compile |
|
Source code in agentflow/prebuilt/agent/router.py
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 | |
__init__
¶__init__(state=None, context_manager=None, publisher=None, id_generator=DefaultIDGenerator(), container=None)
Source code in agentflow/prebuilt/agent/router.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
compile
¶compile(router_node, routes, condition=None, path_map=None, checkpointer=None, store=None, interrupt_before=None, interrupt_after=None, callback_manager=CallbackManager())
Source code in agentflow/prebuilt/agent/router.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 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 | |
SequentialAgent
¶A simple sequential agent that executes a fixed pipeline of nodes.
Pattern: - Nodes run in the provided order: step1 -> step2 -> ... -> stepN - After the last step, the graph ends
Usage
seq = SequentialAgent() app = seq.compile([ ("ingest", ingest_node), ("plan", plan_node), ("execute", execute_node), ])
Methods:
| Name | Description |
|---|---|
__init__ |
|
compile |
|
Source code in agentflow/prebuilt/agent/sequential.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 | |
__init__
¶__init__(state=None, context_manager=None, publisher=None, id_generator=DefaultIDGenerator(), container=None)
Source code in agentflow/prebuilt/agent/sequential.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
compile
¶compile(steps, checkpointer=None, store=None, interrupt_before=None, interrupt_after=None, callback_manager=CallbackManager())
Source code in agentflow/prebuilt/agent/sequential.py
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 | |
SupervisorTeamAgent
¶Supervisor routes tasks to worker nodes and aggregates results.
Nodes: - SUPERVISOR: decides which worker to call (by returning a worker key) or END - Multiple WORKER nodes: functions or ToolNode instances - AGGREGATE: optional aggregator node after worker runs; loops back to SUPERVISOR
The compile requires
supervisor_node: Callable workers: dict[str, Callable|ToolNode] aggregate_node: Callable | None condition: Callable[[AgentState], str] returns worker key or END
Methods:
| Name | Description |
|---|---|
__init__ |
|
compile |
|
Source code in agentflow/prebuilt/agent/supervisor_team.py
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 | |
__init__
¶__init__(state=None, context_manager=None, publisher=None, id_generator=DefaultIDGenerator(), container=None)
Source code in agentflow/prebuilt/agent/supervisor_team.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
compile
¶compile(supervisor_node, workers, condition, aggregate_node=None, checkpointer=None, store=None, interrupt_before=None, interrupt_after=None, callback_manager=CallbackManager())
Source code in agentflow/prebuilt/agent/supervisor_team.py
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 | |
SwarmAgent
¶Swarm pattern: dispatch to many workers, collect, then reach consensus.
Notes: - The underlying engine executes nodes sequentially; true parallelism isn't performed at the graph level. For concurrency, worker/collector nodes can internally use BackgroundTaskManager or async to fan-out. - This pattern wires a linear broadcast-collect chain ending in CONSENSUS.
Nodes: - optional DISPATCH: prepare/plan the swarm task - WORKER_i: a set of worker nodes (Callable or ToolNode) - optional COLLECT: consolidate each worker's result into shared state - CONSENSUS: aggregate all collected results and produce final output
Methods:
| Name | Description |
|---|---|
__init__ |
|
compile |
|
Source code in agentflow/prebuilt/agent/swarm.py
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 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 | |
__init__
¶__init__(state=None, context_manager=None, publisher=None, id_generator=DefaultIDGenerator(), container=None)
Source code in agentflow/prebuilt/agent/swarm.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
compile
¶compile(workers, consensus_node, options=None, checkpointer=None, store=None, interrupt_before=None, interrupt_after=None, callback_manager=CallbackManager())
Source code in agentflow/prebuilt/agent/swarm.py
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 | |
Modules¶
branch_join
¶Classes:
| Name | Description |
|---|---|
BranchJoinAgent |
Execute multiple branches then join. |
Attributes:
| Name | Type | Description |
|---|---|---|
StateT |
|
BranchJoinAgent
¶Execute multiple branches then join.
Note: This prebuilt models branches sequentially (not true parallel execution). For each provided branch node, we add edges branch_i -> JOIN. The JOIN node decides whether more branches remain or END. A more advanced version could use BackgroundTaskManager for concurrency.
Methods:
| Name | Description |
|---|---|
__init__ |
|
compile |
|
Source code in agentflow/prebuilt/agent/branch_join.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 | |
__init__
¶__init__(state=None, context_manager=None, publisher=None, id_generator=DefaultIDGenerator(), container=None)
Source code in agentflow/prebuilt/agent/branch_join.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
compile
¶compile(branches, join_node, next_branch_condition=None, checkpointer=None, store=None, interrupt_before=None, interrupt_after=None, callback_manager=CallbackManager())
Source code in agentflow/prebuilt/agent/branch_join.py
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 | |
deep_research
¶Classes:
| Name | Description |
|---|---|
DeepResearchAgent |
Deep Research Agent: PLAN → RESEARCH → SYNTHESIZE → CRITIQUE loop. |
Attributes:
| Name | Type | Description |
|---|---|---|
StateT |
|
DeepResearchAgent
¶Deep Research Agent: PLAN → RESEARCH → SYNTHESIZE → CRITIQUE loop.
This agent mirrors modern deep-research patterns inspired by DeerFlow and Tongyi DeepResearch: plan tasks, use tools to research, synthesize findings, critique gaps and iterate a bounded number of times.
Nodes: - PLAN: Decompose problem, propose search/tool actions; may include tool calls - RESEARCH: ToolNode executes search/browse/calc/etc tools - SYNTHESIZE: Aggregate and draft a coherent report or partial answer - CRITIQUE: Identify gaps, contradictions, or follow-ups; can request more tools
Routing:
- PLAN -> conditional(_route_after_plan):
{"RESEARCH": RESEARCH, "SYNTHESIZE": SYNTHESIZE, END: END}
- RESEARCH -> SYNTHESIZE
- SYNTHESIZE -> CRITIQUE
- CRITIQUE -> conditional(_route_after_critique): {"RESEARCH": RESEARCH, END: END}
Iteration Control: - Uses execution_meta.internal_data keys: dr_max_iters (int): maximum critique→research loops (default 2) dr_iters (int): current loop count (auto-updated) dr_heavy_mode (bool): if True, bias towards one more loop when critique suggests
Methods:
| Name | Description |
|---|---|
__init__ |
|
compile |
|
Source code in agentflow/prebuilt/agent/deep_research.py
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 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 | |
__init__
¶__init__(state=None, context_manager=None, publisher=None, id_generator=DefaultIDGenerator(), container=None, max_iters=2, heavy_mode=False)
Source code in agentflow/prebuilt/agent/deep_research.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 | |
compile
¶compile(plan_node, research_tool_node, synthesize_node, critique_node, checkpointer=None, store=None, interrupt_before=None, interrupt_after=None, callback_manager=CallbackManager())
Source code in agentflow/prebuilt/agent/deep_research.py
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 | |
guarded
¶Classes:
| Name | Description |
|---|---|
GuardedAgent |
Validate output and repair until valid or attempts exhausted. |
Attributes:
| Name | Type | Description |
|---|---|---|
StateT |
|
GuardedAgent
¶Validate output and repair until valid or attempts exhausted.
Nodes: - PRODUCE: main generation node - REPAIR: correction node when validation fails
Edges: PRODUCE -> conditional(valid? END : REPAIR) REPAIR -> PRODUCE
Methods:
| Name | Description |
|---|---|
__init__ |
|
compile |
|
Source code in agentflow/prebuilt/agent/guarded.py
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 | |
__init__
¶__init__(state=None, context_manager=None, publisher=None, id_generator=DefaultIDGenerator(), container=None)
Source code in agentflow/prebuilt/agent/guarded.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
compile
¶compile(produce_node, repair_node, validator, max_attempts=2, checkpointer=None, store=None, interrupt_before=None, interrupt_after=None, callback_manager=CallbackManager())
Source code in agentflow/prebuilt/agent/guarded.py
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 | |
map_reduce
¶Classes:
| Name | Description |
|---|---|
MapReduceAgent |
Map over items then reduce. |
Attributes:
| Name | Type | Description |
|---|---|---|
StateT |
|
MapReduceAgent
¶Map over items then reduce.
Nodes: - SPLIT: optional, prepares per-item tasks (or state already contains items) - MAP: processes one item per iteration - REDUCE: aggregates results and decides END or continue
Compile requires
map_node: Callable|ToolNode reduce_node: Callable split_node: Callable | None condition: Callable[[AgentState], str] returns "MAP" to continue or END
Methods:
| Name | Description |
|---|---|
__init__ |
|
compile |
|
Source code in agentflow/prebuilt/agent/map_reduce.py
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 | |
__init__
¶__init__(state=None, context_manager=None, publisher=None, id_generator=DefaultIDGenerator(), container=None)
Source code in agentflow/prebuilt/agent/map_reduce.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
compile
¶compile(map_node, reduce_node, split_node=None, condition=None, checkpointer=None, store=None, interrupt_before=None, interrupt_after=None, callback_manager=CallbackManager())
Source code in agentflow/prebuilt/agent/map_reduce.py
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 | |
network
¶Classes:
| Name | Description |
|---|---|
NetworkAgent |
Network pattern: define arbitrary node set and routing policies. |
Attributes:
| Name | Type | Description |
|---|---|---|
StateT |
|
NetworkAgent
¶Network pattern: define arbitrary node set and routing policies.
- Nodes can be callables or ToolNode.
- Edges can be static or conditional via a router function per node.
- Entry point is explicit.
Methods:
| Name | Description |
|---|---|
__init__ |
|
compile |
|
Source code in agentflow/prebuilt/agent/network.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 | |
__init__
¶__init__(state=None, context_manager=None, publisher=None, id_generator=DefaultIDGenerator(), container=None)
Source code in agentflow/prebuilt/agent/network.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
compile
¶compile(nodes, entry, static_edges=None, conditional_edges=None, checkpointer=None, store=None, interrupt_before=None, interrupt_after=None, callback_manager=CallbackManager())
Source code in agentflow/prebuilt/agent/network.py
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 | |
plan_act_reflect
¶Classes:
| Name | Description |
|---|---|
PlanActReflectAgent |
Plan -> Act -> Reflect looping agent. |
Attributes:
| Name | Type | Description |
|---|---|---|
StateT |
|
PlanActReflectAgent
¶Plan -> Act -> Reflect looping agent.
Pattern
PLAN -> (condition) -> ACT | REFLECT | END ACT -> REFLECT REFLECT -> PLAN
Default condition (_should_act): - If last assistant message contains tool calls -> ACT - If last message is from a tool -> REFLECT - Else -> END
Provide a custom condition to override this heuristic and implement
- Budget / depth limiting
- Confidence-based early stop
- Dynamic branch selection (e.g., different tool nodes)
Parameters (constructor): state: Optional initial state instance context_manager: Custom context manager publisher: Optional publisher for streaming / events id_generator: ID generation strategy container: InjectQ DI container
compile(...) arguments: plan_node: Callable (state -> state). Produces next thought / tool requests tool_node: ToolNode executing declared tools reflect_node: Callable (state -> state). Consumes tool results & may adjust plan condition: Optional Callable[[AgentState], str] returning next node name or END checkpointer/store/interrupt_before/interrupt_after/callback_manager: Standard graph compilation options
Returns:
| Type | Description |
|---|---|
|
CompiledGraph ready for invoke / ainvoke. |
Notes
- Node names can be customized via (callable, "NAME") tuples.
- condition must return one of: tool_node_name, reflect_node_name, END.
Methods:
| Name | Description |
|---|---|
__init__ |
|
compile |
Compile the Plan-Act-Reflect loop. |
Source code in agentflow/prebuilt/agent/plan_act_reflect.py
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 | |
__init__
¶__init__(state=None, context_manager=None, publisher=None, id_generator=DefaultIDGenerator(), container=None)
Source code in agentflow/prebuilt/agent/plan_act_reflect.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
compile
¶compile(plan_node, tool_node, reflect_node, *, condition=None, checkpointer=None, store=None, interrupt_before=None, interrupt_after=None, callback_manager=CallbackManager())
Compile the Plan-Act-Reflect loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plan_node
¶ |
Callable | tuple[Callable, str]
|
Callable or (callable, name) |
required |
tool_node
¶ |
ToolNode | tuple[ToolNode, str]
|
ToolNode or (ToolNode, name) |
required |
reflect_node
¶ |
Callable | tuple[Callable, str]
|
Callable or (callable, name) |
required |
condition
¶ |
Callable[[AgentState], str] | None
|
Optional decision function. Defaults to internal heuristic. |
None
|
checkpointer/store/interrupt_* / callback_manager
¶ |
Standard graph options. |
required |
Returns:
| Type | Description |
|---|---|
CompiledGraph
|
CompiledGraph |
Source code in agentflow/prebuilt/agent/plan_act_reflect.py
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 | |
rag
¶Classes:
| Name | Description |
|---|---|
RAGAgent |
Simple RAG: retrieve -> synthesize; optional follow-up. |
Attributes:
| Name | Type | Description |
|---|---|---|
StateT |
|
RAGAgent
¶Simple RAG: retrieve -> synthesize; optional follow-up.
Nodes: - RETRIEVE: uses a retriever (callable or ToolNode) to fetch context - SYNTHESIZE: LLM/composer builds an answer - Optional condition: loop back to RETRIEVE for follow-up queries; else END
Methods:
| Name | Description |
|---|---|
__init__ |
|
compile |
|
compile_advanced |
Advanced RAG wiring with hybrid retrieval and optional stages. |
Source code in agentflow/prebuilt/agent/rag.py
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 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 | |
__init__
¶__init__(state=None, context_manager=None, publisher=None, id_generator=DefaultIDGenerator(), container=None)
Source code in agentflow/prebuilt/agent/rag.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
compile
¶compile(retriever_node, synthesize_node, followup_condition=None, checkpointer=None, store=None, interrupt_before=None, interrupt_after=None, callback_manager=CallbackManager())
Source code in agentflow/prebuilt/agent/rag.py
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 | |
compile_advanced
¶compile_advanced(retriever_nodes, synthesize_node, options=None, checkpointer=None, store=None, interrupt_before=None, interrupt_after=None, callback_manager=CallbackManager())
Advanced RAG wiring with hybrid retrieval and optional stages.
Chain
(QUERY_PLAN?) -> R1 -> (MERGE?) -> R2 -> (MERGE?) -> ... -> (RERANK?) -> (COMPRESS?) -> SYNTHESIZE -> cond
Each retriever may be a different modality (sparse, dense, self-query, MMR, etc.).
Source code in agentflow/prebuilt/agent/rag.py
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 | |
react
¶Classes:
| Name | Description |
|---|---|
ReactAgent |
|
Attributes:
| Name | Type | Description |
|---|---|---|
StateT |
|
ReactAgent
¶Methods:
| Name | Description |
|---|---|
__init__ |
|
compile |
|
Source code in agentflow/prebuilt/agent/react.py
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 | |
__init__
¶__init__(state=None, context_manager=None, publisher=None, id_generator=DefaultIDGenerator(), container=None)
Source code in agentflow/prebuilt/agent/react.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
compile
¶compile(main_node, tool_node, checkpointer=None, store=None, interrupt_before=None, interrupt_after=None, callback_manager=CallbackManager())
Source code in agentflow/prebuilt/agent/react.py
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 | |
router
¶Classes:
| Name | Description |
|---|---|
RouterAgent |
A configurable router-style agent. |
Attributes:
| Name | Type | Description |
|---|---|---|
StateT |
|
RouterAgent
¶A configurable router-style agent.
Pattern: - A router node runs (LLM or custom logic) and may update state/messages - A condition function inspects the state and returns a route key - Edges route to the matching node; each route returns back to ROUTER - Return END (via condition) to finish
Usage
router = RouterAgent() app = router.compile( router_node=my_router_func, # def my_router_func(state, config, ...) routes={ "search": search_node, "summarize": summarize_node, }, # Condition inspects state and returns one of the keys above or END condition=my_condition, # def my_condition(state) -> str # Optional explicit path map if returned keys differ from node names # path_map={"SEARCH": "search", "SUM": "summarize", END: END} )
Methods:
| Name | Description |
|---|---|
__init__ |
|
compile |
|
Source code in agentflow/prebuilt/agent/router.py
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 | |
__init__
¶__init__(state=None, context_manager=None, publisher=None, id_generator=DefaultIDGenerator(), container=None)
Source code in agentflow/prebuilt/agent/router.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
compile
¶compile(router_node, routes, condition=None, path_map=None, checkpointer=None, store=None, interrupt_before=None, interrupt_after=None, callback_manager=CallbackManager())
Source code in agentflow/prebuilt/agent/router.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 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 | |
sequential
¶Classes:
| Name | Description |
|---|---|
SequentialAgent |
A simple sequential agent that executes a fixed pipeline of nodes. |
Attributes:
| Name | Type | Description |
|---|---|---|
StateT |
|
SequentialAgent
¶A simple sequential agent that executes a fixed pipeline of nodes.
Pattern: - Nodes run in the provided order: step1 -> step2 -> ... -> stepN - After the last step, the graph ends
Usage
seq = SequentialAgent() app = seq.compile([ ("ingest", ingest_node), ("plan", plan_node), ("execute", execute_node), ])
Methods:
| Name | Description |
|---|---|
__init__ |
|
compile |
|
Source code in agentflow/prebuilt/agent/sequential.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 | |
__init__
¶__init__(state=None, context_manager=None, publisher=None, id_generator=DefaultIDGenerator(), container=None)
Source code in agentflow/prebuilt/agent/sequential.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
compile
¶compile(steps, checkpointer=None, store=None, interrupt_before=None, interrupt_after=None, callback_manager=CallbackManager())
Source code in agentflow/prebuilt/agent/sequential.py
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 | |
supervisor_team
¶Classes:
| Name | Description |
|---|---|
SupervisorTeamAgent |
Supervisor routes tasks to worker nodes and aggregates results. |
Attributes:
| Name | Type | Description |
|---|---|---|
StateT |
|
SupervisorTeamAgent
¶Supervisor routes tasks to worker nodes and aggregates results.
Nodes: - SUPERVISOR: decides which worker to call (by returning a worker key) or END - Multiple WORKER nodes: functions or ToolNode instances - AGGREGATE: optional aggregator node after worker runs; loops back to SUPERVISOR
The compile requires
supervisor_node: Callable workers: dict[str, Callable|ToolNode] aggregate_node: Callable | None condition: Callable[[AgentState], str] returns worker key or END
Methods:
| Name | Description |
|---|---|
__init__ |
|
compile |
|
Source code in agentflow/prebuilt/agent/supervisor_team.py
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 | |
__init__
¶__init__(state=None, context_manager=None, publisher=None, id_generator=DefaultIDGenerator(), container=None)
Source code in agentflow/prebuilt/agent/supervisor_team.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
compile
¶compile(supervisor_node, workers, condition, aggregate_node=None, checkpointer=None, store=None, interrupt_before=None, interrupt_after=None, callback_manager=CallbackManager())
Source code in agentflow/prebuilt/agent/supervisor_team.py
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 | |
swarm
¶Classes:
| Name | Description |
|---|---|
SwarmAgent |
Swarm pattern: dispatch to many workers, collect, then reach consensus. |
Attributes:
| Name | Type | Description |
|---|---|---|
StateT |
|
SwarmAgent
¶Swarm pattern: dispatch to many workers, collect, then reach consensus.
Notes: - The underlying engine executes nodes sequentially; true parallelism isn't performed at the graph level. For concurrency, worker/collector nodes can internally use BackgroundTaskManager or async to fan-out. - This pattern wires a linear broadcast-collect chain ending in CONSENSUS.
Nodes: - optional DISPATCH: prepare/plan the swarm task - WORKER_i: a set of worker nodes (Callable or ToolNode) - optional COLLECT: consolidate each worker's result into shared state - CONSENSUS: aggregate all collected results and produce final output
Methods:
| Name | Description |
|---|---|
__init__ |
|
compile |
|
Source code in agentflow/prebuilt/agent/swarm.py
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 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 | |
__init__
¶__init__(state=None, context_manager=None, publisher=None, id_generator=DefaultIDGenerator(), container=None)
Source code in agentflow/prebuilt/agent/swarm.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
compile
¶compile(workers, consensus_node, options=None, checkpointer=None, store=None, interrupt_before=None, interrupt_after=None, callback_manager=CallbackManager())
Source code in agentflow/prebuilt/agent/swarm.py
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 | |
publisher
¶
Publisher module for TAF events.
This module provides publishers that handle the delivery of events to various outputs, such as console, Redis, Kafka, and RabbitMQ. Publishers are primarily used for logging and monitoring agent behavior, enabling real-time tracking of performance, usage, and debugging in agent graphs.
Key components: - BasePublisher: Abstract base class for all publishers, defining the interface for publishing event - ConsolePublisher: Default publisher that outputs events to the console for development and debugging - Optional publishers: RedisPublisher, KafkaPublisher, RabbitMQPublisher, which are available only if their dependencies are installed
Usage: - Import publishers: from agentflow.publisher import ConsolePublisher, RedisPublisher (if available) - Instantiate and use in CompiledGraph: graph.compile(publisher=ConsolePublisher()). - Events are emitted as EventModel instances during graph execution, including node starts, completions, and errors.
Dependencies for optional publishers: - RedisPublisher: Requires 'redis.asyncio' (install via pip install redis). - KafkaPublisher: Requires 'aiokafka' (install via pip install aiokafka). - RabbitMQPublisher: Requires 'aio_pika' (install via pip install aio-pika).
For more details, see the individual publisher classes and the TAF documentation.
Modules:
| Name | Description |
|---|---|
base_publisher |
|
console_publisher |
Console publisher implementation for debugging and testing. |
events |
Event and streaming primitives for agent graph execution. |
kafka_publisher |
Kafka publisher implementation (optional dependency). |
publish |
|
rabbitmq_publisher |
RabbitMQ publisher implementation (optional dependency). |
redis_publisher |
Redis publisher implementation (optional dependency). |
Classes:
| Name | Description |
|---|---|
BasePublisher |
Abstract base class for event publishers. |
ConsolePublisher |
Publisher that prints events to the console for debugging and testing. |
ContentType |
Enum for semantic content types in agent graph streaming. |
Event |
Enum for event sources in agent graph execution. |
EventModel |
Structured event chunk for streaming agent graph execution. |
EventType |
Enum for event phases in agent graph execution. |
KafkaPublisher |
Publish events to a Kafka topic using aiokafka. |
RabbitMQPublisher |
Publish events to RabbitMQ using aio-pika. |
RedisPublisher |
Publish events to Redis via Pub/Sub channel or Stream. |
Functions:
| Name | Description |
|---|---|
publish_event |
Publish an event asynchronously using the background task manager. |
Attributes¶
__all__
module-attribute
¶
__all__ = ['BasePublisher', 'ConsolePublisher', 'ContentType', 'Event', 'EventModel', 'EventType', 'KafkaPublisher', 'RabbitMQPublisher', 'RedisPublisher', 'publish_event']
Classes¶
BasePublisher
¶
Bases: ABC
Abstract base class for event publishers.
This class defines the interface for publishing events. Subclasses should implement the publish, close, and sync_close methods to provide specific publishing logic.
Attributes:
| Name | Type | Description |
|---|---|---|
config |
Configuration dictionary for the publisher. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the publisher with the given configuration. |
close |
Close the publisher and release any resources. |
publish |
Publish an event. |
sync_close |
Close the publisher and release any resources (synchronous version). |
Source code in agentflow/publisher/base_publisher.py
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
Attributes¶
Functions¶
__init__
¶__init__(config)
Initialize the publisher with the given configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict[str, Any]
|
Configuration dictionary for the publisher. |
required |
Source code in agentflow/publisher/base_publisher.py
17 18 19 20 21 22 23 | |
close
abstractmethod
async
¶close()
Close the publisher and release any resources.
This method should be overridden by subclasses to provide specific cleanup logic. It will be called externally.
Source code in agentflow/publisher/base_publisher.py
37 38 39 40 41 42 43 44 | |
publish
abstractmethod
async
¶publish(event)
Publish an event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
¶ |
EventModel
|
The event to publish. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The result of the publish operation. |
Source code in agentflow/publisher/base_publisher.py
25 26 27 28 29 30 31 32 33 34 35 | |
sync_close
abstractmethod
¶sync_close()
Close the publisher and release any resources (synchronous version).
This method should be overridden by subclasses to provide specific cleanup logic. It will be called externally.
Source code in agentflow/publisher/base_publisher.py
46 47 48 49 50 51 52 53 | |
ConsolePublisher
¶
Bases: BasePublisher
Publisher that prints events to the console for debugging and testing.
This publisher is useful for development and debugging purposes, as it outputs event information to the standard output.
Attributes:
| Name | Type | Description |
|---|---|---|
format |
Output format ('json' by default). |
|
include_timestamp |
Whether to include timestamp (True by default). |
|
indent |
Indentation for output (2 by default). |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the ConsolePublisher with the given configuration. |
close |
Close the publisher and release any resources. |
publish |
Publish an event to the console. |
sync_close |
Synchronously close the publisher and release any resources. |
Source code in agentflow/publisher/console_publisher.py
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 | |
Attributes¶
include_timestamp
instance-attribute
¶include_timestamp = get('include_timestamp', True) if config else True
Functions¶
__init__
¶__init__(config=None)
Initialize the ConsolePublisher with the given configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict[str, Any] | None
|
Configuration dictionary. Supported keys: - format: Output format (default: 'json'). - include_timestamp: Whether to include timestamp (default: True). - indent: Indentation for output (default: 2). |
None
|
Source code in agentflow/publisher/console_publisher.py
29 30 31 32 33 34 35 36 37 38 39 40 41 | |
close
async
¶close()
Close the publisher and release any resources.
ConsolePublisher does not require cleanup, but this method is provided for interface compatibility.
Source code in agentflow/publisher/console_publisher.py
57 58 59 60 61 62 63 | |
publish
async
¶publish(event)
Publish an event to the console.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
¶ |
EventModel
|
The event to publish. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
None |
Source code in agentflow/publisher/console_publisher.py
43 44 45 46 47 48 49 50 51 52 53 54 55 | |
sync_close
¶sync_close()
Synchronously close the publisher and release any resources.
ConsolePublisher does not require cleanup, but this method is provided for interface compatibility.
Source code in agentflow/publisher/console_publisher.py
65 66 67 68 69 70 71 | |
ContentType
¶
Bases: str, Enum
Enum for semantic content types in agent graph streaming.
Values
TEXT: Textual content. MESSAGE: Message content. REASONING: Reasoning content. TOOL_CALL: Tool call content. TOOL_RESULT: Tool result content. IMAGE: Image content. AUDIO: Audio content. VIDEO: Video content. DOCUMENT: Document content. DATA: Data content. STATE: State content. UPDATE: Update content. ERROR: Error content.
Attributes:
| Name | Type | Description |
|---|---|---|
AUDIO |
|
|
DATA |
|
|
DOCUMENT |
|
|
ERROR |
|
|
IMAGE |
|
|
MESSAGE |
|
|
REASONING |
|
|
STATE |
|
|
TEXT |
|
|
TOOL_CALL |
|
|
TOOL_RESULT |
|
|
UPDATE |
|
|
VIDEO |
|
Source code in agentflow/publisher/events.py
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 | |
Attributes¶
Event
¶
Bases: str, Enum
Enum for event sources in agent graph execution.
Values
GRAPH_EXECUTION: Event from graph execution. NODE_EXECUTION: Event from node execution. TOOL_EXECUTION: Event from tool execution. STREAMING: Event from streaming updates.
Attributes:
| Name | Type | Description |
|---|---|---|
GRAPH_EXECUTION |
|
|
NODE_EXECUTION |
|
|
STREAMING |
|
|
TOOL_EXECUTION |
|
Source code in agentflow/publisher/events.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
Attributes¶
EventModel
¶
Bases: BaseModel
Structured event chunk for streaming agent graph execution.
Represents a chunk of streamed data with event and content semantics, supporting both delta (incremental) and full content. Used for real-time streaming of execution updates, tool calls, state changes, messages, and errors.
Attributes:
| Name | Type | Description |
|---|---|---|
event |
Event
|
Type of the event source. |
event_type |
EventType
|
Phase of the event (start, progress, end, update). |
content |
str
|
Streamed textual content. |
content_blocks |
list[ContentBlock] | None
|
Structured content blocks for multimodal streaming. |
delta |
list[ContentBlock] | None
|
True if this is a delta update (incremental). |
delta_type |
list[ContentBlock] | None
|
Type of delta when delta=True. |
block_index |
list[ContentBlock] | None
|
Index of the content block this chunk applies to. |
chunk_index |
list[ContentBlock] | None
|
Per-block chunk index for ordering. |
byte_offset |
list[ContentBlock] | None
|
Byte offset for binary/media streaming. |
data |
dict[str, Any]
|
Additional structured data. |
content_type |
list[ContentType] | None
|
Semantic type of content. |
sequence_id |
list[ContentType] | None
|
Monotonic sequence ID for stream ordering. |
node_name |
str
|
Name of the node producing this chunk. |
run_id |
str
|
Unique ID for this stream/run. |
thread_id |
str | int
|
Thread ID for this execution. |
timestamp |
float
|
UNIX timestamp of when chunk was created. |
is_error |
bool
|
Marks this chunk as representing an error state. |
metadata |
dict[str, Any]
|
Optional metadata for consumers. |
Classes:
| Name | Description |
|---|---|
Config |
Pydantic configuration for EventModel. |
Methods:
| Name | Description |
|---|---|
default |
Create a default EventModel instance with minimal required fields. |
stream |
Create a default EventModel instance for streaming updates. |
Source code in agentflow/publisher/events.py
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 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 | |
Attributes¶
content
class-attribute
instance-attribute
¶content = Field(default='', description='Streamed textual content')
content_blocks
class-attribute
instance-attribute
¶content_blocks = Field(default=None, description='Structured content blocks carried by this event')
content_type
class-attribute
instance-attribute
¶content_type = Field(default=None, description='Semantic type of content')
data
class-attribute
instance-attribute
¶data = Field(default_factory=dict, description='Additional structured data')
event
class-attribute
instance-attribute
¶event = Field(..., description='Type of the event source')
event_type
class-attribute
instance-attribute
¶event_type = Field(..., description='Phase of the event (start, progress, end, update)')
is_error
class-attribute
instance-attribute
¶is_error = Field(default=False, description='Marks this chunk as representing an error state')
metadata
class-attribute
instance-attribute
¶metadata = Field(default_factory=dict, description='Optional metadata for consumers')
node_name
class-attribute
instance-attribute
¶node_name = Field(default='', description='Name of the node producing this chunk')
run_id
class-attribute
instance-attribute
¶run_id = Field(default_factory=lambda: str(uuid4()), description='Unique ID for this stream/run')
thread_id
class-attribute
instance-attribute
¶thread_id = Field(default='', description='Thread ID for this execution')
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/publisher/events.py
161 162 163 164 165 166 167 168 | |
Functions¶
default
classmethod
¶default(base_config, data, content_type, event=Event.GRAPH_EXECUTION, event_type=EventType.START, node_name='', extra=None)
Create a default EventModel instance with minimal required fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_config
¶ |
dict
|
Base configuration for the event (thread/run/timestamp/user). |
required |
data
¶ |
dict[str, Any]
|
Structured data payload. |
required |
content_type
¶ |
list[ContentType]
|
Semantic type(s) of content. |
required |
event
¶ |
Event
|
Event source type (default: GRAPH_EXECUTION). |
GRAPH_EXECUTION
|
event_type
¶ |
Event phase (default: START). |
START
|
|
node_name
¶ |
str
|
Name of the node producing the event. |
''
|
extra
¶ |
dict[str, Any] | None
|
Additional metadata. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
EventModel |
EventModel
|
The created event model instance. |
Source code in agentflow/publisher/events.py
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 | |
stream
classmethod
¶stream(base_config, node_name='', extra=None)
Create a default EventModel instance for streaming updates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_config
¶ |
dict
|
Base configuration for the event (thread/run/timestamp/user). |
required |
node_name
¶ |
str
|
Name of the node producing the event. |
''
|
extra
¶ |
dict[str, Any] | None
|
Additional metadata. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
EventModel |
EventModel
|
The created event model instance for streaming. |
Source code in agentflow/publisher/events.py
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 | |
EventType
¶
Bases: str, Enum
Enum for event phases in agent graph execution.
Values
START: Event marks start of execution. PROGRESS: Event marks progress update. RESULT: Event marks result produced. END: Event marks end of execution. UPDATE: Event marks update. ERROR: Event marks error. INTERRUPTED: Event marks interruption.
Attributes:
| Name | Type | Description |
|---|---|---|
END |
|
|
ERROR |
|
|
INTERRUPTED |
|
|
PROGRESS |
|
|
RESULT |
|
|
START |
|
|
UPDATE |
|
Source code in agentflow/publisher/events.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
Attributes¶
KafkaPublisher
¶
Bases: BasePublisher
Publish events to a Kafka topic using aiokafka.
This class provides an asynchronous interface for publishing events to a Kafka topic. It uses the aiokafka library to handle the producer operations. The publisher is lazily initialized and can be reused for multiple publishes.
Attributes:
| Name | Type | Description |
|---|---|---|
bootstrap_servers |
str
|
Kafka bootstrap servers. |
topic |
str
|
Kafka topic to publish to. |
client_id |
str | None
|
Client ID for the producer. |
_producer |
Lazy-loaded Kafka producer instance. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the KafkaPublisher. |
close |
Close the Kafka producer. |
publish |
Publish an event to the Kafka topic. |
sync_close |
Synchronously close the Kafka producer. |
Source code in agentflow/publisher/kafka_publisher.py
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 | |
Attributes¶
bootstrap_servers
instance-attribute
¶bootstrap_servers = get('bootstrap_servers', 'localhost:9092')
Functions¶
__init__
¶__init__(config=None)
Initialize the KafkaPublisher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict[str, Any] | None
|
Configuration dictionary. Supported keys: - bootstrap_servers: Kafka bootstrap servers (default: "localhost:9092"). - topic: Kafka topic to publish to (default: "agentflow.events"). - client_id: Client ID for the producer. |
None
|
Source code in agentflow/publisher/kafka_publisher.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
close
async
¶close()
Close the Kafka producer.
Stops the producer and cleans up resources. Errors during stopping are logged but do not raise exceptions.
Source code in agentflow/publisher/kafka_publisher.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
publish
async
¶publish(event)
Publish an event to the Kafka topic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
¶ |
EventModel
|
The event to publish. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The result of the send_and_wait operation. |
Source code in agentflow/publisher/kafka_publisher.py
84 85 86 87 88 89 90 91 92 93 94 95 | |
sync_close
¶sync_close()
Synchronously close the Kafka producer.
This method runs the async close in a new event loop. If called within an active event loop, it logs a warning and skips the operation.
Source code in agentflow/publisher/kafka_publisher.py
113 114 115 116 117 118 119 120 121 122 | |
RabbitMQPublisher
¶
Bases: BasePublisher
Publish events to RabbitMQ using aio-pika.
Attributes:
| Name | Type | Description |
|---|---|---|
url |
str
|
RabbitMQ connection URL. |
exchange |
str
|
Exchange name. |
routing_key |
str
|
Routing key for messages. |
exchange_type |
str
|
Type of exchange. |
declare |
bool
|
Whether to declare the exchange. |
durable |
bool
|
Whether the exchange is durable. |
_conn |
Connection instance. |
|
_channel |
Channel instance. |
|
_exchange |
Exchange instance. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the RabbitMQPublisher. |
close |
Close the RabbitMQ connection and channel. |
publish |
Publish an event to RabbitMQ. |
sync_close |
Synchronously close the RabbitMQ connection. |
Source code in agentflow/publisher/rabbitmq_publisher.py
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 | |
Attributes¶
Functions¶
__init__
¶__init__(config=None)
Initialize the RabbitMQPublisher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict[str, Any] | None
|
Configuration dictionary. Supported keys: - url: RabbitMQ URL (default: "amqp://guest:guest@localhost/"). - exchange: Exchange name (default: "agentflow.events"). - routing_key: Routing key (default: "agentflow.events"). - exchange_type: Exchange type (default: "topic"). - declare: Whether to declare exchange (default: True). - durable: Whether exchange is durable (default: True). |
None
|
Source code in agentflow/publisher/rabbitmq_publisher.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
close
async
¶close()
Close the RabbitMQ connection and channel.
Source code in agentflow/publisher/rabbitmq_publisher.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
publish
async
¶publish(event)
Publish an event to RabbitMQ.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
¶ |
EventModel
|
The event to publish. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
True on success. |
Source code in agentflow/publisher/rabbitmq_publisher.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
sync_close
¶sync_close()
Synchronously close the RabbitMQ connection.
Source code in agentflow/publisher/rabbitmq_publisher.py
131 132 133 134 135 136 | |
RedisPublisher
¶
Bases: BasePublisher
Publish events to Redis via Pub/Sub channel or Stream.
Attributes:
| Name | Type | Description |
|---|---|---|
url |
str
|
Redis URL. |
mode |
str
|
Publishing mode ('pubsub' or 'stream'). |
channel |
str
|
Pub/Sub channel name. |
stream |
str
|
Stream name. |
maxlen |
int | None
|
Max length for streams. |
encoding |
str
|
Encoding for messages. |
_redis |
Redis client instance. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the RedisPublisher. |
close |
Close the Redis client. |
publish |
Publish an event to Redis. |
sync_close |
Synchronously close the Redis client. |
Source code in agentflow/publisher/redis_publisher.py
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 | |
Attributes¶
Functions¶
__init__
¶__init__(config=None)
Initialize the RedisPublisher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict[str, Any] | None
|
Configuration dictionary. Supported keys: - url: Redis URL (default: "redis://localhost:6379/0"). - mode: Publishing mode ('pubsub' or 'stream', default: 'pubsub'). - channel: Pub/Sub channel name (default: "agentflow.events"). - stream: Stream name (default: "agentflow.events"). - maxlen: Max length for streams. - encoding: Encoding (default: "utf-8"). |
None
|
Source code in agentflow/publisher/redis_publisher.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
close
async
¶close()
Close the Redis client.
Source code in agentflow/publisher/redis_publisher.py
114 115 116 117 118 119 120 121 122 123 | |
publish
async
¶publish(event)
Publish an event to Redis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
¶ |
EventModel
|
The event to publish. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The result of the publish operation. |
Source code in agentflow/publisher/redis_publisher.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
sync_close
¶sync_close()
Synchronously close the Redis client.
Source code in agentflow/publisher/redis_publisher.py
125 126 127 128 129 130 131 | |
Functions¶
publish_event
¶
publish_event(event, publisher=Inject[BasePublisher], task_manager=Inject[BackgroundTaskManager])
Publish an event asynchronously using the background task manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
EventModel
|
The event to publish. |
required |
|
BasePublisher | None
|
The publisher instance (injected). |
Inject[BasePublisher]
|
|
BackgroundTaskManager
|
The background task manager (injected). |
Inject[BackgroundTaskManager]
|
Source code in agentflow/publisher/publish.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
Modules¶
base_publisher
¶
Classes:
| Name | Description |
|---|---|
BasePublisher |
Abstract base class for event publishers. |
Classes¶
BasePublisher
¶
Bases: ABC
Abstract base class for event publishers.
This class defines the interface for publishing events. Subclasses should implement the publish, close, and sync_close methods to provide specific publishing logic.
Attributes:
| Name | Type | Description |
|---|---|---|
config |
Configuration dictionary for the publisher. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the publisher with the given configuration. |
close |
Close the publisher and release any resources. |
publish |
Publish an event. |
sync_close |
Close the publisher and release any resources (synchronous version). |
Source code in agentflow/publisher/base_publisher.py
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
__init__
¶__init__(config)
Initialize the publisher with the given configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict[str, Any]
|
Configuration dictionary for the publisher. |
required |
Source code in agentflow/publisher/base_publisher.py
17 18 19 20 21 22 23 | |
close
abstractmethod
async
¶close()
Close the publisher and release any resources.
This method should be overridden by subclasses to provide specific cleanup logic. It will be called externally.
Source code in agentflow/publisher/base_publisher.py
37 38 39 40 41 42 43 44 | |
publish
abstractmethod
async
¶publish(event)
Publish an event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
¶ |
EventModel
|
The event to publish. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The result of the publish operation. |
Source code in agentflow/publisher/base_publisher.py
25 26 27 28 29 30 31 32 33 34 35 | |
sync_close
abstractmethod
¶sync_close()
Close the publisher and release any resources (synchronous version).
This method should be overridden by subclasses to provide specific cleanup logic. It will be called externally.
Source code in agentflow/publisher/base_publisher.py
46 47 48 49 50 51 52 53 | |
console_publisher
¶
Console publisher implementation for debugging and testing.
This module provides a publisher that outputs events to the console for development and debugging purposes.
Classes:
| Name | Description |
|---|---|
ConsolePublisher |
Publisher that prints events to the console for debugging and testing. |
Attributes:
| Name | Type | Description |
|---|---|---|
logger |
|
Attributes¶
Classes¶
ConsolePublisher
¶
Bases: BasePublisher
Publisher that prints events to the console for debugging and testing.
This publisher is useful for development and debugging purposes, as it outputs event information to the standard output.
Attributes:
| Name | Type | Description |
|---|---|---|
format |
Output format ('json' by default). |
|
include_timestamp |
Whether to include timestamp (True by default). |
|
indent |
Indentation for output (2 by default). |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the ConsolePublisher with the given configuration. |
close |
Close the publisher and release any resources. |
publish |
Publish an event to the console. |
sync_close |
Synchronously close the publisher and release any resources. |
Source code in agentflow/publisher/console_publisher.py
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 | |
include_timestamp
instance-attribute
¶include_timestamp = get('include_timestamp', True) if config else True
__init__
¶__init__(config=None)
Initialize the ConsolePublisher with the given configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict[str, Any] | None
|
Configuration dictionary. Supported keys: - format: Output format (default: 'json'). - include_timestamp: Whether to include timestamp (default: True). - indent: Indentation for output (default: 2). |
None
|
Source code in agentflow/publisher/console_publisher.py
29 30 31 32 33 34 35 36 37 38 39 40 41 | |
close
async
¶close()
Close the publisher and release any resources.
ConsolePublisher does not require cleanup, but this method is provided for interface compatibility.
Source code in agentflow/publisher/console_publisher.py
57 58 59 60 61 62 63 | |
publish
async
¶publish(event)
Publish an event to the console.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
¶ |
EventModel
|
The event to publish. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
None |
Source code in agentflow/publisher/console_publisher.py
43 44 45 46 47 48 49 50 51 52 53 54 55 | |
sync_close
¶sync_close()
Synchronously close the publisher and release any resources.
ConsolePublisher does not require cleanup, but this method is provided for interface compatibility.
Source code in agentflow/publisher/console_publisher.py
65 66 67 68 69 70 71 | |
events
¶
Event and streaming primitives for agent graph execution.
This module defines event types, content types, and the EventModel for structured streaming of execution updates, tool calls, state changes, messages, and errors in agent graphs.
Classes:
| Name | Description |
|---|---|
Event |
Enum for event sources (graph, node, tool, streaming). |
EventType |
Enum for event phases (start, progress, result, end, etc.). |
ContentType |
Enum for semantic content types (text, message, tool_call, etc.). |
EventModel |
Structured event chunk for streaming agent graph execution. |
Attributes¶
Classes¶
ContentType
¶
Bases: str, Enum
Enum for semantic content types in agent graph streaming.
Values
TEXT: Textual content. MESSAGE: Message content. REASONING: Reasoning content. TOOL_CALL: Tool call content. TOOL_RESULT: Tool result content. IMAGE: Image content. AUDIO: Audio content. VIDEO: Video content. DOCUMENT: Document content. DATA: Data content. STATE: State content. UPDATE: Update content. ERROR: Error content.
Attributes:
| Name | Type | Description |
|---|---|---|
AUDIO |
|
|
DATA |
|
|
DOCUMENT |
|
|
ERROR |
|
|
IMAGE |
|
|
MESSAGE |
|
|
REASONING |
|
|
STATE |
|
|
TEXT |
|
|
TOOL_CALL |
|
|
TOOL_RESULT |
|
|
UPDATE |
|
|
VIDEO |
|
Source code in agentflow/publisher/events.py
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 | |
Event
¶
Bases: str, Enum
Enum for event sources in agent graph execution.
Values
GRAPH_EXECUTION: Event from graph execution. NODE_EXECUTION: Event from node execution. TOOL_EXECUTION: Event from tool execution. STREAMING: Event from streaming updates.
Attributes:
| Name | Type | Description |
|---|---|---|
GRAPH_EXECUTION |
|
|
NODE_EXECUTION |
|
|
STREAMING |
|
|
TOOL_EXECUTION |
|
Source code in agentflow/publisher/events.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
EventModel
¶
Bases: BaseModel
Structured event chunk for streaming agent graph execution.
Represents a chunk of streamed data with event and content semantics, supporting both delta (incremental) and full content. Used for real-time streaming of execution updates, tool calls, state changes, messages, and errors.
Attributes:
| Name | Type | Description |
|---|---|---|
event |
Event
|
Type of the event source. |
event_type |
EventType
|
Phase of the event (start, progress, end, update). |
content |
str
|
Streamed textual content. |
content_blocks |
list[ContentBlock] | None
|
Structured content blocks for multimodal streaming. |
delta |
list[ContentBlock] | None
|
True if this is a delta update (incremental). |
delta_type |
list[ContentBlock] | None
|
Type of delta when delta=True. |
block_index |
list[ContentBlock] | None
|
Index of the content block this chunk applies to. |
chunk_index |
list[ContentBlock] | None
|
Per-block chunk index for ordering. |
byte_offset |
list[ContentBlock] | None
|
Byte offset for binary/media streaming. |
data |
dict[str, Any]
|
Additional structured data. |
content_type |
list[ContentType] | None
|
Semantic type of content. |
sequence_id |
list[ContentType] | None
|
Monotonic sequence ID for stream ordering. |
node_name |
str
|
Name of the node producing this chunk. |
run_id |
str
|
Unique ID for this stream/run. |
thread_id |
str | int
|
Thread ID for this execution. |
timestamp |
float
|
UNIX timestamp of when chunk was created. |
is_error |
bool
|
Marks this chunk as representing an error state. |
metadata |
dict[str, Any]
|
Optional metadata for consumers. |
Classes:
| Name | Description |
|---|---|
Config |
Pydantic configuration for EventModel. |
Methods:
| Name | Description |
|---|---|
default |
Create a default EventModel instance with minimal required fields. |
stream |
Create a default EventModel instance for streaming updates. |
Source code in agentflow/publisher/events.py
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 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 | |
content
class-attribute
instance-attribute
¶content = Field(default='', description='Streamed textual content')
content_blocks
class-attribute
instance-attribute
¶content_blocks = Field(default=None, description='Structured content blocks carried by this event')
content_type
class-attribute
instance-attribute
¶content_type = Field(default=None, description='Semantic type of content')
data
class-attribute
instance-attribute
¶data = Field(default_factory=dict, description='Additional structured data')
event
class-attribute
instance-attribute
¶event = Field(..., description='Type of the event source')
event_type
class-attribute
instance-attribute
¶event_type = Field(..., description='Phase of the event (start, progress, end, update)')
is_error
class-attribute
instance-attribute
¶is_error = Field(default=False, description='Marks this chunk as representing an error state')
metadata
class-attribute
instance-attribute
¶metadata = Field(default_factory=dict, description='Optional metadata for consumers')
node_name
class-attribute
instance-attribute
¶node_name = Field(default='', description='Name of the node producing this chunk')
run_id
class-attribute
instance-attribute
¶run_id = Field(default_factory=lambda: str(uuid4()), description='Unique ID for this stream/run')
thread_id
class-attribute
instance-attribute
¶thread_id = Field(default='', description='Thread ID for this execution')
timestamp
class-attribute
instance-attribute
¶timestamp = Field(default_factory=timestamp, description='UNIX timestamp of when chunk was created')
Config
¶Pydantic configuration for EventModel.
Attributes:
| Name | Type | Description |
|---|---|---|
use_enum_values |
Output enums as strings. |
Source code in agentflow/publisher/events.py
161 162 163 164 165 166 167 168 | |
default
classmethod
¶default(base_config, data, content_type, event=Event.GRAPH_EXECUTION, event_type=EventType.START, node_name='', extra=None)
Create a default EventModel instance with minimal required fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_config
¶ |
dict
|
Base configuration for the event (thread/run/timestamp/user). |
required |
data
¶ |
dict[str, Any]
|
Structured data payload. |
required |
content_type
¶ |
list[ContentType]
|
Semantic type(s) of content. |
required |
event
¶ |
Event
|
Event source type (default: GRAPH_EXECUTION). |
GRAPH_EXECUTION
|
event_type
¶ |
Event phase (default: START). |
START
|
|
node_name
¶ |
str
|
Name of the node producing the event. |
''
|
extra
¶ |
dict[str, Any] | None
|
Additional metadata. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
EventModel |
EventModel
|
The created event model instance. |
Source code in agentflow/publisher/events.py
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 | |
stream
classmethod
¶stream(base_config, node_name='', extra=None)
Create a default EventModel instance for streaming updates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_config
¶ |
dict
|
Base configuration for the event (thread/run/timestamp/user). |
required |
node_name
¶ |
str
|
Name of the node producing the event. |
''
|
extra
¶ |
dict[str, Any] | None
|
Additional metadata. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
EventModel |
EventModel
|
The created event model instance for streaming. |
Source code in agentflow/publisher/events.py
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 | |
EventType
¶
Bases: str, Enum
Enum for event phases in agent graph execution.
Values
START: Event marks start of execution. PROGRESS: Event marks progress update. RESULT: Event marks result produced. END: Event marks end of execution. UPDATE: Event marks update. ERROR: Event marks error. INTERRUPTED: Event marks interruption.
Attributes:
| Name | Type | Description |
|---|---|---|
END |
|
|
ERROR |
|
|
INTERRUPTED |
|
|
PROGRESS |
|
|
RESULT |
|
|
START |
|
|
UPDATE |
|
Source code in agentflow/publisher/events.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
kafka_publisher
¶
Kafka publisher implementation (optional dependency).
Uses aiokafka to publish events to a Kafka topic.
Dependency: aiokafka
Not installed by default; install extra: pip install 10xscale-agentflow[kafka].
Classes:
| Name | Description |
|---|---|
KafkaPublisher |
Publish events to a Kafka topic using aiokafka. |
Attributes:
| Name | Type | Description |
|---|---|---|
logger |
|
Attributes¶
Classes¶
KafkaPublisher
¶
Bases: BasePublisher
Publish events to a Kafka topic using aiokafka.
This class provides an asynchronous interface for publishing events to a Kafka topic. It uses the aiokafka library to handle the producer operations. The publisher is lazily initialized and can be reused for multiple publishes.
Attributes:
| Name | Type | Description |
|---|---|---|
bootstrap_servers |
str
|
Kafka bootstrap servers. |
topic |
str
|
Kafka topic to publish to. |
client_id |
str | None
|
Client ID for the producer. |
_producer |
Lazy-loaded Kafka producer instance. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the KafkaPublisher. |
close |
Close the Kafka producer. |
publish |
Publish an event to the Kafka topic. |
sync_close |
Synchronously close the Kafka producer. |
Source code in agentflow/publisher/kafka_publisher.py
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 | |
bootstrap_servers
instance-attribute
¶bootstrap_servers = get('bootstrap_servers', 'localhost:9092')
__init__
¶__init__(config=None)
Initialize the KafkaPublisher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict[str, Any] | None
|
Configuration dictionary. Supported keys: - bootstrap_servers: Kafka bootstrap servers (default: "localhost:9092"). - topic: Kafka topic to publish to (default: "agentflow.events"). - client_id: Client ID for the producer. |
None
|
Source code in agentflow/publisher/kafka_publisher.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
close
async
¶close()
Close the Kafka producer.
Stops the producer and cleans up resources. Errors during stopping are logged but do not raise exceptions.
Source code in agentflow/publisher/kafka_publisher.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
publish
async
¶publish(event)
Publish an event to the Kafka topic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
¶ |
EventModel
|
The event to publish. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The result of the send_and_wait operation. |
Source code in agentflow/publisher/kafka_publisher.py
84 85 86 87 88 89 90 91 92 93 94 95 | |
sync_close
¶sync_close()
Synchronously close the Kafka producer.
This method runs the async close in a new event loop. If called within an active event loop, it logs a warning and skips the operation.
Source code in agentflow/publisher/kafka_publisher.py
113 114 115 116 117 118 119 120 121 122 | |
publish
¶
Functions:
| Name | Description |
|---|---|
publish_event |
Publish an event asynchronously using the background task manager. |
Attributes:
| Name | Type | Description |
|---|---|---|
logger |
|
Attributes¶
Classes¶
Functions¶
publish_event
¶publish_event(event, publisher=Inject[BasePublisher], task_manager=Inject[BackgroundTaskManager])
Publish an event asynchronously using the background task manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
¶ |
EventModel
|
The event to publish. |
required |
publisher
¶ |
BasePublisher | None
|
The publisher instance (injected). |
Inject[BasePublisher]
|
task_manager
¶ |
BackgroundTaskManager
|
The background task manager (injected). |
Inject[BackgroundTaskManager]
|
Source code in agentflow/publisher/publish.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
rabbitmq_publisher
¶
RabbitMQ publisher implementation (optional dependency).
Uses aio-pika to publish events to an exchange with a routing key.
Dependency: aio-pika
Not installed by default; install extra: pip install 10xscale-agentflow[rabbitmq].
Classes:
| Name | Description |
|---|---|
RabbitMQPublisher |
Publish events to RabbitMQ using aio-pika. |
Attributes:
| Name | Type | Description |
|---|---|---|
logger |
|
Attributes¶
Classes¶
RabbitMQPublisher
¶
Bases: BasePublisher
Publish events to RabbitMQ using aio-pika.
Attributes:
| Name | Type | Description |
|---|---|---|
url |
str
|
RabbitMQ connection URL. |
exchange |
str
|
Exchange name. |
routing_key |
str
|
Routing key for messages. |
exchange_type |
str
|
Type of exchange. |
declare |
bool
|
Whether to declare the exchange. |
durable |
bool
|
Whether the exchange is durable. |
_conn |
Connection instance. |
|
_channel |
Channel instance. |
|
_exchange |
Exchange instance. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the RabbitMQPublisher. |
close |
Close the RabbitMQ connection and channel. |
publish |
Publish an event to RabbitMQ. |
sync_close |
Synchronously close the RabbitMQ connection. |
Source code in agentflow/publisher/rabbitmq_publisher.py
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 | |
__init__
¶__init__(config=None)
Initialize the RabbitMQPublisher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict[str, Any] | None
|
Configuration dictionary. Supported keys: - url: RabbitMQ URL (default: "amqp://guest:guest@localhost/"). - exchange: Exchange name (default: "agentflow.events"). - routing_key: Routing key (default: "agentflow.events"). - exchange_type: Exchange type (default: "topic"). - declare: Whether to declare exchange (default: True). - durable: Whether exchange is durable (default: True). |
None
|
Source code in agentflow/publisher/rabbitmq_publisher.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
close
async
¶close()
Close the RabbitMQ connection and channel.
Source code in agentflow/publisher/rabbitmq_publisher.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
publish
async
¶publish(event)
Publish an event to RabbitMQ.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
¶ |
EventModel
|
The event to publish. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
True on success. |
Source code in agentflow/publisher/rabbitmq_publisher.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
sync_close
¶sync_close()
Synchronously close the RabbitMQ connection.
Source code in agentflow/publisher/rabbitmq_publisher.py
131 132 133 134 135 136 | |
redis_publisher
¶
Redis publisher implementation (optional dependency).
This publisher uses the redis-py asyncio client to publish events via: - Pub/Sub channels (default), or - Redis Streams (XADD) when configured with mode="stream".
Dependency: redis>=4.2 (provides redis.asyncio).
Not installed by default; install extra: pip install 10xscale-agentflow[redis].
Classes:
| Name | Description |
|---|---|
RedisPublisher |
Publish events to Redis via Pub/Sub channel or Stream. |
Attributes:
| Name | Type | Description |
|---|---|---|
logger |
|
Attributes¶
Classes¶
RedisPublisher
¶
Bases: BasePublisher
Publish events to Redis via Pub/Sub channel or Stream.
Attributes:
| Name | Type | Description |
|---|---|---|
url |
str
|
Redis URL. |
mode |
str
|
Publishing mode ('pubsub' or 'stream'). |
channel |
str
|
Pub/Sub channel name. |
stream |
str
|
Stream name. |
maxlen |
int | None
|
Max length for streams. |
encoding |
str
|
Encoding for messages. |
_redis |
Redis client instance. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the RedisPublisher. |
close |
Close the Redis client. |
publish |
Publish an event to Redis. |
sync_close |
Synchronously close the Redis client. |
Source code in agentflow/publisher/redis_publisher.py
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 | |
__init__
¶__init__(config=None)
Initialize the RedisPublisher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
¶ |
dict[str, Any] | None
|
Configuration dictionary. Supported keys: - url: Redis URL (default: "redis://localhost:6379/0"). - mode: Publishing mode ('pubsub' or 'stream', default: 'pubsub'). - channel: Pub/Sub channel name (default: "agentflow.events"). - stream: Stream name (default: "agentflow.events"). - maxlen: Max length for streams. - encoding: Encoding (default: "utf-8"). |
None
|
Source code in agentflow/publisher/redis_publisher.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
close
async
¶close()
Close the Redis client.
Source code in agentflow/publisher/redis_publisher.py
114 115 116 117 118 119 120 121 122 123 | |
publish
async
¶publish(event)
Publish an event to Redis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
¶ |
EventModel
|
The event to publish. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The result of the publish operation. |
Source code in agentflow/publisher/redis_publisher.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
sync_close
¶sync_close()
Synchronously close the Redis client.
Source code in agentflow/publisher/redis_publisher.py
125 126 127 128 129 130 131 | |
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 |
|---|---|---|---|
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 | |
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 |
|---|---|---|---|
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 | |
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 |
|---|---|---|---|
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¶
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 |
|---|---|---|---|
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 | |
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 | |
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 | |
execution_meta
class-attribute
instance-attribute
¶execution_meta = Field(default_factory=lambda: ExecutionState(current_node=START))
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 | |
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 | |
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 | |
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 | |
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())
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 | |
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 |
|---|---|---|---|
default_id
¶ |
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 | |
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 | |
__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 |
|---|---|---|---|
left
¶ |
list[Message]
|
Existing list of messages. |
required |
right
¶ |
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 |
|---|---|---|---|
left
¶ |
list
|
Existing list of items (must have .id attribute). |
required |
right
¶ |
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 |
|---|---|---|---|
messages
¶ |
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 |
|---|---|---|---|
left
¶ |
list[Message]
|
Existing list of messages (ignored). |
required |
right
¶ |
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 |
|---|---|---|---|
left
¶ |
Existing value (ignored). |
required | |
right
¶ |
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 | |
timestamp
class-attribute
instance-attribute
¶timestamp = Field(default_factory=timestamp, description='UNIX timestamp of when chunk was created')
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 | |
store
¶
Modules:
| Name | Description |
|---|---|
base_store |
Simplified Async-First Base Store for TAF Framework |
embedding |
|
mem0_store |
Mem0 Long-Term Memory Store |
qdrant_store |
Qdrant Vector Store Implementation for TAF Framework |
store_schema |
|
Classes:
| Name | Description |
|---|---|
BaseEmbedding |
|
BaseStore |
Simplified async-first base class for memory stores in TAF. |
DistanceMetric |
Supported distance metrics for vector similarity. |
Mem0Store |
Mem0 implementation of long-term memory. |
MemoryRecord |
Comprehensive memory record for storage (Pydantic model). |
MemorySearchResult |
Result from a memory search operation (Pydantic model). |
MemoryType |
Types of memories that can be stored. |
OpenAIEmbedding |
|
QdrantStore |
Modern async-first Qdrant-based vector store implementation. |
Functions:
| Name | Description |
|---|---|
create_cloud_qdrant_store |
Create a cloud Qdrant store. |
create_local_qdrant_store |
Create a local Qdrant store. |
create_mem0_store |
Factory for a basic Mem0 long-term store. |
create_mem0_store_with_qdrant |
Factory producing a Mem0Store configured for Qdrant backing. |
create_remote_qdrant_store |
Create a remote Qdrant store. |
Attributes¶
__all__
module-attribute
¶
__all__ = ['BaseEmbedding', 'BaseStore', 'DistanceMetric', 'Mem0Store', 'MemoryRecord', 'MemorySearchResult', 'MemoryType', 'OpenAIEmbedding', 'QdrantStore', 'create_cloud_qdrant_store', 'create_local_qdrant_store', 'create_mem0_store', 'create_mem0_store_with_qdrant', 'create_remote_qdrant_store']
Classes¶
BaseEmbedding
¶
Bases: ABC
Methods:
| Name | Description |
|---|---|
aembed |
Generate embedding for a single text. |
aembed_batch |
Generate embeddings for a list of texts. |
embed |
Synchronous wrapper for |
embed_batch |
Synchronous wrapper for |
Attributes:
| Name | Type | Description |
|---|---|---|
dimension |
int
|
Synchronous wrapper for that runs the async implementation. |
Source code in agentflow/store/embedding/base_embedding.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 | |
Attributes¶
dimension
abstractmethod
property
¶dimension
Synchronous wrapper for that runs the async implementation.
Functions¶
aembed
abstractmethod
async
¶aembed(text)
Generate embedding for a single text.
Source code in agentflow/store/embedding/base_embedding.py
20 21 22 23 | |
aembed_batch
abstractmethod
async
¶aembed_batch(texts)
Generate embeddings for a list of texts.
Source code in agentflow/store/embedding/base_embedding.py
11 12 13 | |
embed
¶embed(text)
Synchronous wrapper for aembed that runs the async implementation.
Source code in agentflow/store/embedding/base_embedding.py
16 17 18 | |
embed_batch
¶embed_batch(texts)
Synchronous wrapper for aembed_batch that runs the async implementation.
Source code in agentflow/store/embedding/base_embedding.py
7 8 9 | |
BaseStore
¶
Bases: ABC
Simplified async-first base class for memory stores in TAF.
This class provides a clean interface that supports: - Vector stores (Qdrant, Pinecone, Chroma, etc.) - Managed memory services (mem0, Zep, etc.) - Graph databases (Neo4j, etc.)
Key Design Principles: - Async-first for better performance - Core CRUD operations only - User and agent-centric operations - Extensible filtering and metadata
Methods:
| Name | Description |
|---|---|
adelete |
Delete a memory by ID. |
aforget_memory |
Delete a memory by for a user or agent. |
aget |
Get a specific memory by ID. |
aget_all |
Get a specific memory by user_id. |
arelease |
Clean up any resources used by the store (override in subclasses if needed). |
asearch |
Search memories by content similarity. |
asetup |
Asynchronous setup method for checkpointer. |
astore |
Add a new memory. |
aupdate |
Update an existing memory. |
delete |
Synchronous wrapper for |
forget_memory |
Delete a memory by for a user or agent. |
get |
Synchronous wrapper for |
get_all |
Synchronous wrapper for |
release |
Clean up any resources used by the store (override in subclasses if needed). |
search |
Synchronous wrapper for |
setup |
Synchronous setup method for checkpointer. |
store |
Synchronous wrapper for |
update |
Synchronous wrapper for |
Source code in agentflow/store/base_store.py
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 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 | |
Functions¶
adelete
abstractmethod
async
¶adelete(config, memory_id, **kwargs)
Delete a memory by ID.
Source code in agentflow/store/base_store.py
238 239 240 241 242 243 244 245 246 | |
aforget_memory
abstractmethod
async
¶aforget_memory(config, **kwargs)
Delete a memory by for a user or agent.
Source code in agentflow/store/base_store.py
252 253 254 255 256 257 258 259 | |
aget
abstractmethod
async
¶aget(config, memory_id, **kwargs)
Get a specific memory by ID.
Source code in agentflow/store/base_store.py
174 175 176 177 178 179 180 181 182 | |
aget_all
abstractmethod
async
¶aget_all(config, limit=100, **kwargs)
Get a specific memory by user_id.
Source code in agentflow/store/base_store.py
184 185 186 187 188 189 190 191 192 | |
arelease
async
¶arelease()
Clean up any resources used by the store (override in subclasses if needed).
Source code in agentflow/store/base_store.py
271 272 273 | |
asearch
abstractmethod
async
¶asearch(config, query, memory_type=None, category=None, limit=10, score_threshold=None, filters=None, retrieval_strategy=RetrievalStrategy.SIMILARITY, distance_metric=DistanceMetric.COSINE, max_tokens=4000, **kwargs)
Search memories by content similarity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
¶ |
str
|
Search query |
required |
user_id
¶ |
Filter by user |
required | |
agent_id
¶ |
Filter by agent |
required | |
memory_type
¶ |
MemoryType | None
|
Filter by memory type |
None
|
category
¶ |
str | None
|
Filter by category |
None
|
limit
¶ |
int
|
Maximum results |
10
|
score_threshold
¶ |
float | None
|
Minimum similarity score |
None
|
filters
¶ |
dict[str, Any] | None
|
Additional filters |
None
|
**kwargs
¶ |
Store-specific parameters |
{}
|
Returns:
| Type | Description |
|---|---|
list[MemorySearchResult]
|
List of matching memories |
Source code in agentflow/store/base_store.py
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 | |
asetup
async
¶asetup()
Asynchronous setup method for checkpointer.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Implementation-defined setup result. |
Source code in agentflow/store/base_store.py
49 50 51 52 53 54 55 56 | |
astore
abstractmethod
async
¶astore(config, content, memory_type=MemoryType.EPISODIC, category='general', metadata=None, **kwargs)
Add a new memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
¶ |
str | Message
|
The memory content |
required |
user_id
¶ |
User identifier |
required | |
agent_id
¶ |
Agent identifier |
required | |
memory_type
¶ |
MemoryType
|
Type of memory (episodic, semantic, etc.) |
EPISODIC
|
category
¶ |
str
|
Memory category for organization |
'general'
|
metadata
¶ |
dict[str, Any] | None
|
Additional metadata |
None
|
**kwargs
¶ |
Store-specific parameters |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
Memory ID |
Source code in agentflow/store/base_store.py
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 | |
aupdate
abstractmethod
async
¶aupdate(config, memory_id, content, metadata=None, **kwargs)
Update an existing memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
memory_id
¶ |
str
|
ID of memory to update |
required |
content
¶ |
str | Message
|
New content (optional) |
required |
metadata
¶ |
dict[str, Any] | None
|
New/additional metadata (optional) |
None
|
**kwargs
¶ |
Store-specific parameters |
{}
|
Source code in agentflow/store/base_store.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
delete
¶delete(config, memory_id, **kwargs)
Synchronous wrapper for adelete that runs the async implementation.
Source code in agentflow/store/base_store.py
248 249 250 | |
forget_memory
¶forget_memory(config, **kwargs)
Delete a memory by for a user or agent.
Source code in agentflow/store/base_store.py
261 262 263 264 265 266 267 | |
get
¶get(config, memory_id, **kwargs)
Synchronous wrapper for aget that runs the async implementation.
Source code in agentflow/store/base_store.py
194 195 196 | |
get_all
¶get_all(config, limit=100, **kwargs)
Synchronous wrapper for aget that runs the async implementation.
Source code in agentflow/store/base_store.py
198 199 200 201 202 203 204 205 | |
release
¶release()
Clean up any resources used by the store (override in subclasses if needed).
Source code in agentflow/store/base_store.py
275 276 277 | |
search
¶search(config, query, memory_type=None, category=None, limit=10, score_threshold=None, filters=None, retrieval_strategy=RetrievalStrategy.SIMILARITY, distance_metric=DistanceMetric.COSINE, max_tokens=4000, **kwargs)
Synchronous wrapper for asearch that runs the async implementation.
Source code in agentflow/store/base_store.py
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 | |
setup
¶setup()
Synchronous setup method for checkpointer.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Implementation-defined setup result. |
Source code in agentflow/store/base_store.py
40 41 42 43 44 45 46 47 | |
store
¶store(config, content, memory_type=MemoryType.EPISODIC, category='general', metadata=None, **kwargs)
Synchronous wrapper for astore that runs the async implementation.
Source code in agentflow/store/base_store.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
update
¶update(config, memory_id, content, metadata=None, **kwargs)
Synchronous wrapper for aupdate that runs the async implementation.
Source code in agentflow/store/base_store.py
227 228 229 230 231 232 233 234 235 236 | |
DistanceMetric
¶
Bases: Enum
Supported distance metrics for vector similarity.
Attributes:
| Name | Type | Description |
|---|---|---|
COSINE |
|
|
DOT_PRODUCT |
|
|
EUCLIDEAN |
|
|
MANHATTAN |
|
Source code in agentflow/store/store_schema.py
21 22 23 24 25 26 27 | |
Mem0Store
¶
Bases: BaseStore
Mem0 implementation of long-term memory.
Primary responsibilities:
* Persist memories (episodic by default) across graph invocations
* Retrieve semantically similar memories to augment state
* Provide CRUD lifecycle aligned with BaseStore async API
Unlike in-memory state, these memories survive process restarts as they are managed by Mem0's configured vector / persistence layer.
Methods:
| Name | Description |
|---|---|
__init__ |
|
adelete |
|
aforget_memory |
|
aget |
|
aget_all |
|
arelease |
|
asearch |
|
asetup |
Asynchronous setup method for checkpointer. |
astore |
|
aupdate |
|
delete |
Synchronous wrapper for |
forget_memory |
Delete a memory by for a user or agent. |
generate_framework_id |
|
get |
Synchronous wrapper for |
get_all |
Synchronous wrapper for |
release |
Clean up any resources used by the store (override in subclasses if needed). |
search |
Synchronous wrapper for |
setup |
Synchronous setup method for checkpointer. |
store |
Synchronous wrapper for |
update |
Synchronous wrapper for |
Attributes:
| Name | Type | Description |
|---|---|---|
app_id |
|
|
config |
|
Source code in agentflow/store/mem0_store.py
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 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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 | |
Attributes¶
Functions¶
__init__
¶__init__(config, app_id=None, **kwargs)
Source code in agentflow/store/mem0_store.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
adelete
async
¶adelete(config, memory_id, **kwargs)
Source code in agentflow/store/mem0_store.py
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 | |
aforget_memory
async
¶aforget_memory(config, **kwargs)
Source code in agentflow/store/mem0_store.py
373 374 375 376 377 378 379 380 381 382 383 | |
aget
async
¶aget(config, memory_id, **kwargs)
Source code in agentflow/store/mem0_store.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
aget_all
async
¶aget_all(config, limit=100, **kwargs)
Source code in agentflow/store/mem0_store.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | |
arelease
async
¶arelease()
Source code in agentflow/store/mem0_store.py
385 386 | |
asearch
async
¶asearch(config, query, memory_type=None, category=None, limit=10, score_threshold=None, filters=None, retrieval_strategy=None, distance_metric=None, max_tokens=4000, **kwargs)
Source code in agentflow/store/mem0_store.py
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 | |
asetup
async
¶asetup()
Asynchronous setup method for checkpointer.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Implementation-defined setup result. |
Source code in agentflow/store/base_store.py
49 50 51 52 53 54 55 56 | |
astore
async
¶astore(config, content, memory_type=MemoryType.EPISODIC, category='general', metadata=None, **kwargs)
Source code in agentflow/store/mem0_store.py
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 | |
aupdate
async
¶aupdate(config, memory_id, content, metadata=None, **kwargs)
Source code in agentflow/store/mem0_store.py
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 | |
delete
¶delete(config, memory_id, **kwargs)
Synchronous wrapper for adelete that runs the async implementation.
Source code in agentflow/store/base_store.py
248 249 250 | |
forget_memory
¶forget_memory(config, **kwargs)
Delete a memory by for a user or agent.
Source code in agentflow/store/base_store.py
261 262 263 264 265 266 267 | |
generate_framework_id
async
¶generate_framework_id()
Source code in agentflow/store/mem0_store.py
173 174 175 176 177 | |
get
¶get(config, memory_id, **kwargs)
Synchronous wrapper for aget that runs the async implementation.
Source code in agentflow/store/base_store.py
194 195 196 | |
get_all
¶get_all(config, limit=100, **kwargs)
Synchronous wrapper for aget that runs the async implementation.
Source code in agentflow/store/base_store.py
198 199 200 201 202 203 204 205 | |
release
¶release()
Clean up any resources used by the store (override in subclasses if needed).
Source code in agentflow/store/base_store.py
275 276 277 | |
search
¶search(config, query, memory_type=None, category=None, limit=10, score_threshold=None, filters=None, retrieval_strategy=RetrievalStrategy.SIMILARITY, distance_metric=DistanceMetric.COSINE, max_tokens=4000, **kwargs)
Synchronous wrapper for asearch that runs the async implementation.
Source code in agentflow/store/base_store.py
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 | |
setup
¶setup()
Synchronous setup method for checkpointer.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Implementation-defined setup result. |
Source code in agentflow/store/base_store.py
40 41 42 43 44 45 46 47 | |
store
¶store(config, content, memory_type=MemoryType.EPISODIC, category='general', metadata=None, **kwargs)
Synchronous wrapper for astore that runs the async implementation.
Source code in agentflow/store/base_store.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
update
¶update(config, memory_id, content, metadata=None, **kwargs)
Synchronous wrapper for aupdate that runs the async implementation.
Source code in agentflow/store/base_store.py
227 228 229 230 231 232 233 234 235 236 | |
MemoryRecord
¶
Bases: BaseModel
Comprehensive memory record for storage (Pydantic model).
Methods:
| Name | Description |
|---|---|
from_message |
|
validate_vector |
|
Attributes:
| Name | Type | Description |
|---|---|---|
category |
str
|
|
content |
str
|
|
id |
str
|
|
memory_type |
MemoryType
|
|
metadata |
dict[str, Any]
|
|
thread_id |
str | None
|
|
timestamp |
datetime | None
|
|
user_id |
str | None
|
|
vector |
list[float] | None
|
|
Source code in agentflow/store/store_schema.py
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 | |
Attributes¶
Functions¶
from_message
classmethod
¶from_message(message, user_id=None, thread_id=None, vector=None, additional_metadata=None)
Source code in agentflow/store/store_schema.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 119 120 | |
validate_vector
classmethod
¶validate_vector(v)
Source code in agentflow/store/store_schema.py
78 79 80 81 82 83 84 85 | |
MemorySearchResult
¶
Bases: BaseModel
Result from a memory search operation (Pydantic model).
Methods:
| Name | Description |
|---|---|
validate_vector |
|
Attributes:
| Name | Type | Description |
|---|---|---|
content |
str
|
|
id |
str
|
|
memory_type |
MemoryType
|
|
metadata |
dict[str, Any]
|
|
score |
float
|
|
thread_id |
str | None
|
|
timestamp |
datetime | None
|
|
user_id |
str | None
|
|
vector |
list[float] | None
|
|
Source code in agentflow/store/store_schema.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
Attributes¶
content
class-attribute
instance-attribute
¶content = Field(default='', description='Primary textual content of the memory')
score
class-attribute
instance-attribute
¶score = Field(default=0.0, ge=0.0, description='Similarity / relevance score')
Functions¶
validate_vector
classmethod
¶validate_vector(v)
Source code in agentflow/store/store_schema.py
55 56 57 58 59 60 61 62 | |
MemoryType
¶
Bases: Enum
Types of memories that can be stored.
Attributes:
| Name | Type | Description |
|---|---|---|
CUSTOM |
|
|
DECLARATIVE |
|
|
ENTITY |
|
|
EPISODIC |
|
|
PROCEDURAL |
|
|
RELATIONSHIP |
|
|
SEMANTIC |
|
Source code in agentflow/store/store_schema.py
30 31 32 33 34 35 36 37 38 39 | |
Attributes¶
OpenAIEmbedding
¶
Bases: BaseEmbedding
Methods:
| Name | Description |
|---|---|
__init__ |
|
aembed |
|
aembed_batch |
|
embed |
Synchronous wrapper for |
embed_batch |
Synchronous wrapper for |
Attributes:
| Name | Type | Description |
|---|---|---|
api_key |
|
|
client |
|
|
dimension |
int
|
|
model |
|
Source code in agentflow/store/embedding/openai_embedding.py
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 | |
Attributes¶
Functions¶
__init__
¶__init__(model='text-embedding-3-small', api_key=None)
Source code in agentflow/store/embedding/openai_embedding.py
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 | |
aembed
async
¶aembed(text)
Source code in agentflow/store/embedding/openai_embedding.py
55 56 57 58 59 60 61 62 63 64 65 | |
aembed_batch
async
¶aembed_batch(texts)
Source code in agentflow/store/embedding/openai_embedding.py
43 44 45 46 47 48 49 50 51 52 53 | |
embed
¶embed(text)
Synchronous wrapper for aembed that runs the async implementation.
Source code in agentflow/store/embedding/base_embedding.py
16 17 18 | |
embed_batch
¶embed_batch(texts)
Synchronous wrapper for aembed_batch that runs the async implementation.
Source code in agentflow/store/embedding/base_embedding.py
7 8 9 | |
QdrantStore
¶
Bases: BaseStore
Modern async-first Qdrant-based vector store implementation.
Features: - Async-only operations for better performance - Local and cloud Qdrant deployment support - Configurable embedding services - Efficient vector similarity search with multiple strategies - Collection management with automatic creation - Rich metadata filtering capabilities - User and agent-scoped operations
Example
# Local Qdrant with OpenAI embeddings
store = QdrantStore(path="./qdrant_data", embedding_service=OpenAIEmbeddingService())
# Remote Qdrant
store = QdrantStore(host="localhost", port=6333, embedding_service=OpenAIEmbeddingService())
# Cloud Qdrant
store = QdrantStore(
url="https://xyz.qdrant.io",
api_key="your-api-key",
embedding_service=OpenAIEmbeddingService(),
)
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize Qdrant vector store. |
adelete |
Delete a memory by ID. |
aforget_memory |
Delete all memories for a user or agent. |
aget |
Get a specific memory by ID. |
aget_all |
Get all memories for a user. |
arelease |
Clean up resources. |
asearch |
Search memories by content similarity. |
asetup |
Set up the store and ensure default collection exists. |
astore |
Store a new memory. |
aupdate |
Update an existing memory. |
delete |
Synchronous wrapper for |
forget_memory |
Delete a memory by for a user or agent. |
get |
Synchronous wrapper for |
get_all |
Synchronous wrapper for |
release |
Clean up any resources used by the store (override in subclasses if needed). |
search |
Synchronous wrapper for |
setup |
Synchronous setup method for checkpointer. |
store |
Synchronous wrapper for |
update |
Synchronous wrapper for |
Attributes:
| Name | Type | Description |
|---|---|---|
client |
|
|
default_collection |
|
|
embedding |
|
Source code in agentflow/store/qdrant_store.py
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 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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 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 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 | |
Attributes¶
Functions¶
__init__
¶__init__(embedding, path=None, host=None, port=None, url=None, api_key=None, default_collection='agentflow_memories', distance_metric=DistanceMetric.COSINE, **kwargs)
Initialize Qdrant vector store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embedding
¶ |
BaseEmbedding
|
Service for generating embeddings |
required |
path
¶ |
str | None
|
Path for local Qdrant (file-based storage) |
None
|
host
¶ |
str | None
|
Host for remote Qdrant server |
None
|
port
¶ |
int | None
|
Port for remote Qdrant server |
None
|
url
¶ |
str | None
|
URL for Qdrant cloud |
None
|
api_key
¶ |
str | None
|
API key for Qdrant cloud |
None
|
default_collection
¶ |
str
|
Default collection name |
'agentflow_memories'
|
distance_metric
¶ |
DistanceMetric
|
Default distance metric |
COSINE
|
**kwargs
¶ |
Any
|
Additional client parameters |
{}
|
Source code in agentflow/store/qdrant_store.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 112 113 114 115 116 117 118 119 120 121 | |
adelete
async
¶adelete(config, memory_id, **kwargs)
Delete a memory by ID.
Source code in agentflow/store/qdrant_store.py
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | |
aforget_memory
async
¶aforget_memory(config, **kwargs)
Delete all memories for a user or agent.
Source code in agentflow/store/qdrant_store.py
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 | |
aget
async
¶aget(config, memory_id, **kwargs)
Get a specific memory by ID.
Source code in agentflow/store/qdrant_store.py
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 | |
aget_all
async
¶aget_all(config, limit=100, **kwargs)
Get all memories for a user.
Source code in agentflow/store/qdrant_store.py
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 | |
arelease
async
¶arelease()
Clean up resources.
Source code in agentflow/store/qdrant_store.py
595 596 597 598 599 | |
asearch
async
¶asearch(config, query, memory_type=None, category=None, limit=10, score_threshold=None, filters=None, retrieval_strategy=RetrievalStrategy.SIMILARITY, distance_metric=DistanceMetric.COSINE, max_tokens=4000, **kwargs)
Search memories by content similarity.
Source code in agentflow/store/qdrant_store.py
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | |
asetup
async
¶asetup()
Set up the store and ensure default collection exists.
Source code in agentflow/store/qdrant_store.py
123 124 125 126 127 | |
astore
async
¶astore(config, content, memory_type=MemoryType.EPISODIC, category='general', metadata=None, **kwargs)
Store a new memory.
Source code in agentflow/store/qdrant_store.py
301 302 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 | |
aupdate
async
¶aupdate(config, memory_id, content, metadata=None, **kwargs)
Update an existing memory.
Source code in agentflow/store/qdrant_store.py
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 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 533 534 535 536 | |
delete
¶delete(config, memory_id, **kwargs)
Synchronous wrapper for adelete that runs the async implementation.
Source code in agentflow/store/base_store.py
248 249 250 | |
forget_memory
¶forget_memory(config, **kwargs)
Delete a memory by for a user or agent.
Source code in agentflow/store/base_store.py
261 262 263 264 265 266 267 | |
get
¶get(config, memory_id, **kwargs)
Synchronous wrapper for aget that runs the async implementation.
Source code in agentflow/store/base_store.py
194 195 196 | |
get_all
¶get_all(config, limit=100, **kwargs)
Synchronous wrapper for aget that runs the async implementation.
Source code in agentflow/store/base_store.py
198 199 200 201 202 203 204 205 | |
release
¶release()
Clean up any resources used by the store (override in subclasses if needed).
Source code in agentflow/store/base_store.py
275 276 277 | |
search
¶search(config, query, memory_type=None, category=None, limit=10, score_threshold=None, filters=None, retrieval_strategy=RetrievalStrategy.SIMILARITY, distance_metric=DistanceMetric.COSINE, max_tokens=4000, **kwargs)
Synchronous wrapper for asearch that runs the async implementation.
Source code in agentflow/store/base_store.py
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 | |
setup
¶setup()
Synchronous setup method for checkpointer.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Implementation-defined setup result. |
Source code in agentflow/store/base_store.py
40 41 42 43 44 45 46 47 | |
store
¶store(config, content, memory_type=MemoryType.EPISODIC, category='general', metadata=None, **kwargs)
Synchronous wrapper for astore that runs the async implementation.
Source code in agentflow/store/base_store.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
update
¶update(config, memory_id, content, metadata=None, **kwargs)
Synchronous wrapper for aupdate that runs the async implementation.
Source code in agentflow/store/base_store.py
227 228 229 230 231 232 233 234 235 236 | |
Functions¶
create_cloud_qdrant_store
¶
create_cloud_qdrant_store(url, api_key, embedding, **kwargs)
Create a cloud Qdrant store.
Source code in agentflow/store/qdrant_store.py
633 634 635 636 637 638 639 640 641 642 643 644 645 | |
create_local_qdrant_store
¶
create_local_qdrant_store(path, embedding, **kwargs)
Create a local Qdrant store.
Source code in agentflow/store/qdrant_store.py
605 606 607 608 609 610 611 612 613 614 615 | |
create_mem0_store
¶
create_mem0_store(config, user_id='default_user', thread_id=None, app_id='agentflow_app')
Factory for a basic Mem0 long-term store.
Source code in agentflow/store/mem0_store.py
392 393 394 395 396 397 398 399 400 401 402 403 404 | |
create_mem0_store_with_qdrant
¶
create_mem0_store_with_qdrant(qdrant_url, qdrant_api_key=None, collection_name='agentflow_memories', embedding_model='text-embedding-ada-002', llm_model='gpt-4o-mini', app_id='agentflow_app', **kwargs)
Factory producing a Mem0Store configured for Qdrant backing.
Source code in agentflow/store/mem0_store.py
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 | |
create_remote_qdrant_store
¶
create_remote_qdrant_store(host, port, embedding, **kwargs)
Create a remote Qdrant store.
Source code in agentflow/store/qdrant_store.py
618 619 620 621 622 623 624 625 626 627 628 629 630 | |
Modules¶
base_store
¶
Simplified Async-First Base Store for TAF Framework
This module provides a clean, modern interface for memory stores with: - Async-first design for better performance - Core CRUD operations only - Message-specific convenience methods - Extensible for different backends (vector stores, managed services, etc.)
Classes:
| Name | Description |
|---|---|
BaseStore |
Simplified async-first base class for memory stores in TAF. |
Attributes:
| Name | Type | Description |
|---|---|---|
logger |
|
Attributes¶
Classes¶
BaseStore
¶
Bases: ABC
Simplified async-first base class for memory stores in TAF.
This class provides a clean interface that supports: - Vector stores (Qdrant, Pinecone, Chroma, etc.) - Managed memory services (mem0, Zep, etc.) - Graph databases (Neo4j, etc.)
Key Design Principles: - Async-first for better performance - Core CRUD operations only - User and agent-centric operations - Extensible filtering and metadata
Methods:
| Name | Description |
|---|---|
adelete |
Delete a memory by ID. |
aforget_memory |
Delete a memory by for a user or agent. |
aget |
Get a specific memory by ID. |
aget_all |
Get a specific memory by user_id. |
arelease |
Clean up any resources used by the store (override in subclasses if needed). |
asearch |
Search memories by content similarity. |
asetup |
Asynchronous setup method for checkpointer. |
astore |
Add a new memory. |
aupdate |
Update an existing memory. |
delete |
Synchronous wrapper for |
forget_memory |
Delete a memory by for a user or agent. |
get |
Synchronous wrapper for |
get_all |
Synchronous wrapper for |
release |
Clean up any resources used by the store (override in subclasses if needed). |
search |
Synchronous wrapper for |
setup |
Synchronous setup method for checkpointer. |
store |
Synchronous wrapper for |
update |
Synchronous wrapper for |
Source code in agentflow/store/base_store.py
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 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 | |
adelete
abstractmethod
async
¶adelete(config, memory_id, **kwargs)
Delete a memory by ID.
Source code in agentflow/store/base_store.py
238 239 240 241 242 243 244 245 246 | |
aforget_memory
abstractmethod
async
¶aforget_memory(config, **kwargs)
Delete a memory by for a user or agent.
Source code in agentflow/store/base_store.py
252 253 254 255 256 257 258 259 | |
aget
abstractmethod
async
¶aget(config, memory_id, **kwargs)
Get a specific memory by ID.
Source code in agentflow/store/base_store.py
174 175 176 177 178 179 180 181 182 | |
aget_all
abstractmethod
async
¶aget_all(config, limit=100, **kwargs)
Get a specific memory by user_id.
Source code in agentflow/store/base_store.py
184 185 186 187 188 189 190 191 192 | |
arelease
async
¶arelease()
Clean up any resources used by the store (override in subclasses if needed).
Source code in agentflow/store/base_store.py
271 272 273 | |
asearch
abstractmethod
async
¶asearch(config, query, memory_type=None, category=None, limit=10, score_threshold=None, filters=None, retrieval_strategy=RetrievalStrategy.SIMILARITY, distance_metric=DistanceMetric.COSINE, max_tokens=4000, **kwargs)
Search memories by content similarity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
¶ |
str
|
Search query |
required |
user_id
¶ |
Filter by user |
required | |
agent_id
¶ |
Filter by agent |
required | |
memory_type
¶ |
MemoryType | None
|
Filter by memory type |
None
|
category
¶ |
str | None
|
Filter by category |
None
|
limit
¶ |
int
|
Maximum results |
10
|
score_threshold
¶ |
float | None
|
Minimum similarity score |
None
|
filters
¶ |
dict[str, Any] | None
|
Additional filters |
None
|
**kwargs
¶ |
Store-specific parameters |
{}
|
Returns:
| Type | Description |
|---|---|
list[MemorySearchResult]
|
List of matching memories |
Source code in agentflow/store/base_store.py
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 | |
asetup
async
¶asetup()
Asynchronous setup method for checkpointer.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Implementation-defined setup result. |
Source code in agentflow/store/base_store.py
49 50 51 52 53 54 55 56 | |
astore
abstractmethod
async
¶astore(config, content, memory_type=MemoryType.EPISODIC, category='general', metadata=None, **kwargs)
Add a new memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
¶ |
str | Message
|
The memory content |
required |
user_id
¶ |
User identifier |
required | |
agent_id
¶ |
Agent identifier |
required | |
memory_type
¶ |
MemoryType
|
Type of memory (episodic, semantic, etc.) |
EPISODIC
|
category
¶ |
str
|
Memory category for organization |
'general'
|
metadata
¶ |
dict[str, Any] | None
|
Additional metadata |
None
|
**kwargs
¶ |
Store-specific parameters |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
Memory ID |
Source code in agentflow/store/base_store.py
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 | |
aupdate
abstractmethod
async
¶aupdate(config, memory_id, content, metadata=None, **kwargs)
Update an existing memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
memory_id
¶ |
str
|
ID of memory to update |
required |
content
¶ |
str | Message
|
New content (optional) |
required |
metadata
¶ |
dict[str, Any] | None
|
New/additional metadata (optional) |
None
|
**kwargs
¶ |
Store-specific parameters |
{}
|
Source code in agentflow/store/base_store.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
delete
¶delete(config, memory_id, **kwargs)
Synchronous wrapper for adelete that runs the async implementation.
Source code in agentflow/store/base_store.py
248 249 250 | |
forget_memory
¶forget_memory(config, **kwargs)
Delete a memory by for a user or agent.
Source code in agentflow/store/base_store.py
261 262 263 264 265 266 267 | |
get
¶get(config, memory_id, **kwargs)
Synchronous wrapper for aget that runs the async implementation.
Source code in agentflow/store/base_store.py
194 195 196 | |
get_all
¶get_all(config, limit=100, **kwargs)
Synchronous wrapper for aget that runs the async implementation.
Source code in agentflow/store/base_store.py
198 199 200 201 202 203 204 205 | |
release
¶release()
Clean up any resources used by the store (override in subclasses if needed).
Source code in agentflow/store/base_store.py
275 276 277 | |
search
¶search(config, query, memory_type=None, category=None, limit=10, score_threshold=None, filters=None, retrieval_strategy=RetrievalStrategy.SIMILARITY, distance_metric=DistanceMetric.COSINE, max_tokens=4000, **kwargs)
Synchronous wrapper for asearch that runs the async implementation.
Source code in agentflow/store/base_store.py
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 | |
setup
¶setup()
Synchronous setup method for checkpointer.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Implementation-defined setup result. |
Source code in agentflow/store/base_store.py
40 41 42 43 44 45 46 47 | |
store
¶store(config, content, memory_type=MemoryType.EPISODIC, category='general', metadata=None, **kwargs)
Synchronous wrapper for astore that runs the async implementation.
Source code in agentflow/store/base_store.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
update
¶update(config, memory_id, content, metadata=None, **kwargs)
Synchronous wrapper for aupdate that runs the async implementation.
Source code in agentflow/store/base_store.py
227 228 229 230 231 232 233 234 235 236 | |
Functions¶
embedding
¶
Modules:
| Name | Description |
|---|---|
base_embedding |
|
openai_embedding |
|
Classes:
| Name | Description |
|---|---|
BaseEmbedding |
|
OpenAIEmbedding |
|
Attributes¶
Classes¶
BaseEmbedding
¶
Bases: ABC
Methods:
| Name | Description |
|---|---|
aembed |
Generate embedding for a single text. |
aembed_batch |
Generate embeddings for a list of texts. |
embed |
Synchronous wrapper for |
embed_batch |
Synchronous wrapper for |
Attributes:
| Name | Type | Description |
|---|---|---|
dimension |
int
|
Synchronous wrapper for that runs the async implementation. |
Source code in agentflow/store/embedding/base_embedding.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 | |
dimension
abstractmethod
property
¶dimension
Synchronous wrapper for that runs the async implementation.
aembed
abstractmethod
async
¶aembed(text)
Generate embedding for a single text.
Source code in agentflow/store/embedding/base_embedding.py
20 21 22 23 | |
aembed_batch
abstractmethod
async
¶aembed_batch(texts)
Generate embeddings for a list of texts.
Source code in agentflow/store/embedding/base_embedding.py
11 12 13 | |
embed
¶embed(text)
Synchronous wrapper for aembed that runs the async implementation.
Source code in agentflow/store/embedding/base_embedding.py
16 17 18 | |
embed_batch
¶embed_batch(texts)
Synchronous wrapper for aembed_batch that runs the async implementation.
Source code in agentflow/store/embedding/base_embedding.py
7 8 9 | |
OpenAIEmbedding
¶
Bases: BaseEmbedding
Methods:
| Name | Description |
|---|---|
__init__ |
|
aembed |
|
aembed_batch |
|
embed |
Synchronous wrapper for |
embed_batch |
Synchronous wrapper for |
Attributes:
| Name | Type | Description |
|---|---|---|
api_key |
|
|
client |
|
|
dimension |
int
|
|
model |
|
Source code in agentflow/store/embedding/openai_embedding.py
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 | |
__init__
¶__init__(model='text-embedding-3-small', api_key=None)
Source code in agentflow/store/embedding/openai_embedding.py
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 | |
aembed
async
¶aembed(text)
Source code in agentflow/store/embedding/openai_embedding.py
55 56 57 58 59 60 61 62 63 64 65 | |
aembed_batch
async
¶aembed_batch(texts)
Source code in agentflow/store/embedding/openai_embedding.py
43 44 45 46 47 48 49 50 51 52 53 | |
embed
¶embed(text)
Synchronous wrapper for aembed that runs the async implementation.
Source code in agentflow/store/embedding/base_embedding.py
16 17 18 | |
embed_batch
¶embed_batch(texts)
Synchronous wrapper for aembed_batch that runs the async implementation.
Source code in agentflow/store/embedding/base_embedding.py
7 8 9 | |
Modules¶
base_embedding
¶Classes:
| Name | Description |
|---|---|
BaseEmbedding |
|
BaseEmbedding
¶
Bases: ABC
Methods:
| Name | Description |
|---|---|
aembed |
Generate embedding for a single text. |
aembed_batch |
Generate embeddings for a list of texts. |
embed |
Synchronous wrapper for |
embed_batch |
Synchronous wrapper for |
Attributes:
| Name | Type | Description |
|---|---|---|
dimension |
int
|
Synchronous wrapper for that runs the async implementation. |
Source code in agentflow/store/embedding/base_embedding.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 | |
dimension
abstractmethod
property
¶dimension
Synchronous wrapper for that runs the async implementation.
aembed
abstractmethod
async
¶aembed(text)
Generate embedding for a single text.
Source code in agentflow/store/embedding/base_embedding.py
20 21 22 23 | |
aembed_batch
abstractmethod
async
¶aembed_batch(texts)
Generate embeddings for a list of texts.
Source code in agentflow/store/embedding/base_embedding.py
11 12 13 | |
embed
¶embed(text)
Synchronous wrapper for aembed that runs the async implementation.
Source code in agentflow/store/embedding/base_embedding.py
16 17 18 | |
embed_batch
¶embed_batch(texts)
Synchronous wrapper for aembed_batch that runs the async implementation.
Source code in agentflow/store/embedding/base_embedding.py
7 8 9 | |
openai_embedding
¶Classes:
| Name | Description |
|---|---|
OpenAIEmbedding |
|
Attributes:
| Name | Type | Description |
|---|---|---|
HAS_OPENAI |
|
OpenAIEmbedding
¶
Bases: BaseEmbedding
Methods:
| Name | Description |
|---|---|
__init__ |
|
aembed |
|
aembed_batch |
|
embed |
Synchronous wrapper for |
embed_batch |
Synchronous wrapper for |
Attributes:
| Name | Type | Description |
|---|---|---|
api_key |
|
|
client |
|
|
dimension |
int
|
|
model |
|
Source code in agentflow/store/embedding/openai_embedding.py
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 | |
__init__
¶__init__(model='text-embedding-3-small', api_key=None)
Source code in agentflow/store/embedding/openai_embedding.py
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 | |
aembed
async
¶aembed(text)
Source code in agentflow/store/embedding/openai_embedding.py
55 56 57 58 59 60 61 62 63 64 65 | |
aembed_batch
async
¶aembed_batch(texts)
Source code in agentflow/store/embedding/openai_embedding.py
43 44 45 46 47 48 49 50 51 52 53 | |
embed
¶embed(text)
Synchronous wrapper for aembed that runs the async implementation.
Source code in agentflow/store/embedding/base_embedding.py
16 17 18 | |
embed_batch
¶embed_batch(texts)
Synchronous wrapper for aembed_batch that runs the async implementation.
Source code in agentflow/store/embedding/base_embedding.py
7 8 9 | |
mem0_store
¶
Mem0 Long-Term Memory Store
Async-first implementation of :class:BaseStore that uses the mem0 library
as a managed long-term memory layer. In TAF we treat the graph state as
short-term (ephemeral per run / session) memory and a store implementation as
long-term, durable memory. This module wires Mem0 so that:
astore/asearch/ etc. map to Mem0'sadd,search,get_all,update,delete.- We maintain a generated UUID (framework memory id) separate from the Mem0 internal id.
- Metadata is enriched to retain memory type, category, timestamps and app scoping.
- The public async methods satisfy the :class:
BaseStorecontract (astore,abatch_store,asearch,aget,aupdate,adelete,aforget_memoryandarelease).
Design notes:¶
Mem0 (>= 0.2.x / 2025 spec) still exposes synchronous Python APIs. We off-load
blocking calls to a thread executor to keep the interface awaitable. Where Mem0
does not support an operation directly (e.g. fetch by custom memory id) we
fallback to scanning get_all for the user. For batch insertion we parallelise
Add operations with gather while bounding concurrency (simple semaphore) to
avoid thread explosion.
The store interprets the supplied config mapping passed to every method as:
{"user_id": str | None, "thread_id": str | None, "app_id": str | None}.
thread_id is stored into metadata under agent_id for backward compatibility
with earlier implementations where agent_id served a similar role.
Prerequisite: install mem0.
pip install mem0ai
create_mem0_store_with_qdrant for quick Qdrant backing.
Classes:
| Name | Description |
|---|---|
Mem0Store |
Mem0 implementation of long-term memory. |
Functions:
| Name | Description |
|---|---|
create_mem0_store |
Factory for a basic Mem0 long-term store. |
create_mem0_store_with_qdrant |
Factory producing a Mem0Store configured for Qdrant backing. |
Attributes:
| Name | Type | Description |
|---|---|---|
HAS_MEM0 |
|
|
logger |
|
Attributes¶
Classes¶
Mem0Store
¶
Bases: BaseStore
Mem0 implementation of long-term memory.
Primary responsibilities:
* Persist memories (episodic by default) across graph invocations
* Retrieve semantically similar memories to augment state
* Provide CRUD lifecycle aligned with BaseStore async API
Unlike in-memory state, these memories survive process restarts as they are managed by Mem0's configured vector / persistence layer.
Methods:
| Name | Description |
|---|---|
__init__ |
|
adelete |
|
aforget_memory |
|
aget |
|
aget_all |
|
arelease |
|
asearch |
|
asetup |
Asynchronous setup method for checkpointer. |
astore |
|
aupdate |
|
delete |
Synchronous wrapper for |
forget_memory |
Delete a memory by for a user or agent. |
generate_framework_id |
|
get |
Synchronous wrapper for |
get_all |
Synchronous wrapper for |
release |
Clean up any resources used by the store (override in subclasses if needed). |
search |
Synchronous wrapper for |
setup |
Synchronous setup method for checkpointer. |
store |
Synchronous wrapper for |
update |
Synchronous wrapper for |
Attributes:
| Name | Type | Description |
|---|---|---|
app_id |
|
|
config |
|
Source code in agentflow/store/mem0_store.py
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 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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 | |
__init__
¶__init__(config, app_id=None, **kwargs)
Source code in agentflow/store/mem0_store.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
adelete
async
¶adelete(config, memory_id, **kwargs)
Source code in agentflow/store/mem0_store.py
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 | |
aforget_memory
async
¶aforget_memory(config, **kwargs)
Source code in agentflow/store/mem0_store.py
373 374 375 376 377 378 379 380 381 382 383 | |
aget
async
¶aget(config, memory_id, **kwargs)
Source code in agentflow/store/mem0_store.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
aget_all
async
¶aget_all(config, limit=100, **kwargs)
Source code in agentflow/store/mem0_store.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | |
arelease
async
¶arelease()
Source code in agentflow/store/mem0_store.py
385 386 | |
asearch
async
¶asearch(config, query, memory_type=None, category=None, limit=10, score_threshold=None, filters=None, retrieval_strategy=None, distance_metric=None, max_tokens=4000, **kwargs)
Source code in agentflow/store/mem0_store.py
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 | |
asetup
async
¶asetup()
Asynchronous setup method for checkpointer.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Implementation-defined setup result. |
Source code in agentflow/store/base_store.py
49 50 51 52 53 54 55 56 | |
astore
async
¶astore(config, content, memory_type=MemoryType.EPISODIC, category='general', metadata=None, **kwargs)
Source code in agentflow/store/mem0_store.py
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 | |
aupdate
async
¶aupdate(config, memory_id, content, metadata=None, **kwargs)
Source code in agentflow/store/mem0_store.py
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 | |
delete
¶delete(config, memory_id, **kwargs)
Synchronous wrapper for adelete that runs the async implementation.
Source code in agentflow/store/base_store.py
248 249 250 | |
forget_memory
¶forget_memory(config, **kwargs)
Delete a memory by for a user or agent.
Source code in agentflow/store/base_store.py
261 262 263 264 265 266 267 | |
generate_framework_id
async
¶generate_framework_id()
Source code in agentflow/store/mem0_store.py
173 174 175 176 177 | |
get
¶get(config, memory_id, **kwargs)
Synchronous wrapper for aget that runs the async implementation.
Source code in agentflow/store/base_store.py
194 195 196 | |
get_all
¶get_all(config, limit=100, **kwargs)
Synchronous wrapper for aget that runs the async implementation.
Source code in agentflow/store/base_store.py
198 199 200 201 202 203 204 205 | |
release
¶release()
Clean up any resources used by the store (override in subclasses if needed).
Source code in agentflow/store/base_store.py
275 276 277 | |
search
¶search(config, query, memory_type=None, category=None, limit=10, score_threshold=None, filters=None, retrieval_strategy=RetrievalStrategy.SIMILARITY, distance_metric=DistanceMetric.COSINE, max_tokens=4000, **kwargs)
Synchronous wrapper for asearch that runs the async implementation.
Source code in agentflow/store/base_store.py
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 | |
setup
¶setup()
Synchronous setup method for checkpointer.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Implementation-defined setup result. |
Source code in agentflow/store/base_store.py
40 41 42 43 44 45 46 47 | |
store
¶store(config, content, memory_type=MemoryType.EPISODIC, category='general', metadata=None, **kwargs)
Synchronous wrapper for astore that runs the async implementation.
Source code in agentflow/store/base_store.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
update
¶update(config, memory_id, content, metadata=None, **kwargs)
Synchronous wrapper for aupdate that runs the async implementation.
Source code in agentflow/store/base_store.py
227 228 229 230 231 232 233 234 235 236 | |
Functions¶
create_mem0_store
¶create_mem0_store(config, user_id='default_user', thread_id=None, app_id='agentflow_app')
Factory for a basic Mem0 long-term store.
Source code in agentflow/store/mem0_store.py
392 393 394 395 396 397 398 399 400 401 402 403 404 | |
create_mem0_store_with_qdrant
¶create_mem0_store_with_qdrant(qdrant_url, qdrant_api_key=None, collection_name='agentflow_memories', embedding_model='text-embedding-ada-002', llm_model='gpt-4o-mini', app_id='agentflow_app', **kwargs)
Factory producing a Mem0Store configured for Qdrant backing.
Source code in agentflow/store/mem0_store.py
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 | |
qdrant_store
¶
Qdrant Vector Store Implementation for TAF Framework
This module provides a modern, async-first implementation of BaseStore using Qdrant as the backend vector database. Supports both local and cloud Qdrant deployments with configurable embedding services.
Classes:
| Name | Description |
|---|---|
QdrantStore |
Modern async-first Qdrant-based vector store implementation. |
Functions:
| Name | Description |
|---|---|
create_cloud_qdrant_store |
Create a cloud Qdrant store. |
create_local_qdrant_store |
Create a local Qdrant store. |
create_remote_qdrant_store |
Create a remote Qdrant store. |
Attributes:
| Name | Type | Description |
|---|---|---|
HAS_QDRANT |
|
|
logger |
|
Attributes¶
Classes¶
QdrantStore
¶
Bases: BaseStore
Modern async-first Qdrant-based vector store implementation.
Features: - Async-only operations for better performance - Local and cloud Qdrant deployment support - Configurable embedding services - Efficient vector similarity search with multiple strategies - Collection management with automatic creation - Rich metadata filtering capabilities - User and agent-scoped operations
Example
# Local Qdrant with OpenAI embeddings
store = QdrantStore(path="./qdrant_data", embedding_service=OpenAIEmbeddingService())
# Remote Qdrant
store = QdrantStore(host="localhost", port=6333, embedding_service=OpenAIEmbeddingService())
# Cloud Qdrant
store = QdrantStore(
url="https://xyz.qdrant.io",
api_key="your-api-key",
embedding_service=OpenAIEmbeddingService(),
)
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize Qdrant vector store. |
adelete |
Delete a memory by ID. |
aforget_memory |
Delete all memories for a user or agent. |
aget |
Get a specific memory by ID. |
aget_all |
Get all memories for a user. |
arelease |
Clean up resources. |
asearch |
Search memories by content similarity. |
asetup |
Set up the store and ensure default collection exists. |
astore |
Store a new memory. |
aupdate |
Update an existing memory. |
delete |
Synchronous wrapper for |
forget_memory |
Delete a memory by for a user or agent. |
get |
Synchronous wrapper for |
get_all |
Synchronous wrapper for |
release |
Clean up any resources used by the store (override in subclasses if needed). |
search |
Synchronous wrapper for |
setup |
Synchronous setup method for checkpointer. |
store |
Synchronous wrapper for |
update |
Synchronous wrapper for |
Attributes:
| Name | Type | Description |
|---|---|---|
client |
|
|
default_collection |
|
|
embedding |
|
Source code in agentflow/store/qdrant_store.py
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 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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 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 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 | |
__init__
¶__init__(embedding, path=None, host=None, port=None, url=None, api_key=None, default_collection='agentflow_memories', distance_metric=DistanceMetric.COSINE, **kwargs)
Initialize Qdrant vector store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embedding
¶ |
BaseEmbedding
|
Service for generating embeddings |
required |
path
¶ |
str | None
|
Path for local Qdrant (file-based storage) |
None
|
host
¶ |
str | None
|
Host for remote Qdrant server |
None
|
port
¶ |
int | None
|
Port for remote Qdrant server |
None
|
url
¶ |
str | None
|
URL for Qdrant cloud |
None
|
api_key
¶ |
str | None
|
API key for Qdrant cloud |
None
|
default_collection
¶ |
str
|
Default collection name |
'agentflow_memories'
|
distance_metric
¶ |
DistanceMetric
|
Default distance metric |
COSINE
|
**kwargs
¶ |
Any
|
Additional client parameters |
{}
|
Source code in agentflow/store/qdrant_store.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 112 113 114 115 116 117 118 119 120 121 | |
adelete
async
¶adelete(config, memory_id, **kwargs)
Delete a memory by ID.
Source code in agentflow/store/qdrant_store.py
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | |
aforget_memory
async
¶aforget_memory(config, **kwargs)
Delete all memories for a user or agent.
Source code in agentflow/store/qdrant_store.py
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 | |
aget
async
¶aget(config, memory_id, **kwargs)
Get a specific memory by ID.
Source code in agentflow/store/qdrant_store.py
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 | |
aget_all
async
¶aget_all(config, limit=100, **kwargs)
Get all memories for a user.
Source code in agentflow/store/qdrant_store.py
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 | |
arelease
async
¶arelease()
Clean up resources.
Source code in agentflow/store/qdrant_store.py
595 596 597 598 599 | |
asearch
async
¶asearch(config, query, memory_type=None, category=None, limit=10, score_threshold=None, filters=None, retrieval_strategy=RetrievalStrategy.SIMILARITY, distance_metric=DistanceMetric.COSINE, max_tokens=4000, **kwargs)
Search memories by content similarity.
Source code in agentflow/store/qdrant_store.py
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | |
asetup
async
¶asetup()
Set up the store and ensure default collection exists.
Source code in agentflow/store/qdrant_store.py
123 124 125 126 127 | |
astore
async
¶astore(config, content, memory_type=MemoryType.EPISODIC, category='general', metadata=None, **kwargs)
Store a new memory.
Source code in agentflow/store/qdrant_store.py
301 302 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 | |
aupdate
async
¶aupdate(config, memory_id, content, metadata=None, **kwargs)
Update an existing memory.
Source code in agentflow/store/qdrant_store.py
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 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 533 534 535 536 | |
delete
¶delete(config, memory_id, **kwargs)
Synchronous wrapper for adelete that runs the async implementation.
Source code in agentflow/store/base_store.py
248 249 250 | |
forget_memory
¶forget_memory(config, **kwargs)
Delete a memory by for a user or agent.
Source code in agentflow/store/base_store.py
261 262 263 264 265 266 267 | |
get
¶get(config, memory_id, **kwargs)
Synchronous wrapper for aget that runs the async implementation.
Source code in agentflow/store/base_store.py
194 195 196 | |
get_all
¶get_all(config, limit=100, **kwargs)
Synchronous wrapper for aget that runs the async implementation.
Source code in agentflow/store/base_store.py
198 199 200 201 202 203 204 205 | |
release
¶release()
Clean up any resources used by the store (override in subclasses if needed).
Source code in agentflow/store/base_store.py
275 276 277 | |
search
¶search(config, query, memory_type=None, category=None, limit=10, score_threshold=None, filters=None, retrieval_strategy=RetrievalStrategy.SIMILARITY, distance_metric=DistanceMetric.COSINE, max_tokens=4000, **kwargs)
Synchronous wrapper for asearch that runs the async implementation.
Source code in agentflow/store/base_store.py
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 | |
setup
¶setup()
Synchronous setup method for checkpointer.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Implementation-defined setup result. |
Source code in agentflow/store/base_store.py
40 41 42 43 44 45 46 47 | |
store
¶store(config, content, memory_type=MemoryType.EPISODIC, category='general', metadata=None, **kwargs)
Synchronous wrapper for astore that runs the async implementation.
Source code in agentflow/store/base_store.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
update
¶update(config, memory_id, content, metadata=None, **kwargs)
Synchronous wrapper for aupdate that runs the async implementation.
Source code in agentflow/store/base_store.py
227 228 229 230 231 232 233 234 235 236 | |
Functions¶
create_cloud_qdrant_store
¶create_cloud_qdrant_store(url, api_key, embedding, **kwargs)
Create a cloud Qdrant store.
Source code in agentflow/store/qdrant_store.py
633 634 635 636 637 638 639 640 641 642 643 644 645 | |
create_local_qdrant_store
¶create_local_qdrant_store(path, embedding, **kwargs)
Create a local Qdrant store.
Source code in agentflow/store/qdrant_store.py
605 606 607 608 609 610 611 612 613 614 615 | |
create_remote_qdrant_store
¶create_remote_qdrant_store(host, port, embedding, **kwargs)
Create a remote Qdrant store.
Source code in agentflow/store/qdrant_store.py
618 619 620 621 622 623 624 625 626 627 628 629 630 | |
store_schema
¶
Classes:
| Name | Description |
|---|---|
DistanceMetric |
Supported distance metrics for vector similarity. |
MemoryRecord |
Comprehensive memory record for storage (Pydantic model). |
MemorySearchResult |
Result from a memory search operation (Pydantic model). |
MemoryType |
Types of memories that can be stored. |
RetrievalStrategy |
Memory retrieval strategies. |
Classes¶
DistanceMetric
¶
Bases: Enum
Supported distance metrics for vector similarity.
Attributes:
| Name | Type | Description |
|---|---|---|
COSINE |
|
|
DOT_PRODUCT |
|
|
EUCLIDEAN |
|
|
MANHATTAN |
|
Source code in agentflow/store/store_schema.py
21 22 23 24 25 26 27 | |
MemoryRecord
¶
Bases: BaseModel
Comprehensive memory record for storage (Pydantic model).
Methods:
| Name | Description |
|---|---|
from_message |
|
validate_vector |
|
Attributes:
| Name | Type | Description |
|---|---|---|
category |
str
|
|
content |
str
|
|
id |
str
|
|
memory_type |
MemoryType
|
|
metadata |
dict[str, Any]
|
|
thread_id |
str | None
|
|
timestamp |
datetime | None
|
|
user_id |
str | None
|
|
vector |
list[float] | None
|
|
Source code in agentflow/store/store_schema.py
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 | |
from_message
classmethod
¶from_message(message, user_id=None, thread_id=None, vector=None, additional_metadata=None)
Source code in agentflow/store/store_schema.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 119 120 | |
validate_vector
classmethod
¶validate_vector(v)
Source code in agentflow/store/store_schema.py
78 79 80 81 82 83 84 85 | |
MemorySearchResult
¶
Bases: BaseModel
Result from a memory search operation (Pydantic model).
Methods:
| Name | Description |
|---|---|
validate_vector |
|
Attributes:
| Name | Type | Description |
|---|---|---|
content |
str
|
|
id |
str
|
|
memory_type |
MemoryType
|
|
metadata |
dict[str, Any]
|
|
score |
float
|
|
thread_id |
str | None
|
|
timestamp |
datetime | None
|
|
user_id |
str | None
|
|
vector |
list[float] | None
|
|
Source code in agentflow/store/store_schema.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
content
class-attribute
instance-attribute
¶content = Field(default='', description='Primary textual content of the memory')
score
class-attribute
instance-attribute
¶score = Field(default=0.0, ge=0.0, description='Similarity / relevance score')
validate_vector
classmethod
¶validate_vector(v)
Source code in agentflow/store/store_schema.py
55 56 57 58 59 60 61 62 | |
MemoryType
¶
Bases: Enum
Types of memories that can be stored.
Attributes:
| Name | Type | Description |
|---|---|---|
CUSTOM |
|
|
DECLARATIVE |
|
|
ENTITY |
|
|
EPISODIC |
|
|
PROCEDURAL |
|
|
RELATIONSHIP |
|
|
SEMANTIC |
|
Source code in agentflow/store/store_schema.py
30 31 32 33 34 35 36 37 38 39 | |
RetrievalStrategy
¶
Bases: Enum
Memory retrieval strategies.
Attributes:
| Name | Type | Description |
|---|---|---|
GRAPH_TRAVERSAL |
|
|
HYBRID |
|
|
RELEVANCE |
|
|
SIMILARITY |
|
|
TEMPORAL |
|
Source code in agentflow/store/store_schema.py
11 12 13 14 15 16 17 18 | |
utils
¶
Unified utility exports for TAF agent graphs.
This module re-exports core utility symbols for agent graph construction, message handling, callback management, reducers, and constants. Import from this module for a stable, unified surface of agent utilities.
Main Exports
- Message and content blocks (Message, TextBlock, ToolCallBlock, etc.)
- Callback management (CallbackManager, register_before_invoke, etc.)
- Command and callable utilities (Command, call_sync_or_async)
- Reducers (add_messages, replace_messages, append_items, replace_value)
- Constants (START, END, ExecutionState, etc.)
- Converter (convert_messages)
Modules:
| Name | Description |
|---|---|
background_task_manager |
Background task manager for async operations in TAF. |
callable_utils |
Utilities for calling sync or async functions in TAF. |
callbacks |
Callback system for TAF. |
command |
Command API for AgentGraph in TAF. |
constants |
Constants and enums for TAF agent graph execution and messaging. |
converter |
Message conversion utilities for TAF agent graphs. |
id_generator |
ID Generator Module |
logging |
Centralized logging configuration for TAF. |
metrics |
Lightweight metrics instrumentation utilities. |
thread_info |
Thread metadata and status tracking for agent graphs. |
thread_name_generator |
Thread name generation utilities for AI agent conversations. |
Classes:
| Name | Description |
|---|---|
AfterInvokeCallback |
Abstract base class for after_invoke callbacks. |
AsyncIDGenerator |
ID generator that produces UUID version 4 strings asynchronously. |
BackgroundTaskManager |
Manages asyncio background tasks for agent operations. |
BaseIDGenerator |
Abstract base class for ID generation strategies. |
BeforeInvokeCallback |
Abstract base class for before_invoke callbacks. |
BigIntIDGenerator |
ID generator that produces big integer IDs based on current time in nanoseconds. |
CallbackContext |
Context information passed to callbacks. |
CallbackManager |
Manages registration and execution of callbacks for different invocation types. |
Command |
Command object that combines state updates with control flow. |
DefaultIDGenerator |
Default ID generator that returns empty strings. |
ExecutionState |
Graph execution states for agent workflows. |
HexIDGenerator |
ID generator that produces hexadecimal strings. |
IDType |
Enumeration of supported ID types. |
IntIDGenerator |
ID generator that produces 32-bit random integers. |
InvocationType |
Types of invocations that can trigger callbacks. |
OnErrorCallback |
Abstract base class for on_error callbacks. |
ResponseGranularity |
Response granularity options for agent graph outputs. |
ShortIDGenerator |
ID generator that produces short alphanumeric strings. |
StorageLevel |
Message storage levels for agent state persistence. |
TaskMetadata |
Metadata for tracking background tasks. |
ThreadInfo |
Metadata and status for a thread in agent execution. |
TimestampIDGenerator |
ID generator that produces integer IDs based on current time in microseconds. |
UUIDGenerator |
ID generator that produces UUID version 4 strings. |
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. |
call_sync_or_async |
Call a function that may be sync or async, returning its result. |
configure_logging |
Configures the root logger for the TAF project. |
convert_messages |
Convert system prompts, agent state, and extra messages to a list of dicts for |
generate_dummy_thread_name |
Generate a meaningful English name for an AI chat thread. |
register_after_invoke |
Register an after_invoke callback on the global callback manager. |
register_before_invoke |
Register a before_invoke callback on the global callback manager. |
register_on_error |
Register an on_error callback on the global callback manager. |
replace_messages |
Replaces the entire message list with a new one. |
replace_value |
Replaces a value with another. |
run_coroutine |
Run an async coroutine from a sync context safely. |
Attributes:
| Name | Type | Description |
|---|---|---|
END |
Literal['__end__']
|
|
START |
Literal['__start__']
|
|
default_callback_manager |
|
Attributes¶
__all__
module-attribute
¶
__all__ = ['END', 'START', 'AfterInvokeCallback', 'AsyncIDGenerator', 'BackgroundTaskManager', 'BaseIDGenerator', 'BeforeInvokeCallback', 'BigIntIDGenerator', 'CallbackContext', 'CallbackManager', 'Command', 'DefaultIDGenerator', 'ExecutionState', 'HexIDGenerator', 'IDType', 'IntIDGenerator', 'InvocationType', 'OnErrorCallback', 'ResponseGranularity', 'ShortIDGenerator', 'StorageLevel', 'TaskMetadata', 'ThreadInfo', 'TimestampIDGenerator', 'UUIDGenerator', 'add_messages', 'append_items', 'call_sync_or_async', 'configure_logging', 'convert_messages', 'default_callback_manager', 'generate_dummy_thread_name', 'register_after_invoke', 'register_before_invoke', 'register_on_error', 'replace_messages', 'replace_value', 'run_coroutine']
Classes¶
AfterInvokeCallback
¶
Bases: ABC
Abstract base class for after_invoke callbacks.
Called after the AI model, tool, or MCP function is invoked. Allows for output validation and modification.
Methods:
| Name | Description |
|---|---|
__call__ |
Execute the after_invoke callback. |
Source code in agentflow/utils/callbacks.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
Functions¶
__call__
abstractmethod
async
¶__call__(context, input_data, output_data)
Execute the after_invoke callback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
¶ |
CallbackContext
|
Context information about the invocation |
required |
input_data
¶ |
T
|
The original input data that was sent |
required |
output_data
¶ |
Any
|
The output data returned from the invocation |
required |
Returns:
| Type | Description |
|---|---|
Any | R
|
Modified output data (can be same type or different type) |
Raises:
| Type | Description |
|---|---|
Exception
|
If validation fails or modification cannot be performed |
Source code in agentflow/utils/callbacks.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
AsyncIDGenerator
¶
Bases: BaseIDGenerator
ID generator that produces UUID version 4 strings asynchronously.
UUIDs are 128-bit identifiers that are virtually guaranteed to be unique across space and time. The generated strings are 36 characters long (32 hexadecimal digits + 4 hyphens in the format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx). This generator provides an asynchronous interface for generating UUIDs.
Methods:
| Name | Description |
|---|---|
generate |
Asynchronously generate a new UUID4 string. |
Attributes:
| Name | Type | Description |
|---|---|---|
id_type |
IDType
|
Return the type of ID generated by this generator. |
Source code in agentflow/utils/id_generator.py
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 | |
Attributes¶
id_type
property
¶id_type
Return the type of ID generated by this generator.
Returns:
| Name | Type | Description |
|---|---|---|
IDType |
IDType
|
The type of ID (STRING). |
Functions¶
generate
async
¶generate()
Asynchronously generate a new UUID4 string.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A 36-character UUID string (e.g., '550e8400-e29b-41d4-a716-446655440000'). |
Source code in agentflow/utils/id_generator.py
226 227 228 229 230 231 232 233 234 | |
BackgroundTaskManager
¶
Manages asyncio background tasks for agent operations.
Tracks created tasks, ensures cleanup, and logs errors from background execution. Enhanced with cancellation, timeouts, and metadata tracking.
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the BackgroundTaskManager. |
cancel_all |
Cancel all tracked background tasks. |
create_task |
Create and track a background asyncio task. |
get_task_count |
Get the number of active background tasks. |
get_task_info |
Get information about all active tasks. |
wait_for_all |
Wait for all tracked background tasks to complete. |
Source code in agentflow/utils/background_task_manager.py
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 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 | |
Functions¶
__init__
¶__init__()
Initialize the BackgroundTaskManager.
Source code in agentflow/utils/background_task_manager.py
39 40 41 42 43 44 | |
cancel_all
async
¶cancel_all()
Cancel all tracked background tasks.
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in agentflow/utils/background_task_manager.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
create_task
¶create_task(coro, *, name='background_task', timeout=None, context=None)
Create and track a background asyncio task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coro
¶ |
Coroutine
|
The coroutine to run in the background. |
required |
name
¶ |
str
|
Human-readable name for the task. |
'background_task'
|
timeout
¶ |
Optional[float]
|
Timeout in seconds for the task. |
None
|
context
¶ |
Optional[dict]
|
Additional context for logging. |
None
|
Returns:
| Type | Description |
|---|---|
Task
|
asyncio.Task: The created task. |
Source code in agentflow/utils/background_task_manager.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 | |
get_task_count
¶get_task_count()
Get the number of active background tasks.
Source code in agentflow/utils/background_task_manager.py
198 199 200 | |
get_task_info
¶get_task_info()
Get information about all active tasks.
Source code in agentflow/utils/background_task_manager.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
wait_for_all
async
¶wait_for_all(timeout=None, return_exceptions=False)
Wait for all tracked background tasks to complete.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
¶ |
float | None
|
Maximum time to wait in seconds. |
None
|
return_exceptions
¶ |
bool
|
If True, exceptions are returned as results instead of raised. |
False
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in agentflow/utils/background_task_manager.py
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 | |
BaseIDGenerator
¶
Bases: ABC
Abstract base class for ID generation strategies.
All ID generators must implement the id_type property and generate method.
Methods:
| Name | Description |
|---|---|
generate |
Generate a new unique ID. |
Attributes:
| Name | Type | Description |
|---|---|---|
id_type |
IDType
|
Return the type of ID generated by this generator. |
Source code in agentflow/utils/id_generator.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
Attributes¶
id_type
abstractmethod
property
¶id_type
Return the type of ID generated by this generator.
Returns:
| Name | Type | Description |
|---|---|---|
IDType |
IDType
|
The type of ID (STRING, INTEGER, or BIGINT). |
Functions¶
generate
abstractmethod
¶generate()
Generate a new unique ID.
Returns:
| Type | Description |
|---|---|
str | int | Awaitable[str | int]
|
str | int: A new unique identifier of the appropriate type. |
Source code in agentflow/utils/id_generator.py
41 42 43 44 45 46 47 48 | |
BeforeInvokeCallback
¶
Bases: ABC
Abstract base class for before_invoke callbacks.
Called before the AI model, tool, or MCP function is invoked. Allows for input validation and modification.
Methods:
| Name | Description |
|---|---|
__call__ |
Execute the before_invoke callback. |
Source code in agentflow/utils/callbacks.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
Functions¶
__call__
abstractmethod
async
¶__call__(context, input_data)
Execute the before_invoke callback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
¶ |
CallbackContext
|
Context information about the invocation |
required |
input_data
¶ |
T
|
The input data about to be sent to the invocation |
required |
Returns:
| Type | Description |
|---|---|
T | R
|
Modified input data (can be same type or different type) |
Raises:
| Type | Description |
|---|---|
Exception
|
If validation fails or modification cannot be performed |
Source code in agentflow/utils/callbacks.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
BigIntIDGenerator
¶
Bases: BaseIDGenerator
ID generator that produces big integer IDs based on current time in nanoseconds.
Generates IDs by multiplying current Unix timestamp by 1e9, resulting in large integers that are sortable by creation time. Typical size is 19-20 digits.
Methods:
| Name | Description |
|---|---|
generate |
Generate a new big integer ID based on current nanoseconds. |
Attributes:
| Name | Type | Description |
|---|---|---|
id_type |
IDType
|
|
Source code in agentflow/utils/id_generator.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
Attributes¶
Functions¶
generate
¶generate()
Generate a new big integer ID based on current nanoseconds.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
A large integer (19-20 digits) representing nanoseconds since Unix epoch. |
Source code in agentflow/utils/id_generator.py
83 84 85 86 87 88 89 90 | |
CallbackContext
dataclass
¶
Context information passed to callbacks.
Methods:
| Name | Description |
|---|---|
__init__ |
|
Attributes:
| Name | Type | Description |
|---|---|---|
function_name |
str | None
|
|
invocation_type |
InvocationType
|
|
metadata |
dict[str, Any] | None
|
|
node_name |
str
|
|
Source code in agentflow/utils/callbacks.py
36 37 38 39 40 41 42 43 | |
CallbackManager
¶
Manages registration and execution of callbacks for different invocation types.
Handles before_invoke, after_invoke, and on_error callbacks for AI, TOOL, and MCP invocations.
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the CallbackManager with empty callback registries. |
clear_callbacks |
Clear callbacks for a specific invocation type or all types. |
execute_after_invoke |
Execute all after_invoke callbacks for the given context. |
execute_before_invoke |
Execute all before_invoke callbacks for the given context. |
execute_on_error |
Execute all on_error callbacks for the given context. |
get_callback_counts |
Get count of registered callbacks by type for debugging. |
register_after_invoke |
Register an after_invoke callback for a specific invocation type. |
register_before_invoke |
Register a before_invoke callback for a specific invocation type. |
register_on_error |
Register an on_error callback for a specific invocation type. |
Source code in agentflow/utils/callbacks.py
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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 | |
Functions¶
__init__
¶__init__()
Initialize the CallbackManager with empty callback registries.
Source code in agentflow/utils/callbacks.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
clear_callbacks
¶clear_callbacks(invocation_type=None)
Clear callbacks for a specific invocation type or all types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
invocation_type
¶ |
InvocationType | None
|
The invocation type to clear, or None for all. |
None
|
Source code in agentflow/utils/callbacks.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
execute_after_invoke
async
¶execute_after_invoke(context, input_data, output_data)
Execute all after_invoke callbacks for the given context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
¶ |
CallbackContext
|
Context information about the invocation. |
required |
input_data
¶ |
Any
|
The original input data sent to the invocation. |
required |
output_data
¶ |
Any
|
The output data returned from the invocation. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The modified output data after all callbacks. |
Raises:
| Type | Description |
|---|---|
Exception
|
If any callback fails. |
Source code in agentflow/utils/callbacks.py
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 | |
execute_before_invoke
async
¶execute_before_invoke(context, input_data)
Execute all before_invoke callbacks for the given context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
¶ |
CallbackContext
|
Context information about the invocation. |
required |
input_data
¶ |
Any
|
The input data to be validated or modified. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The modified input data after all callbacks. |
Raises:
| Type | Description |
|---|---|
Exception
|
If any callback fails. |
Source code in agentflow/utils/callbacks.py
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 | |
execute_on_error
async
¶execute_on_error(context, input_data, error)
Execute all on_error callbacks for the given context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
¶ |
CallbackContext
|
Context information about the invocation. |
required |
input_data
¶ |
Any
|
The input data that caused the error. |
required |
error
¶ |
Exception
|
The exception that occurred. |
required |
Returns:
| Type | Description |
|---|---|
Message | None
|
Message | None: Recovery value from callbacks, or None if not handled. |
Source code in agentflow/utils/callbacks.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
get_callback_counts
¶get_callback_counts()
Get count of registered callbacks by type for debugging.
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, int]]
|
dict[str, dict[str, int]]: Counts of callbacks for each invocation type. |
Source code in agentflow/utils/callbacks.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
register_after_invoke
¶register_after_invoke(invocation_type, callback)
Register an after_invoke callback for a specific invocation type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
invocation_type
¶ |
InvocationType
|
The type of invocation (AI, TOOL, MCP). |
required |
callback
¶ |
AfterInvokeCallbackType
|
The callback to register. |
required |
Source code in agentflow/utils/callbacks.py
176 177 178 179 180 181 182 183 184 185 186 | |
register_before_invoke
¶register_before_invoke(invocation_type, callback)
Register a before_invoke callback for a specific invocation type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
invocation_type
¶ |
InvocationType
|
The type of invocation (AI, TOOL, MCP). |
required |
callback
¶ |
BeforeInvokeCallbackType
|
The callback to register. |
required |
Source code in agentflow/utils/callbacks.py
164 165 166 167 168 169 170 171 172 173 174 | |
register_on_error
¶register_on_error(invocation_type, callback)
Register an on_error callback for a specific invocation type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
invocation_type
¶ |
InvocationType
|
The type of invocation (AI, TOOL, MCP). |
required |
callback
¶ |
OnErrorCallbackType
|
The callback to register. |
required |
Source code in agentflow/utils/callbacks.py
188 189 190 191 192 193 194 195 196 197 198 | |
Command
¶
Command object that combines state updates with control flow.
Allows nodes to update agent state and direct graph execution to specific nodes or graphs. Similar to LangGraph's Command API.
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize a Command object. |
__repr__ |
Return a string representation of the Command object. |
Attributes:
| Name | Type | Description |
|---|---|---|
PARENT |
|
|
goto |
|
|
graph |
|
|
state |
|
|
update |
|
Source code in agentflow/utils/command.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 | |
Attributes¶
Functions¶
__init__
¶__init__(update=None, goto=None, graph=None, state=None)
Initialize a Command object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
update
¶ |
StateT | None | Message | str | BaseConverter
|
State update to apply. |
None
|
goto
¶ |
str | None
|
Next node to execute (node name or END). |
None
|
graph
¶ |
str | None
|
Which graph to navigate to (None for current, PARENT for parent). |
None
|
state
¶ |
StateT | None
|
Optional agent state to attach. |
None
|
Source code in agentflow/utils/command.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
__repr__
¶__repr__()
Return a string representation of the Command object.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
String representation of the Command. |
Source code in agentflow/utils/command.py
54 55 56 57 58 59 60 61 62 63 64 | |
DefaultIDGenerator
¶
Bases: BaseIDGenerator
Default ID generator that returns empty strings.
This generator is intended as a placeholder that can be configured to use framework defaults (typically UUID-based). Currently returns empty strings. If empty string is returned, the framework will use its default UUID-based generator. If the framework is not configured to use UUID generation, it will fall back to UUID4.
Methods:
| Name | Description |
|---|---|
generate |
Generate a default ID (currently empty string). |
Attributes:
| Name | Type | Description |
|---|---|---|
id_type |
IDType
|
|
Source code in agentflow/utils/id_generator.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 | |
Attributes¶
Functions¶
generate
¶generate()
Generate a default ID (currently empty string).
If empty string is returned, the framework will use its default UUID-based generator. If the framework is not configured to use UUID generation, it will fall back to UUID4.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
An empty string (framework will substitute with UUID). |
Source code in agentflow/utils/id_generator.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
ExecutionState
¶
Bases: StrEnum
Graph execution states for agent workflows.
Values
RUNNING: Execution is in progress. PAUSED: Execution is paused. COMPLETED: Execution completed successfully. ERROR: Execution encountered an error. INTERRUPTED: Execution was interrupted. ABORTED: Execution was aborted. IDLE: Execution is idle.
Attributes:
| Name | Type | Description |
|---|---|---|
ABORTED |
|
|
COMPLETED |
|
|
ERROR |
|
|
IDLE |
|
|
INTERRUPTED |
|
|
PAUSED |
|
|
RUNNING |
|
Source code in agentflow/utils/constants.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
Attributes¶
HexIDGenerator
¶
Bases: BaseIDGenerator
ID generator that produces hexadecimal strings.
Generates cryptographically secure random hex strings of 32 characters (representing 16 random bytes). Each character is a hexadecimal digit (0-9, a-f).
Methods:
| Name | Description |
|---|---|
generate |
Generate a new 32-character hexadecimal string. |
Attributes:
| Name | Type | Description |
|---|---|---|
id_type |
IDType
|
|
Source code in agentflow/utils/id_generator.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
Attributes¶
Functions¶
generate
¶generate()
Generate a new 32-character hexadecimal string.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A 32-character hex string (e.g., '1a2b3c4d5e6f7890abcdef1234567890'). |
Source code in agentflow/utils/id_generator.py
154 155 156 157 158 159 160 | |
IDType
¶
Bases: StrEnum
Enumeration of supported ID types.
Attributes:
| Name | Type | Description |
|---|---|---|
BIGINT |
|
|
INTEGER |
|
|
STRING |
|
Source code in agentflow/utils/id_generator.py
17 18 19 20 21 22 | |
IntIDGenerator
¶
Bases: BaseIDGenerator
ID generator that produces 32-bit random integers.
Generates cryptographically secure random integers using secrets.randbits(32). Values range from 0 to 2^32 - 1 (4,294,967,295).
Methods:
| Name | Description |
|---|---|
generate |
Generate a new 32-bit random integer. |
Attributes:
| Name | Type | Description |
|---|---|---|
id_type |
IDType
|
|
Source code in agentflow/utils/id_generator.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
Attributes¶
Functions¶
generate
¶generate()
Generate a new 32-bit random integer.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
A random integer between 0 and 4,294,967,295 (inclusive). |
Source code in agentflow/utils/id_generator.py
134 135 136 137 138 139 140 | |
InvocationType
¶
OnErrorCallback
¶
Bases: ABC
Abstract base class for on_error callbacks.
Called when an error occurs during invocation. Allows for error handling and logging.
Methods:
| Name | Description |
|---|---|
__call__ |
Execute the on_error callback. |
Source code in agentflow/utils/callbacks.py
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 | |
Functions¶
__call__
abstractmethod
async
¶__call__(context, input_data, error)
Execute the on_error callback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
¶ |
CallbackContext
|
Context information about the invocation |
required |
input_data
¶ |
Any
|
The input data that caused the error |
required |
error
¶ |
Exception
|
The exception that occurred |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Optional recovery value or None to re-raise the error |
Raises:
| Type | Description |
|---|---|
Exception
|
If error handling fails or if the error should be re-raised |
Source code in agentflow/utils/callbacks.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
ResponseGranularity
¶
Bases: StrEnum
Response granularity options for agent graph outputs.
Values
FULL: State, latest messages. PARTIAL: Context, summary, latest messages. LOW: Only latest messages.
Attributes:
| Name | Type | Description |
|---|---|---|
FULL |
|
|
LOW |
|
|
PARTIAL |
|
Source code in agentflow/utils/constants.py
55 56 57 58 59 60 61 62 63 64 65 66 67 | |
ShortIDGenerator
¶
Bases: BaseIDGenerator
ID generator that produces short alphanumeric strings.
Generates 8-character strings using uppercase/lowercase letters and digits. Each character is randomly chosen from 62 possible characters (26 + 26 + 10). Total possible combinations: 62^8 ≈ 2.18 x 10^14.
Methods:
| Name | Description |
|---|---|
generate |
Generate a new 8-character alphanumeric string. |
Attributes:
| Name | Type | Description |
|---|---|---|
id_type |
IDType
|
|
Source code in agentflow/utils/id_generator.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
Attributes¶
Functions¶
generate
¶generate()
Generate a new 8-character alphanumeric string.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
An 8-character string containing letters and digits (e.g., 'Ab3XyZ9k'). |
Source code in agentflow/utils/id_generator.py
195 196 197 198 199 200 201 202 203 | |
StorageLevel
¶
Message storage levels for agent state persistence.
Attributes:
| Name | Type | Description |
|---|---|---|
ALL |
Save everything including tool calls. |
|
MEDIUM |
Only AI and human messages. |
|
LOW |
Only first human and last AI message. |
Source code in agentflow/utils/constants.py
17 18 19 20 21 22 23 24 25 26 27 28 29 | |
TaskMetadata
dataclass
¶
Metadata for tracking background tasks.
Methods:
| Name | Description |
|---|---|
__init__ |
|
Attributes:
| Name | Type | Description |
|---|---|---|
context |
dict[str, Any] | None
|
|
created_at |
float
|
|
name |
str
|
|
timeout |
float | None
|
|
Source code in agentflow/utils/background_task_manager.py
21 22 23 24 25 26 27 28 | |
ThreadInfo
¶
Bases: BaseModel
Metadata and status for a thread in agent execution.
Attributes:
| Name | Type | Description |
|---|---|---|
thread_id |
int | str
|
Unique identifier for the thread. |
thread_name |
str | None
|
Optional name for the thread. |
user_id |
int | str | None
|
Optional user identifier associated with the thread. |
metadata |
dict[str, Any] | None
|
Optional metadata for the thread. |
updated_at |
datetime | None
|
Timestamp of last update. |
stop_requested |
bool
|
Whether a stop has been requested for the thread. |
run_id |
str | None
|
Optional run identifier for the thread execution. |
Example
ThreadInfo(thread_id=1, thread_name="main", user_id=42)
Source code in agentflow/utils/thread_info.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
Attributes¶
TimestampIDGenerator
¶
Bases: BaseIDGenerator
ID generator that produces integer IDs based on current time in microseconds.
Generates IDs by multiplying current Unix timestamp by 1e6, resulting in integers that are sortable by creation time. Typical size is 16-17 digits.
Methods:
| Name | Description |
|---|---|
generate |
Generate a new integer ID based on current microseconds. |
Attributes:
| Name | Type | Description |
|---|---|---|
id_type |
IDType
|
|
Source code in agentflow/utils/id_generator.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
Attributes¶
Functions¶
generate
¶generate()
Generate a new integer ID based on current microseconds.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
An integer (16-17 digits) representing microseconds since Unix epoch. |
Source code in agentflow/utils/id_generator.py
174 175 176 177 178 179 180 | |
UUIDGenerator
¶
Bases: BaseIDGenerator
ID generator that produces UUID version 4 strings.
UUIDs are 128-bit identifiers that are virtually guaranteed to be unique across space and time. The generated strings are 36 characters long (32 hexadecimal digits + 4 hyphens in the format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
Methods:
| Name | Description |
|---|---|
generate |
Generate a new UUID4 string. |
Attributes:
| Name | Type | Description |
|---|---|---|
id_type |
IDType
|
|
Source code in agentflow/utils/id_generator.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
Attributes¶
Functions¶
generate
¶generate()
Generate a new UUID4 string.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A 36-character UUID string (e.g., '550e8400-e29b-41d4-a716-446655440000'). |
Source code in agentflow/utils/id_generator.py
63 64 65 66 67 68 69 | |
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 | |
call_sync_or_async
async
¶
call_sync_or_async(func, *args, **kwargs)
Call a function that may be sync or async, returning its result.
If the function is synchronous, it runs in a thread pool to avoid blocking the event loop. If the result is awaitable, it is awaited before returning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Callable[..., Any]
|
The function to call. |
required |
|
Positional arguments for the function. |
()
|
|
|
Keyword arguments for the function. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The result of the function call, awaited if necessary. |
Source code in agentflow/utils/callable_utils.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
configure_logging
¶
configure_logging(level=logging.INFO, format_string=None, handler=None)
Configures the root logger for the TAF project.
This function sets up logging for all modules under the 'agentflow' namespace. It ensures that logs are formatted consistently and sent to the appropriate handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int
|
Logging level (e.g., logging.INFO, logging.DEBUG). Defaults to logging.INFO. |
INFO
|
|
str
|
Custom format string for log messages. If None, uses a default format: "[%(asctime)s] %(levelname)-8s %(name)s: %(message)s". |
None
|
|
Handler
|
Custom logging handler. If None, uses StreamHandler to stdout. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Example
configure_logging(level=logging.DEBUG) logger = logging.getLogger("agentflow.module") logger.info("This is an info message.")
Source code in agentflow/utils/logging.py
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 | |
convert_messages
¶
convert_messages(system_prompts, state=None, extra_messages=None)
Convert system prompts, agent state, and extra messages to a list of dicts for LLM/tool payloads.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[dict[str, Any]]
|
List of system prompt dicts. |
required |
|
AgentState | None
|
Optional agent state containing context and summary. |
None
|
|
list[Message] | None
|
Optional extra messages to include. |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: List of message dicts for payloads. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If system_prompts is None. |
Source code in agentflow/utils/converter.py
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 | |
generate_dummy_thread_name
¶
generate_dummy_thread_name(separator='-')
Generate a meaningful English name for an AI chat thread.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
String to separate words (default: "-"). |
'-'
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A meaningful thread name like 'thoughtful-dialogue', 'exploring-ideas', or 'deep-dive'. |
Example
generate_dummy_thread_name() 'creative-exploration'
Source code in agentflow/utils/thread_name_generator.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
register_after_invoke
¶
register_after_invoke(invocation_type, callback)
Register an after_invoke callback on the global callback manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
InvocationType
|
The type of invocation (AI, TOOL, MCP). |
required |
|
AfterInvokeCallbackType
|
The callback to register. |
required |
Source code in agentflow/utils/callbacks.py
353 354 355 356 357 358 359 360 361 362 363 | |
register_before_invoke
¶
register_before_invoke(invocation_type, callback)
Register a before_invoke callback on the global callback manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
InvocationType
|
The type of invocation (AI, TOOL, MCP). |
required |
|
BeforeInvokeCallbackType
|
The callback to register. |
required |
Source code in agentflow/utils/callbacks.py
340 341 342 343 344 345 346 347 348 349 350 | |
register_on_error
¶
register_on_error(invocation_type, callback)
Register an on_error callback on the global callback manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
InvocationType
|
The type of invocation (AI, TOOL, MCP). |
required |
|
OnErrorCallbackType
|
The callback to register. |
required |
Source code in agentflow/utils/callbacks.py
366 367 368 369 370 371 372 373 374 | |
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 | |
run_coroutine
¶
run_coroutine(func)
Run an async coroutine from a sync context safely.
Source code in agentflow/utils/callable_utils.py
54 55 56 57 58 59 60 61 62 63 64 65 | |
Modules¶
background_task_manager
¶
Background task manager for async operations in TAF.
This module provides BackgroundTaskManager, which tracks and manages asyncio background tasks, ensuring proper cleanup and error logging.
Classes:
| Name | Description |
|---|---|
BackgroundTaskManager |
Manages asyncio background tasks for agent operations. |
TaskMetadata |
Metadata for tracking background tasks. |
Attributes:
| Name | Type | Description |
|---|---|---|
logger |
|
Attributes¶
Classes¶
BackgroundTaskManager
¶Manages asyncio background tasks for agent operations.
Tracks created tasks, ensures cleanup, and logs errors from background execution. Enhanced with cancellation, timeouts, and metadata tracking.
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the BackgroundTaskManager. |
cancel_all |
Cancel all tracked background tasks. |
create_task |
Create and track a background asyncio task. |
get_task_count |
Get the number of active background tasks. |
get_task_info |
Get information about all active tasks. |
wait_for_all |
Wait for all tracked background tasks to complete. |
Source code in agentflow/utils/background_task_manager.py
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 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 | |
__init__
¶__init__()
Initialize the BackgroundTaskManager.
Source code in agentflow/utils/background_task_manager.py
39 40 41 42 43 44 | |
cancel_all
async
¶cancel_all()
Cancel all tracked background tasks.
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in agentflow/utils/background_task_manager.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
create_task
¶create_task(coro, *, name='background_task', timeout=None, context=None)
Create and track a background asyncio task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coro
¶ |
Coroutine
|
The coroutine to run in the background. |
required |
name
¶ |
str
|
Human-readable name for the task. |
'background_task'
|
timeout
¶ |
Optional[float]
|
Timeout in seconds for the task. |
None
|
context
¶ |
Optional[dict]
|
Additional context for logging. |
None
|
Returns:
| Type | Description |
|---|---|
Task
|
asyncio.Task: The created task. |
Source code in agentflow/utils/background_task_manager.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 | |
get_task_count
¶get_task_count()
Get the number of active background tasks.
Source code in agentflow/utils/background_task_manager.py
198 199 200 | |
get_task_info
¶get_task_info()
Get information about all active tasks.
Source code in agentflow/utils/background_task_manager.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
wait_for_all
async
¶wait_for_all(timeout=None, return_exceptions=False)
Wait for all tracked background tasks to complete.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
¶ |
float | None
|
Maximum time to wait in seconds. |
None
|
return_exceptions
¶ |
bool
|
If True, exceptions are returned as results instead of raised. |
False
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in agentflow/utils/background_task_manager.py
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 | |
TaskMetadata
dataclass
¶Metadata for tracking background tasks.
Methods:
| Name | Description |
|---|---|
__init__ |
|
Attributes:
| Name | Type | Description |
|---|---|---|
context |
dict[str, Any] | None
|
|
created_at |
float
|
|
name |
str
|
|
timeout |
float | None
|
|
Source code in agentflow/utils/background_task_manager.py
21 22 23 24 25 26 27 28 | |
Modules¶
callable_utils
¶
Utilities for calling sync or async functions in TAF.
This module provides helpers to detect async callables and to invoke functions that may be synchronous or asynchronous, handling thread pool execution and awaitables.
Functions:
| Name | Description |
|---|---|
call_sync_or_async |
Call a function that may be sync or async, returning its result. |
run_coroutine |
Run an async coroutine from a sync context safely. |
Functions¶
call_sync_or_async
async
¶call_sync_or_async(func, *args, **kwargs)
Call a function that may be sync or async, returning its result.
If the function is synchronous, it runs in a thread pool to avoid blocking the event loop. If the result is awaitable, it is awaited before returning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
¶ |
Callable[..., Any]
|
The function to call. |
required |
*args
¶ |
Positional arguments for the function. |
()
|
|
**kwargs
¶ |
Keyword arguments for the function. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The result of the function call, awaited if necessary. |
Source code in agentflow/utils/callable_utils.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
run_coroutine
¶run_coroutine(func)
Run an async coroutine from a sync context safely.
Source code in agentflow/utils/callable_utils.py
54 55 56 57 58 59 60 61 62 63 64 65 | |
callbacks
¶
Callback system for TAF.
This module provides a comprehensive callback framework that allows users to define their own validation logic and custom behavior at key points in the execution flow:
- before_invoke: Called before AI/TOOL/MCP invocation for input validation and modification
- after_invoke: Called after AI/TOOL/MCP invocation for output validation and modification
- on_error: Called when errors occur during invocation for error handling and logging
The system is generic and type-safe, supporting different callback types for different invocation contexts.
Classes:
| Name | Description |
|---|---|
AfterInvokeCallback |
Abstract base class for after_invoke callbacks. |
BeforeInvokeCallback |
Abstract base class for before_invoke callbacks. |
CallbackContext |
Context information passed to callbacks. |
CallbackManager |
Manages registration and execution of callbacks for different invocation types. |
InvocationType |
Types of invocations that can trigger callbacks. |
OnErrorCallback |
Abstract base class for on_error callbacks. |
Functions:
| Name | Description |
|---|---|
register_after_invoke |
Register an after_invoke callback on the global callback manager. |
register_before_invoke |
Register a before_invoke callback on the global callback manager. |
register_on_error |
Register an on_error callback on the global callback manager. |
Attributes:
| Name | Type | Description |
|---|---|---|
AfterInvokeCallbackType |
|
|
BeforeInvokeCallbackType |
|
|
OnErrorCallbackType |
|
|
default_callback_manager |
|
|
logger |
|
Attributes¶
AfterInvokeCallbackType
module-attribute
¶AfterInvokeCallbackType = Union[AfterInvokeCallback[Any, Any], Callable[[CallbackContext, Any, Any], Union[Any, Awaitable[Any]]]]
BeforeInvokeCallbackType
module-attribute
¶BeforeInvokeCallbackType = Union[BeforeInvokeCallback[Any, Any], Callable[[CallbackContext, Any], Union[Any, Awaitable[Any]]]]
OnErrorCallbackType
module-attribute
¶OnErrorCallbackType = Union[OnErrorCallback, Callable[[CallbackContext, Any, Exception], Union[Any | None, Awaitable[Any | None]]]]
Classes¶
AfterInvokeCallback
¶
Bases: ABC
Abstract base class for after_invoke callbacks.
Called after the AI model, tool, or MCP function is invoked. Allows for output validation and modification.
Methods:
| Name | Description |
|---|---|
__call__ |
Execute the after_invoke callback. |
Source code in agentflow/utils/callbacks.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
__call__
abstractmethod
async
¶__call__(context, input_data, output_data)
Execute the after_invoke callback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
¶ |
CallbackContext
|
Context information about the invocation |
required |
input_data
¶ |
T
|
The original input data that was sent |
required |
output_data
¶ |
Any
|
The output data returned from the invocation |
required |
Returns:
| Type | Description |
|---|---|
Any | R
|
Modified output data (can be same type or different type) |
Raises:
| Type | Description |
|---|---|
Exception
|
If validation fails or modification cannot be performed |
Source code in agentflow/utils/callbacks.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
BeforeInvokeCallback
¶
Bases: ABC
Abstract base class for before_invoke callbacks.
Called before the AI model, tool, or MCP function is invoked. Allows for input validation and modification.
Methods:
| Name | Description |
|---|---|
__call__ |
Execute the before_invoke callback. |
Source code in agentflow/utils/callbacks.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
__call__
abstractmethod
async
¶__call__(context, input_data)
Execute the before_invoke callback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
¶ |
CallbackContext
|
Context information about the invocation |
required |
input_data
¶ |
T
|
The input data about to be sent to the invocation |
required |
Returns:
| Type | Description |
|---|---|
T | R
|
Modified input data (can be same type or different type) |
Raises:
| Type | Description |
|---|---|
Exception
|
If validation fails or modification cannot be performed |
Source code in agentflow/utils/callbacks.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
CallbackContext
dataclass
¶Context information passed to callbacks.
Methods:
| Name | Description |
|---|---|
__init__ |
|
Attributes:
| Name | Type | Description |
|---|---|---|
function_name |
str | None
|
|
invocation_type |
InvocationType
|
|
metadata |
dict[str, Any] | None
|
|
node_name |
str
|
|
Source code in agentflow/utils/callbacks.py
36 37 38 39 40 41 42 43 | |
CallbackManager
¶Manages registration and execution of callbacks for different invocation types.
Handles before_invoke, after_invoke, and on_error callbacks for AI, TOOL, and MCP invocations.
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the CallbackManager with empty callback registries. |
clear_callbacks |
Clear callbacks for a specific invocation type or all types. |
execute_after_invoke |
Execute all after_invoke callbacks for the given context. |
execute_before_invoke |
Execute all before_invoke callbacks for the given context. |
execute_on_error |
Execute all on_error callbacks for the given context. |
get_callback_counts |
Get count of registered callbacks by type for debugging. |
register_after_invoke |
Register an after_invoke callback for a specific invocation type. |
register_before_invoke |
Register a before_invoke callback for a specific invocation type. |
register_on_error |
Register an on_error callback for a specific invocation type. |
Source code in agentflow/utils/callbacks.py
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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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 | |
__init__
¶__init__()
Initialize the CallbackManager with empty callback registries.
Source code in agentflow/utils/callbacks.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
clear_callbacks
¶clear_callbacks(invocation_type=None)
Clear callbacks for a specific invocation type or all types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
invocation_type
¶ |
InvocationType | None
|
The invocation type to clear, or None for all. |
None
|
Source code in agentflow/utils/callbacks.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
execute_after_invoke
async
¶execute_after_invoke(context, input_data, output_data)
Execute all after_invoke callbacks for the given context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
¶ |
CallbackContext
|
Context information about the invocation. |
required |
input_data
¶ |
Any
|
The original input data sent to the invocation. |
required |
output_data
¶ |
Any
|
The output data returned from the invocation. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The modified output data after all callbacks. |
Raises:
| Type | Description |
|---|---|
Exception
|
If any callback fails. |
Source code in agentflow/utils/callbacks.py
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 | |
execute_before_invoke
async
¶execute_before_invoke(context, input_data)
Execute all before_invoke callbacks for the given context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
¶ |
CallbackContext
|
Context information about the invocation. |
required |
input_data
¶ |
Any
|
The input data to be validated or modified. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The modified input data after all callbacks. |
Raises:
| Type | Description |
|---|---|
Exception
|
If any callback fails. |
Source code in agentflow/utils/callbacks.py
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 | |
execute_on_error
async
¶execute_on_error(context, input_data, error)
Execute all on_error callbacks for the given context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
¶ |
CallbackContext
|
Context information about the invocation. |
required |
input_data
¶ |
Any
|
The input data that caused the error. |
required |
error
¶ |
Exception
|
The exception that occurred. |
required |
Returns:
| Type | Description |
|---|---|
Message | None
|
Message | None: Recovery value from callbacks, or None if not handled. |
Source code in agentflow/utils/callbacks.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
get_callback_counts
¶get_callback_counts()
Get count of registered callbacks by type for debugging.
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, int]]
|
dict[str, dict[str, int]]: Counts of callbacks for each invocation type. |
Source code in agentflow/utils/callbacks.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
register_after_invoke
¶register_after_invoke(invocation_type, callback)
Register an after_invoke callback for a specific invocation type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
invocation_type
¶ |
InvocationType
|
The type of invocation (AI, TOOL, MCP). |
required |
callback
¶ |
AfterInvokeCallbackType
|
The callback to register. |
required |
Source code in agentflow/utils/callbacks.py
176 177 178 179 180 181 182 183 184 185 186 | |
register_before_invoke
¶register_before_invoke(invocation_type, callback)
Register a before_invoke callback for a specific invocation type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
invocation_type
¶ |
InvocationType
|
The type of invocation (AI, TOOL, MCP). |
required |
callback
¶ |
BeforeInvokeCallbackType
|
The callback to register. |
required |
Source code in agentflow/utils/callbacks.py
164 165 166 167 168 169 170 171 172 173 174 | |
register_on_error
¶register_on_error(invocation_type, callback)
Register an on_error callback for a specific invocation type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
invocation_type
¶ |
InvocationType
|
The type of invocation (AI, TOOL, MCP). |
required |
callback
¶ |
OnErrorCallbackType
|
The callback to register. |
required |
Source code in agentflow/utils/callbacks.py
188 189 190 191 192 193 194 195 196 197 198 | |
InvocationType
¶ OnErrorCallback
¶
Bases: ABC
Abstract base class for on_error callbacks.
Called when an error occurs during invocation. Allows for error handling and logging.
Methods:
| Name | Description |
|---|---|
__call__ |
Execute the on_error callback. |
Source code in agentflow/utils/callbacks.py
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 | |
__call__
abstractmethod
async
¶__call__(context, input_data, error)
Execute the on_error callback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
¶ |
CallbackContext
|
Context information about the invocation |
required |
input_data
¶ |
Any
|
The input data that caused the error |
required |
error
¶ |
Exception
|
The exception that occurred |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Optional recovery value or None to re-raise the error |
Raises:
| Type | Description |
|---|---|
Exception
|
If error handling fails or if the error should be re-raised |
Source code in agentflow/utils/callbacks.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
Functions¶
register_after_invoke
¶register_after_invoke(invocation_type, callback)
Register an after_invoke callback on the global callback manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
invocation_type
¶ |
InvocationType
|
The type of invocation (AI, TOOL, MCP). |
required |
callback
¶ |
AfterInvokeCallbackType
|
The callback to register. |
required |
Source code in agentflow/utils/callbacks.py
353 354 355 356 357 358 359 360 361 362 363 | |
register_before_invoke
¶register_before_invoke(invocation_type, callback)
Register a before_invoke callback on the global callback manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
invocation_type
¶ |
InvocationType
|
The type of invocation (AI, TOOL, MCP). |
required |
callback
¶ |
BeforeInvokeCallbackType
|
The callback to register. |
required |
Source code in agentflow/utils/callbacks.py
340 341 342 343 344 345 346 347 348 349 350 | |
register_on_error
¶register_on_error(invocation_type, callback)
Register an on_error callback on the global callback manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
invocation_type
¶ |
InvocationType
|
The type of invocation (AI, TOOL, MCP). |
required |
callback
¶ |
OnErrorCallbackType
|
The callback to register. |
required |
Source code in agentflow/utils/callbacks.py
366 367 368 369 370 371 372 373 374 | |
command
¶
Command API for AgentGraph in TAF.
This module provides the Command class, which allows nodes to combine state updates with control flow, similar to LangGraph's Command API. Nodes can update agent state and direct graph execution to specific nodes or graphs.
Classes:
| Name | Description |
|---|---|
Command |
Command object that combines state updates with control flow. |
Attributes:
| Name | Type | Description |
|---|---|---|
StateT |
|
Attributes¶
Classes¶
Command
¶Command object that combines state updates with control flow.
Allows nodes to update agent state and direct graph execution to specific nodes or graphs. Similar to LangGraph's Command API.
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize a Command object. |
__repr__ |
Return a string representation of the Command object. |
Attributes:
| Name | Type | Description |
|---|---|---|
PARENT |
|
|
goto |
|
|
graph |
|
|
state |
|
|
update |
|
Source code in agentflow/utils/command.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 | |
__init__
¶__init__(update=None, goto=None, graph=None, state=None)
Initialize a Command object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
update
¶ |
StateT | None | Message | str | BaseConverter
|
State update to apply. |
None
|
goto
¶ |
str | None
|
Next node to execute (node name or END). |
None
|
graph
¶ |
str | None
|
Which graph to navigate to (None for current, PARENT for parent). |
None
|
state
¶ |
StateT | None
|
Optional agent state to attach. |
None
|
Source code in agentflow/utils/command.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
__repr__
¶__repr__()
Return a string representation of the Command object.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
String representation of the Command. |
Source code in agentflow/utils/command.py
54 55 56 57 58 59 60 61 62 63 64 | |
constants
¶
Constants and enums for TAF agent graph execution and messaging.
This module defines special node names, message storage levels, execution states, and response granularity options for agent workflows.
Classes:
| Name | Description |
|---|---|
ExecutionState |
Graph execution states for agent workflows. |
ResponseGranularity |
Response granularity options for agent graph outputs. |
StorageLevel |
Message storage levels for agent state persistence. |
Attributes:
| Name | Type | Description |
|---|---|---|
END |
Literal['__end__']
|
|
START |
Literal['__start__']
|
|
Attributes¶
Classes¶
ExecutionState
¶
Bases: StrEnum
Graph execution states for agent workflows.
Values
RUNNING: Execution is in progress. PAUSED: Execution is paused. COMPLETED: Execution completed successfully. ERROR: Execution encountered an error. INTERRUPTED: Execution was interrupted. ABORTED: Execution was aborted. IDLE: Execution is idle.
Attributes:
| Name | Type | Description |
|---|---|---|
ABORTED |
|
|
COMPLETED |
|
|
ERROR |
|
|
IDLE |
|
|
INTERRUPTED |
|
|
PAUSED |
|
|
RUNNING |
|
Source code in agentflow/utils/constants.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
ResponseGranularity
¶
Bases: StrEnum
Response granularity options for agent graph outputs.
Values
FULL: State, latest messages. PARTIAL: Context, summary, latest messages. LOW: Only latest messages.
Attributes:
| Name | Type | Description |
|---|---|---|
FULL |
|
|
LOW |
|
|
PARTIAL |
|
Source code in agentflow/utils/constants.py
55 56 57 58 59 60 61 62 63 64 65 66 67 | |
StorageLevel
¶Message storage levels for agent state persistence.
Attributes:
| Name | Type | Description |
|---|---|---|
ALL |
Save everything including tool calls. |
|
MEDIUM |
Only AI and human messages. |
|
LOW |
Only first human and last AI message. |
Source code in agentflow/utils/constants.py
17 18 19 20 21 22 23 24 25 26 27 28 29 | |
converter
¶
Message conversion utilities for TAF agent graphs.
This module provides helpers to convert Message objects and agent state into dicts suitable for LLM and tool invocation payloads.
Functions:
| Name | Description |
|---|---|
convert_messages |
Convert system prompts, agent state, and extra messages to a list of dicts for |
Attributes:
| Name | Type | Description |
|---|---|---|
logger |
|
Attributes¶
Classes¶
Functions¶
convert_messages
¶convert_messages(system_prompts, state=None, extra_messages=None)
Convert system prompts, agent state, and extra messages to a list of dicts for LLM/tool payloads.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system_prompts
¶ |
list[dict[str, Any]]
|
List of system prompt dicts. |
required |
state
¶ |
AgentState | None
|
Optional agent state containing context and summary. |
None
|
extra_messages
¶ |
list[Message] | None
|
Optional extra messages to include. |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: List of message dicts for payloads. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If system_prompts is None. |
Source code in agentflow/utils/converter.py
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 | |
id_generator
¶
ID Generator Module
This module provides various strategies for generating unique identifiers. Each generator implements the BaseIDGenerator interface and specifies the type and size of IDs it produces.
Classes:
| Name | Description |
|---|---|
AsyncIDGenerator |
ID generator that produces UUID version 4 strings asynchronously. |
BaseIDGenerator |
Abstract base class for ID generation strategies. |
BigIntIDGenerator |
ID generator that produces big integer IDs based on current time in nanoseconds. |
DefaultIDGenerator |
Default ID generator that returns empty strings. |
HexIDGenerator |
ID generator that produces hexadecimal strings. |
IDType |
Enumeration of supported ID types. |
IntIDGenerator |
ID generator that produces 32-bit random integers. |
ShortIDGenerator |
ID generator that produces short alphanumeric strings. |
TimestampIDGenerator |
ID generator that produces integer IDs based on current time in microseconds. |
UUIDGenerator |
ID generator that produces UUID version 4 strings. |
Classes¶
AsyncIDGenerator
¶
Bases: BaseIDGenerator
ID generator that produces UUID version 4 strings asynchronously.
UUIDs are 128-bit identifiers that are virtually guaranteed to be unique across space and time. The generated strings are 36 characters long (32 hexadecimal digits + 4 hyphens in the format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx). This generator provides an asynchronous interface for generating UUIDs.
Methods:
| Name | Description |
|---|---|
generate |
Asynchronously generate a new UUID4 string. |
Attributes:
| Name | Type | Description |
|---|---|---|
id_type |
IDType
|
Return the type of ID generated by this generator. |
Source code in agentflow/utils/id_generator.py
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 | |
id_type
property
¶id_type
Return the type of ID generated by this generator.
Returns:
| Name | Type | Description |
|---|---|---|
IDType |
IDType
|
The type of ID (STRING). |
generate
async
¶generate()
Asynchronously generate a new UUID4 string.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A 36-character UUID string (e.g., '550e8400-e29b-41d4-a716-446655440000'). |
Source code in agentflow/utils/id_generator.py
226 227 228 229 230 231 232 233 234 | |
BaseIDGenerator
¶
Bases: ABC
Abstract base class for ID generation strategies.
All ID generators must implement the id_type property and generate method.
Methods:
| Name | Description |
|---|---|
generate |
Generate a new unique ID. |
Attributes:
| Name | Type | Description |
|---|---|---|
id_type |
IDType
|
Return the type of ID generated by this generator. |
Source code in agentflow/utils/id_generator.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
id_type
abstractmethod
property
¶id_type
Return the type of ID generated by this generator.
Returns:
| Name | Type | Description |
|---|---|---|
IDType |
IDType
|
The type of ID (STRING, INTEGER, or BIGINT). |
generate
abstractmethod
¶generate()
Generate a new unique ID.
Returns:
| Type | Description |
|---|---|
str | int | Awaitable[str | int]
|
str | int: A new unique identifier of the appropriate type. |
Source code in agentflow/utils/id_generator.py
41 42 43 44 45 46 47 48 | |
BigIntIDGenerator
¶
Bases: BaseIDGenerator
ID generator that produces big integer IDs based on current time in nanoseconds.
Generates IDs by multiplying current Unix timestamp by 1e9, resulting in large integers that are sortable by creation time. Typical size is 19-20 digits.
Methods:
| Name | Description |
|---|---|
generate |
Generate a new big integer ID based on current nanoseconds. |
Attributes:
| Name | Type | Description |
|---|---|---|
id_type |
IDType
|
|
Source code in agentflow/utils/id_generator.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
generate
¶generate()
Generate a new big integer ID based on current nanoseconds.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
A large integer (19-20 digits) representing nanoseconds since Unix epoch. |
Source code in agentflow/utils/id_generator.py
83 84 85 86 87 88 89 90 | |
DefaultIDGenerator
¶
Bases: BaseIDGenerator
Default ID generator that returns empty strings.
This generator is intended as a placeholder that can be configured to use framework defaults (typically UUID-based). Currently returns empty strings. If empty string is returned, the framework will use its default UUID-based generator. If the framework is not configured to use UUID generation, it will fall back to UUID4.
Methods:
| Name | Description |
|---|---|
generate |
Generate a default ID (currently empty string). |
Attributes:
| Name | Type | Description |
|---|---|---|
id_type |
IDType
|
|
Source code in agentflow/utils/id_generator.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 | |
generate
¶generate()
Generate a default ID (currently empty string).
If empty string is returned, the framework will use its default UUID-based generator. If the framework is not configured to use UUID generation, it will fall back to UUID4.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
An empty string (framework will substitute with UUID). |
Source code in agentflow/utils/id_generator.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
HexIDGenerator
¶
Bases: BaseIDGenerator
ID generator that produces hexadecimal strings.
Generates cryptographically secure random hex strings of 32 characters (representing 16 random bytes). Each character is a hexadecimal digit (0-9, a-f).
Methods:
| Name | Description |
|---|---|
generate |
Generate a new 32-character hexadecimal string. |
Attributes:
| Name | Type | Description |
|---|---|---|
id_type |
IDType
|
|
Source code in agentflow/utils/id_generator.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
generate
¶generate()
Generate a new 32-character hexadecimal string.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A 32-character hex string (e.g., '1a2b3c4d5e6f7890abcdef1234567890'). |
Source code in agentflow/utils/id_generator.py
154 155 156 157 158 159 160 | |
IDType
¶
Bases: StrEnum
Enumeration of supported ID types.
Attributes:
| Name | Type | Description |
|---|---|---|
BIGINT |
|
|
INTEGER |
|
|
STRING |
|
Source code in agentflow/utils/id_generator.py
17 18 19 20 21 22 | |
IntIDGenerator
¶
Bases: BaseIDGenerator
ID generator that produces 32-bit random integers.
Generates cryptographically secure random integers using secrets.randbits(32). Values range from 0 to 2^32 - 1 (4,294,967,295).
Methods:
| Name | Description |
|---|---|
generate |
Generate a new 32-bit random integer. |
Attributes:
| Name | Type | Description |
|---|---|---|
id_type |
IDType
|
|
Source code in agentflow/utils/id_generator.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
generate
¶generate()
Generate a new 32-bit random integer.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
A random integer between 0 and 4,294,967,295 (inclusive). |
Source code in agentflow/utils/id_generator.py
134 135 136 137 138 139 140 | |
ShortIDGenerator
¶
Bases: BaseIDGenerator
ID generator that produces short alphanumeric strings.
Generates 8-character strings using uppercase/lowercase letters and digits. Each character is randomly chosen from 62 possible characters (26 + 26 + 10). Total possible combinations: 62^8 ≈ 2.18 x 10^14.
Methods:
| Name | Description |
|---|---|
generate |
Generate a new 8-character alphanumeric string. |
Attributes:
| Name | Type | Description |
|---|---|---|
id_type |
IDType
|
|
Source code in agentflow/utils/id_generator.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
generate
¶generate()
Generate a new 8-character alphanumeric string.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
An 8-character string containing letters and digits (e.g., 'Ab3XyZ9k'). |
Source code in agentflow/utils/id_generator.py
195 196 197 198 199 200 201 202 203 | |
TimestampIDGenerator
¶
Bases: BaseIDGenerator
ID generator that produces integer IDs based on current time in microseconds.
Generates IDs by multiplying current Unix timestamp by 1e6, resulting in integers that are sortable by creation time. Typical size is 16-17 digits.
Methods:
| Name | Description |
|---|---|
generate |
Generate a new integer ID based on current microseconds. |
Attributes:
| Name | Type | Description |
|---|---|---|
id_type |
IDType
|
|
Source code in agentflow/utils/id_generator.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
generate
¶generate()
Generate a new integer ID based on current microseconds.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
An integer (16-17 digits) representing microseconds since Unix epoch. |
Source code in agentflow/utils/id_generator.py
174 175 176 177 178 179 180 | |
UUIDGenerator
¶
Bases: BaseIDGenerator
ID generator that produces UUID version 4 strings.
UUIDs are 128-bit identifiers that are virtually guaranteed to be unique across space and time. The generated strings are 36 characters long (32 hexadecimal digits + 4 hyphens in the format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
Methods:
| Name | Description |
|---|---|
generate |
Generate a new UUID4 string. |
Attributes:
| Name | Type | Description |
|---|---|---|
id_type |
IDType
|
|
Source code in agentflow/utils/id_generator.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
generate
¶generate()
Generate a new UUID4 string.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A 36-character UUID string (e.g., '550e8400-e29b-41d4-a716-446655440000'). |
Source code in agentflow/utils/id_generator.py
63 64 65 66 67 68 69 | |
logging
¶
Centralized logging configuration for TAF.
This module provides logging configuration that can be imported and used throughout the project. Each module should use:
import logging
logger = logging.getLogger(__name__)
This ensures proper hierarchical logging with module-specific loggers.
Typical usage example
from agentflow.utils.logging import configure_logging configure_logging(level=logging.DEBUG)
Functions:
| Name | Description |
|---|---|
configure_logging |
Configures the root logger for the TAF project. |
Functions¶
configure_logging
¶configure_logging(level=logging.INFO, format_string=None, handler=None)
Configures the root logger for the TAF project.
This function sets up logging for all modules under the 'agentflow' namespace. It ensures that logs are formatted consistently and sent to the appropriate handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
¶ |
int
|
Logging level (e.g., logging.INFO, logging.DEBUG). Defaults to logging.INFO. |
INFO
|
format_string
¶ |
str
|
Custom format string for log messages. If None, uses a default format: "[%(asctime)s] %(levelname)-8s %(name)s: %(message)s". |
None
|
handler
¶ |
Handler
|
Custom logging handler. If None, uses StreamHandler to stdout. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Example
configure_logging(level=logging.DEBUG) logger = logging.getLogger("agentflow.module") logger.info("This is an info message.")
Source code in agentflow/utils/logging.py
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 | |
metrics
¶
Lightweight metrics instrumentation utilities.
Design goals
- Zero dependency by default.
- Cheap no-op when disabled.
- Pluggable exporter (e.g., Prometheus scrape formatting) later.
Usage
from agentflow.utils.metrics import counter, timer counter('messages_written_total').inc() with timer('db_write_latency_ms'): ...
Classes:
| Name | Description |
|---|---|
Counter |
|
TimerMetric |
|
Functions:
| Name | Description |
|---|---|
counter |
|
enable_metrics |
|
snapshot |
Return a point-in-time snapshot of metrics (thread-safe copy). |
timer |
|
Classes¶
Counter
dataclass
¶Methods:
| Name | Description |
|---|---|
__init__ |
|
inc |
|
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
|
value |
int
|
|
Source code in agentflow/utils/metrics.py
34 35 36 37 38 39 40 41 42 43 | |
TimerMetric
dataclass
¶Methods:
| Name | Description |
|---|---|
__init__ |
|
observe |
|
Attributes:
| Name | Type | Description |
|---|---|---|
avg_ms |
float
|
|
count |
int
|
|
max_ms |
float
|
|
name |
str
|
|
total_ms |
float
|
|
Source code in agentflow/utils/metrics.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
Functions¶
counter
¶counter(name)
Source code in agentflow/utils/metrics.py
68 69 70 71 72 73 74 | |
enable_metrics
¶enable_metrics(value)
Source code in agentflow/utils/metrics.py
29 30 31 | |
snapshot
¶snapshot()
Return a point-in-time snapshot of metrics (thread-safe copy).
Source code in agentflow/utils/metrics.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
timer
¶timer(name)
Source code in agentflow/utils/metrics.py
77 78 79 80 81 82 83 84 85 | |
thread_info
¶
Thread metadata and status tracking for agent graphs.
This module defines the ThreadInfo model, which tracks thread identity, user, metadata, status, and timestamps for agent graph execution and orchestration.
Classes:
| Name | Description |
|---|---|
ThreadInfo |
Metadata and status for a thread in agent execution. |
Classes¶
ThreadInfo
¶
Bases: BaseModel
Metadata and status for a thread in agent execution.
Attributes:
| Name | Type | Description |
|---|---|---|
thread_id |
int | str
|
Unique identifier for the thread. |
thread_name |
str | None
|
Optional name for the thread. |
user_id |
int | str | None
|
Optional user identifier associated with the thread. |
metadata |
dict[str, Any] | None
|
Optional metadata for the thread. |
updated_at |
datetime | None
|
Timestamp of last update. |
stop_requested |
bool
|
Whether a stop has been requested for the thread. |
run_id |
str | None
|
Optional run identifier for the thread execution. |
Example
ThreadInfo(thread_id=1, thread_name="main", user_id=42)
Source code in agentflow/utils/thread_info.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
thread_name_generator
¶
Thread name generation utilities for AI agent conversations.
This module provides the AIThreadNameGenerator class and helper function for generating meaningful, varied, and human-friendly thread names for AI chat sessions using different patterns and themes.
Classes:
| Name | Description |
|---|---|
AIThreadNameGenerator |
Generates thread names using adjective-noun, action-based, |
Functions:
| Name | Description |
|---|---|
generate_dummy_thread_name |
Convenience function for generating a thread name. |
Classes¶
AIThreadNameGenerator
¶Generates meaningful, varied thread names for AI conversations using different patterns and themes. Patterns include adjective-noun, action-based, and compound descriptive names.
Example
AIThreadNameGenerator().generate_name() 'thoughtful-dialogue'
Methods:
| Name | Description |
|---|---|
generate_action_name |
Generate an action-based thread name for a more dynamic feel. |
generate_compound_name |
Generate a compound descriptive thread name. |
generate_name |
Generate a meaningful thread name using random pattern selection. |
generate_simple_name |
Generate a simple adjective-noun combination for a thread name. |
Attributes:
| Name | Type | Description |
|---|---|---|
ACTION_PATTERNS |
|
|
ADJECTIVES |
|
|
COMPOUND_PATTERNS |
|
|
NOUNS |
|
Source code in agentflow/utils/thread_name_generator.py
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 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 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 | |
ACTION_PATTERNS
class-attribute
instance-attribute
¶ACTION_PATTERNS = {'exploring': ['ideas', 'concepts', 'possibilities', 'mysteries', 'frontiers', 'depths'], 'building': ['solutions', 'understanding', 'connections', 'frameworks', 'bridges'], 'discovering': ['insights', 'patterns', 'answers', 'truths', 'secrets', 'wisdom'], 'crafting': ['responses', 'solutions', 'stories', 'strategies', 'experiences'], 'navigating': ['challenges', 'questions', 'complexities', 'territories', 'paths'], 'unlocking': ['potential', 'mysteries', 'possibilities', 'creativity', 'knowledge'], 'weaving': ['ideas', 'stories', 'connections', 'patterns', 'narratives'], 'illuminating': ['concepts', 'mysteries', 'paths', 'truths', 'possibilities']}
ADJECTIVES
class-attribute
instance-attribute
¶ADJECTIVES = ['thoughtful', 'insightful', 'analytical', 'logical', 'strategic', 'methodical', 'systematic', 'comprehensive', 'detailed', 'precise', 'creative', 'imaginative', 'innovative', 'artistic', 'expressive', 'original', 'inventive', 'inspired', 'visionary', 'whimsical', 'engaging', 'collaborative', 'meaningful', 'productive', 'harmonious', 'enlightening', 'empathetic', 'supportive', 'encouraging', 'uplifting', 'dynamic', 'energetic', 'vibrant', 'lively', 'spirited', 'active', 'flowing', 'adaptive', 'responsive', 'interactive', 'focused', 'dedicated', 'thorough', 'meticulous', 'careful', 'patient', 'persistent', 'resilient', 'determined', 'ambitious']
COMPOUND_PATTERNS
class-attribute
instance-attribute
¶COMPOUND_PATTERNS = [('deep', ['dive', 'thought', 'reflection', 'analysis', 'exploration']), ('bright', ['spark', 'idea', 'insight', 'moment', 'flash']), ('fresh', ['perspective', 'approach', 'start', 'take', 'view']), ('open', ['dialogue', 'discussion', 'conversation', 'exchange', 'forum']), ('creative', ['flow', 'spark', 'burst', 'stream', 'wave']), ('mindful', ['moment', 'pause', 'reflection', 'consideration', 'thought']), ('collaborative', ['effort', 'venture', 'journey', 'exploration', 'creation'])]
NOUNS
class-attribute
instance-attribute
¶NOUNS = ['dialogue', 'conversation', 'discussion', 'exchange', 'chat', 'consultation', 'session', 'meeting', 'interaction', 'communication', 'journey', 'exploration', 'adventure', 'quest', 'voyage', 'expedition', 'discovery', 'investigation', 'research', 'study', 'insight', 'vision', 'perspective', 'understanding', 'wisdom', 'knowledge', 'learning', 'growth', 'development', 'progress', 'solution', 'approach', 'strategy', 'method', 'framework', 'plan', 'blueprint', 'pathway', 'route', 'direction', 'canvas', 'story', 'narrative', 'symphony', 'composition', 'creation', 'masterpiece', 'design', 'pattern', 'concept', 'partnership', 'collaboration', 'alliance', 'connection', 'bond', 'synergy', 'harmony', 'unity', 'cooperation', 'teamwork']
generate_action_name
¶generate_action_name(separator='-')
Generate an action-based thread name for a more dynamic feel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
separator
¶ |
str
|
String to separate words (default: "-"). |
'-'
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Name like "exploring-ideas" or "building-understanding". |
Example
AIThreadNameGenerator().generate_action_name() 'building-connections'
Source code in agentflow/utils/thread_name_generator.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
generate_compound_name
¶generate_compound_name(separator='-')
Generate a compound descriptive thread name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
separator
¶ |
str
|
String to separate words (default: "-"). |
'-'
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Name like "deep-dive" or "bright-spark". |
Example
AIThreadNameGenerator().generate_compound_name() 'deep-reflection'
Source code in agentflow/utils/thread_name_generator.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
generate_name
¶generate_name(separator='-')
Generate a meaningful thread name using random pattern selection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
separator
¶ |
str
|
String to separate words (default: "-"). |
'-'
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A meaningful thread name from various patterns. |
Example
AIThreadNameGenerator().generate_name() 'engaging-discussion'
Source code in agentflow/utils/thread_name_generator.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
generate_simple_name
¶generate_simple_name(separator='-')
Generate a simple adjective-noun combination for a thread name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
separator
¶ |
str
|
String to separate words (default: "-"). |
'-'
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Name like "thoughtful-dialogue" or "creative-exploration". |
Example
AIThreadNameGenerator().generate_simple_name() 'creative-exploration'
Source code in agentflow/utils/thread_name_generator.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
Functions¶
generate_dummy_thread_name
¶generate_dummy_thread_name(separator='-')
Generate a meaningful English name for an AI chat thread.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
separator
¶ |
str
|
String to separate words (default: "-"). |
'-'
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A meaningful thread name like 'thoughtful-dialogue', 'exploring-ideas', or 'deep-dive'. |
Example
generate_dummy_thread_name() 'creative-exploration'
Source code in agentflow/utils/thread_name_generator.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |