Utils
Unified utility exports for PyAgenity 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 PyAgenity. |
callable_utils |
Utilities for calling sync or async functions in PyAgenity. |
callbacks |
Callback system for PyAgenity. |
command |
Command API for AgentGraph in PyAgenity. |
constants |
Constants and enums for PyAgenity agent graph execution and messaging. |
converter |
Message conversion utilities for PyAgenity agent graphs. |
id_generator |
ID Generator Module |
logging |
Centralized logging configuration for PyAgenity. |
message |
Message and content block primitives for agent graphs. |
metrics |
Lightweight metrics instrumentation utilities. |
reducers |
Reducer utilities for merging and replacing lists and values in agent state. |
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. |
AnnotationBlock |
Annotation content block for messages. |
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. |
Command |
Command object that combines state updates with control flow. |
DataBlock |
Data content block for messages. |
ErrorBlock |
Error content block for messages. |
ExecutionState |
Graph execution states for agent workflows. |
InvocationType |
Types of invocations that can trigger callbacks. |
Message |
Represents a message in a conversation, including content, role, metadata, and token usage. |
OnErrorCallback |
Abstract base class for on_error callbacks. |
ReasoningBlock |
Reasoning content block for messages. |
ResponseGranularity |
Response granularity options for agent graph outputs. |
StorageLevel |
Message storage levels for agent state persistence. |
TextBlock |
Text content block for messages. |
ThreadInfo |
Metadata and status for a thread in agent execution. |
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. |
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. |
convert_messages |
Convert system prompts, agent state, and extra messages to a list of dicts for |
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 |
---|---|---|
ContentBlock |
|
|
END |
Literal['__end__']
|
|
START |
Literal['__start__']
|
|
default_callback_manager |
|
Attributes¶
ContentBlock
module-attribute
¶
ContentBlock = Annotated[Union[TextBlock, ImageBlock, AudioBlock, VideoBlock, DocumentBlock, DataBlock, ToolCallBlock, ToolResultBlock, ReasoningBlock, AnnotationBlock, ErrorBlock], Field(discriminator='type')]
__all__
module-attribute
¶
__all__ = ['END', 'START', 'AfterInvokeCallback', 'AnnotationBlock', 'BeforeInvokeCallback', 'CallbackContext', 'CallbackManager', 'Command', 'ContentBlock', 'DataBlock', 'ErrorBlock', 'ExecutionState', 'InvocationType', 'Message', 'OnErrorCallback', 'ReasoningBlock', 'ResponseGranularity', 'StorageLevel', 'TextBlock', 'ThreadInfo', 'TokenUsages', 'ToolCallBlock', 'ToolResultBlock', 'add_messages', 'append_items', 'call_sync_or_async', 'convert_messages', 'default_callback_manager', '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 pyagenity/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 pyagenity/utils/callbacks.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
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 pyagenity/utils/message.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
|
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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/utils/command.py
54 55 56 57 58 59 60 61 62 63 64 |
|
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 pyagenity/utils/message.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
|
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 pyagenity/utils/message.py
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
|
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 pyagenity/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¶
InvocationType
¶
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 pyagenity/utils/message.py
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 |
|
Attributes¶
message_id
class-attribute
instance-attribute
¶
message_id = Field(default_factory=lambda: generate_id(None))
Functions¶
attach_media
¶
attach_media(media, as_type)
Append a media block to the content.
If content was text, creates a block list. Supports image, audio, video, and document types.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
MediaRef
|
Reference to media content. |
required |
|
Literal['image', 'audio', 'video', 'document']
|
Type of media block to append. |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Raises:
Type | Description |
---|---|
ValueError
|
If an unsupported media type is provided. |
Example
msg.attach_media(media_ref, as_type="image")
Source code in pyagenity/utils/message.py
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 |
|
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 pyagenity/utils/message.py
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 |
|
text_message
classmethod
¶
text_message(content, role='user', message_id=None)
Create a Message instance from plain text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str
|
The message content. |
required |
|
Literal['user', 'assistant', 'system', 'tool']
|
The role of the sender. |
'user'
|
|
str | None
|
Optional message ID. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Message |
Message
|
The created Message instance. |
Example
Message.text_message("Hello!", role="user")
Source code in pyagenity/utils/message.py
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 |
|
tool_message
classmethod
¶
tool_message(content, message_id=None, meta=None)
Create a tool message, optionally marking it as an error.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
list[ContentBlock]
|
The message content blocks. |
required |
|
str | None
|
Optional message ID. |
None
|
|
dict[str, Any] | None
|
Optional metadata. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Message |
Message
|
The created tool message instance. |
Example
Message.tool_message([ToolResultBlock(...)], message_id="tool1")
Source code in pyagenity/utils/message.py
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 |
|
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 pyagenity/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 pyagenity/utils/callbacks.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
|
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 pyagenity/utils/message.py
314 315 316 317 318 319 320 321 322 323 324 325 326 |
|
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 pyagenity/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 pyagenity/utils/constants.py
17 18 19 20 21 22 23 24 25 26 27 28 29 |
|
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 pyagenity/utils/message.py
176 177 178 179 180 181 182 183 184 185 186 187 188 |
|
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 pyagenity/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¶
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 pyagenity/utils/message.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 |
|
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 pyagenity/utils/message.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
|
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 pyagenity/utils/message.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
|
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 pyagenity/utils/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 pyagenity/utils/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 pyagenity/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 |
|
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 pyagenity/utils/converter.py
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 |
|
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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/utils/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 pyagenity/utils/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 pyagenity/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 PyAgenity.
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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/utils/background_task_manager.py
198 199 200 |
|
get_task_info
¶get_task_info()
Get information about all active tasks.
Source code in pyagenity/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 pyagenity/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 pyagenity/utils/background_task_manager.py
21 22 23 24 25 26 27 28 |
|
Modules¶
callable_utils
¶
Utilities for calling sync or async functions in PyAgenity.
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 pyagenity/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 pyagenity/utils/callable_utils.py
54 55 56 57 58 59 60 61 62 63 64 65 |
|
callbacks
¶
Callback system for PyAgenity.
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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/utils/callbacks.py
366 367 368 369 370 371 372 373 374 |
|
command
¶
Command API for AgentGraph in PyAgenity.
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 pyagenity/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 pyagenity/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 pyagenity/utils/command.py
54 55 56 57 58 59 60 61 62 63 64 |
|
constants
¶
Constants and enums for PyAgenity 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 pyagenity/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 pyagenity/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 pyagenity/utils/constants.py
17 18 19 20 21 22 23 24 25 26 27 28 29 |
|
converter
¶
Message conversion utilities for PyAgenity 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 pyagenity/utils/converter.py
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 |
|
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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/utils/id_generator.py
63 64 65 66 67 68 69 |
|
logging
¶
Centralized logging configuration for PyAgenity.
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 pyagenity.utils.logging import configure_logging configure_logging(level=logging.DEBUG)
Functions:
Name | Description |
---|---|
configure_logging |
Configures the root logger for the PyAgenity project. |
Functions¶
configure_logging
¶
configure_logging(level=logging.INFO, format_string=None, handler=None)
Configures the root logger for the PyAgenity project.
This function sets up logging for all modules under the 'pyagenity' 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("pyagenity.module") logger.info("This is an info message.")
Source code in pyagenity/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 |
|
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 |
---|---|---|
ContentBlock |
|
|
logger |
|
Attributes¶
ContentBlock
module-attribute
¶
ContentBlock = Annotated[Union[TextBlock, ImageBlock, AudioBlock, VideoBlock, DocumentBlock, DataBlock, ToolCallBlock, 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 pyagenity/utils/message.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
|
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 pyagenity/utils/message.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
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 pyagenity/utils/message.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
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 pyagenity/utils/message.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
|
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 pyagenity/utils/message.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
|
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 pyagenity/utils/message.py
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
|
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 pyagenity/utils/message.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
|
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 pyagenity/utils/message.py
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 |
|
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 pyagenity/utils/message.py
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 |
|
Attributes¶
message_id
class-attribute
instance-attribute
¶message_id = Field(default_factory=lambda: generate_id(None))
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 pyagenity/utils/message.py
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 |
|
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 pyagenity/utils/message.py
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 |
|
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 pyagenity/utils/message.py
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 |
|
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 pyagenity/utils/message.py
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 |
|
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 pyagenity/utils/message.py
314 315 316 317 318 319 320 321 322 323 324 325 326 |
|
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 pyagenity/utils/message.py
176 177 178 179 180 181 182 183 184 185 186 187 188 |
|
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 pyagenity/utils/message.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 |
|
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 pyagenity/utils/message.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
|
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 pyagenity/utils/message.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
|
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 pyagenity/utils/message.py
227 228 229 230 231 232 233 234 235 236 237 238 239 |
|
Functions¶
generate_id
¶
generate_id(default_id)
Generate a message or tool call ID based on DI context and type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str | int | None
|
Default ID to use if provided and matches type. |
required |
Returns:
Type | Description |
---|---|
str | int
|
str | int: Generated or provided ID, type determined by DI context. |
Example
generate_id("abc123") 'abc123' generate_id(None) 'a-uuid-string'
Source code in pyagenity/utils/message.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 |
|
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 pyagenity.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 pyagenity/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 pyagenity/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 pyagenity/utils/metrics.py
68 69 70 71 72 73 74 |
|
enable_metrics
¶
enable_metrics(value)
Source code in pyagenity/utils/metrics.py
29 30 31 |
|
snapshot
¶
snapshot()
Return a point-in-time snapshot of metrics (thread-safe copy).
Source code in pyagenity/utils/metrics.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
|
timer
¶
timer(name)
Source code in pyagenity/utils/metrics.py
77 78 79 80 81 82 83 84 85 |
|
reducers
¶
Reducer utilities for merging and replacing lists and values in agent state.
This module provides generic and message-specific reducers for combining lists, replacing values, and appending items while avoiding duplicates.
Functions:
Name | Description |
---|---|
add_messages |
Adds messages to a list, avoiding duplicates by message_id. |
replace_messages |
Replaces the entire message list. |
append_items |
Appends items to a list, avoiding duplicates by id. |
replace_value |
Replaces a value with another. |
Classes¶
Functions¶
add_messages
¶
add_messages(left, right)
Adds messages to the list, avoiding duplicates by message_id.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
list[Message]
|
Existing list of messages. |
required |
|
list[Message]
|
New messages to add. |
required |
Returns:
Type | Description |
---|---|
list[Message]
|
list[Message]: Combined list with unique messages. |
Example
add_messages([msg1], [msg2, msg1]) [msg1, msg2]
Source code in pyagenity/utils/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 pyagenity/utils/reducers.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|
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 pyagenity/utils/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 pyagenity/utils/reducers.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/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 pyagenity/utils/thread_name_generator.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
|