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 |
|---|---|---|---|
|
CallbackContext
|
Context information about the invocation |
required |
|
T
|
The original input data that was sent |
required |
|
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 |
|---|---|---|---|
|
Coroutine
|
The coroutine to run in the background. |
required |
|
str
|
Human-readable name for the task. |
'background_task'
|
|
Optional[float]
|
Timeout in seconds for the task. |
None
|
|
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 |
|---|---|---|---|
|
float | None
|
Maximum time to wait in seconds. |
None
|
|
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 |
|---|---|---|---|
|
CallbackContext
|
Context information about the invocation |
required |
|
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 |
|---|---|---|---|
|
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 |
|---|---|---|---|
|
CallbackContext
|
Context information about the invocation. |
required |
|
Any
|
The original input data sent to the invocation. |
required |
|
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 |
|---|---|---|---|
|
CallbackContext
|
Context information about the invocation. |
required |
|
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 |
|---|---|---|---|
|
CallbackContext
|
Context information about the invocation. |
required |
|
Any
|
The input data that caused the error. |
required |
|
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 |
|---|---|---|---|
|
InvocationType
|
The type of invocation (AI, TOOL, MCP). |
required |
|
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 |
|---|---|---|---|
|
InvocationType
|
The type of invocation (AI, TOOL, MCP). |
required |
|
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 |
|---|---|---|---|
|
InvocationType
|
The type of invocation (AI, TOOL, MCP). |
required |
|
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 |
|---|---|---|---|
|
StateT | None | Message | str | BaseConverter
|
State update to apply. |
None
|
|
str | None
|
Next node to execute (node name or END). |
None
|
|
str | None
|
Which graph to navigate to (None for current, PARENT for parent). |
None
|
|
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 |
|---|---|---|---|
|
CallbackContext
|
Context information about the invocation |
required |
|
Any
|
The input data that caused the error |
required |
|
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 | |
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 | |
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 |
|---|---|---|---|
|
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 |
|---|---|---|---|
|
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 | |
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 | |
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 | |
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 | |
Attributes¶
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 |
|---|---|---|---|
|
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 |
|---|---|---|---|
|
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 | |
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 | |
Attributes¶
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 | |
Attributes¶
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']
Functions¶
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 |
|---|---|---|---|
|
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 | |