State
State management for PyAgenity agent graphs.
This package provides schemas and context managers for agent state, execution tracking, and message context management. All core state classes are exported for use in agent workflows and custom state extensions.
Modules:
Name | Description |
---|---|
agent_state |
Agent state schema for PyAgenity agent graphs. |
base_context |
Abstract base class for context management in PyAgenity agent graphs. |
execution_state |
Execution state management for graph execution in PyAgenity. |
message_context_manager |
Message context management for agent state in PyAgenity. |
Classes:
Name | Description |
---|---|
AgentState |
Common state schema that includes messages, context and internal execution metadata. |
BaseContextManager |
Abstract base class for context management in AI interactions. |
ExecutionState |
Tracks the internal execution state of a graph. |
ExecutionStatus |
Status of graph execution. |
MessageContextManager |
Manages the context field for AI interactions. |
Attributes¶
__all__
module-attribute
¶
__all__ = ['AgentState', 'BaseContextManager', 'ExecutionState', 'ExecutionStatus', 'MessageContextManager']
Classes¶
AgentState
¶
Bases: BaseModel
Common state schema that includes messages, context and internal execution metadata.
This class can be subclassed to add application-specific fields while maintaining compatibility with the PyAgenity framework. All internal execution metadata is preserved through subclassing.
Notes:
- execution_meta
contains internal-only execution progress and interrupt info.
- Users may subclass AgentState
to add application fields; internal exec meta remains
available to the runtime and will be persisted with the state.
- When subclassing, add your fields but keep the core fields intact.
Example
class MyCustomState(AgentState): user_data: dict = Field(default_factory=dict) custom_field: str = "default"
Methods:
Name | Description |
---|---|
advance_step |
Advance the execution step in the metadata. |
clear_interrupt |
Clear any interrupt in the execution metadata. |
complete |
Mark the agent state as completed. |
error |
Mark the agent state as errored. |
is_interrupted |
Check if the agent state is currently interrupted. |
is_running |
Check if the agent state is currently running. |
is_stopped_requested |
Check if a stop has been requested for the agent state. |
set_current_node |
Set the current node in the execution metadata. |
set_interrupt |
Set an interrupt in the execution metadata. |
Attributes:
Name | Type | Description |
---|---|---|
context |
Annotated[list[Message], add_messages]
|
|
context_summary |
str | None
|
|
execution_meta |
ExecutionState
|
|
Source code in pyagenity/state/agent_state.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
|
Attributes¶
execution_meta
class-attribute
instance-attribute
¶
execution_meta = Field(default_factory=lambda: ExecutionState(current_node=START))
Functions¶
advance_step
¶
advance_step()
Advance the execution step in the metadata.
Source code in pyagenity/state/agent_state.py
90 91 92 93 94 95 96 |
|
clear_interrupt
¶
clear_interrupt()
Clear any interrupt in the execution metadata.
Source code in pyagenity/state/agent_state.py
61 62 63 64 65 66 |
|
complete
¶
complete()
Mark the agent state as completed.
Source code in pyagenity/state/agent_state.py
109 110 111 112 113 114 |
|
error
¶
error(error_msg)
Mark the agent state as errored.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str
|
Error message to record. |
required |
Source code in pyagenity/state/agent_state.py
116 117 118 119 120 121 122 123 124 |
|
is_interrupted
¶
is_interrupted()
Check if the agent state is currently interrupted.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if interrupted, False otherwise. |
Source code in pyagenity/state/agent_state.py
79 80 81 82 83 84 85 86 87 88 |
|
is_running
¶
is_running()
Check if the agent state is currently running.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if running, False otherwise. |
Source code in pyagenity/state/agent_state.py
68 69 70 71 72 73 74 75 76 77 |
|
is_stopped_requested
¶
is_stopped_requested()
Check if a stop has been requested for the agent state.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if stop requested, False otherwise. |
Source code in pyagenity/state/agent_state.py
126 127 128 129 130 131 132 133 134 135 |
|
set_current_node
¶
set_current_node(node)
Set the current node in the execution metadata.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str
|
Node to set as current. |
required |
Source code in pyagenity/state/agent_state.py
98 99 100 101 102 103 104 105 106 107 |
|
set_interrupt
¶
set_interrupt(node, reason, status, data=None)
Set an interrupt in the execution metadata.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str
|
Node where the interrupt occurred. |
required |
|
str
|
Reason for the interrupt. |
required |
|
Execution status to set. |
required | |
|
dict | None
|
Optional additional interrupt data. |
None
|
Source code in pyagenity/state/agent_state.py
48 49 50 51 52 53 54 55 56 57 58 59 |
|
BaseContextManager
¶
Bases: ABC
Abstract base class for context management in AI interactions.
Subclasses should implement trim_context
as either a synchronous or asynchronous method.
Generic over AgentState or its subclasses.
Methods:
Name | Description |
---|---|
atrim_context |
Trim context based on message count asynchronously. |
trim_context |
Trim context based on message count. Can be sync or async. |
Source code in pyagenity/state/base_context.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
Functions¶
atrim_context
abstractmethod
async
¶
atrim_context(state)
Trim context based on message count asynchronously.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
S
|
The state containing context to be trimmed. |
required |
Returns:
Type | Description |
---|---|
S
|
The state with trimmed context. |
Source code in pyagenity/state/base_context.py
43 44 45 46 47 48 49 50 51 52 53 54 |
|
trim_context
abstractmethod
¶
trim_context(state)
Trim context based on message count. Can be sync or async.
Subclasses may implement as either a synchronous or asynchronous method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
S
|
The state containing context to be trimmed. |
required |
Returns:
Type | Description |
---|---|
S
|
The state with trimmed context, either directly or as an awaitable. |
Source code in pyagenity/state/base_context.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
ExecutionState
¶
Bases: BaseModel
Tracks the internal execution state of a graph.
This class manages the execution progress, interrupt status, and internal data that should not be exposed to users.
Methods:
Name | Description |
---|---|
advance_step |
Advance to the next execution step. |
clear_interrupt |
Clear the interrupt state and resume execution. |
complete |
Mark execution as completed. |
error |
Mark execution as errored. |
from_dict |
Create an ExecutionState instance from a dictionary. |
is_interrupted |
Check if execution is currently interrupted. |
is_running |
Check if execution is currently running. |
is_stopped_requested |
Check if a stop has been requested for execution. |
set_current_node |
Update the current node in execution state. |
set_interrupt |
Set the interrupt state for execution. |
Attributes:
Name | Type | Description |
---|---|---|
current_node |
str
|
|
internal_data |
dict[str, Any]
|
|
interrupt_data |
dict[str, Any] | None
|
|
interrupt_reason |
str | None
|
|
interrupted_node |
str | None
|
|
status |
ExecutionStatus
|
|
step |
int
|
|
stop_current_execution |
StopRequestStatus
|
|
thread_id |
str | None
|
|
Source code in pyagenity/state/execution_state.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
Attributes¶
Functions¶
advance_step
¶
advance_step()
Advance to the next execution step.
Source code in pyagenity/state/execution_state.py
134 135 136 137 138 139 140 |
|
clear_interrupt
¶
clear_interrupt()
Clear the interrupt state and resume execution.
Source code in pyagenity/state/execution_state.py
110 111 112 113 114 115 116 117 118 |
|
complete
¶
complete()
Mark execution as completed.
Source code in pyagenity/state/execution_state.py
153 154 155 156 157 158 |
|
error
¶
error(error_msg)
Mark execution as errored.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str
|
Error message to record. |
required |
Source code in pyagenity/state/execution_state.py
160 161 162 163 164 165 166 167 168 169 |
|
from_dict
classmethod
¶
from_dict(data)
Create an ExecutionState instance from a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
dict[str, Any]
|
Dictionary containing execution state fields. |
required |
Returns:
Name | Type | Description |
---|---|---|
ExecutionState |
ExecutionState
|
The deserialized execution state object. |
Source code in pyagenity/state/execution_state.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
is_interrupted
¶
is_interrupted()
Check if execution is currently interrupted.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if interrupted, False otherwise. |
Source code in pyagenity/state/execution_state.py
120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
is_running
¶
is_running()
Check if execution is currently running.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if running, False otherwise. |
Source code in pyagenity/state/execution_state.py
171 172 173 174 175 176 177 178 179 180 |
|
is_stopped_requested
¶
is_stopped_requested()
Check if a stop has been requested for execution.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if stop requested, False otherwise. |
Source code in pyagenity/state/execution_state.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
set_current_node
¶
set_current_node(node)
Update the current node in execution state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str
|
Node to set as current. |
required |
Source code in pyagenity/state/execution_state.py
142 143 144 145 146 147 148 149 150 151 |
|
set_interrupt
¶
set_interrupt(node, reason, status, data=None)
Set the interrupt state for execution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str
|
Node where the interrupt occurred. |
required |
|
str
|
Reason for the interrupt. |
required |
|
ExecutionStatus
|
Status to set for the interrupt. |
required |
|
dict[str, Any] | None
|
Optional additional interrupt data. |
None
|
Source code in pyagenity/state/execution_state.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
|
ExecutionStatus
¶
Bases: Enum
Status of graph execution.
Attributes:
Name | Type | Description |
---|---|---|
COMPLETED |
|
|
ERROR |
|
|
INTERRUPTED_AFTER |
|
|
INTERRUPTED_BEFORE |
|
|
RUNNING |
|
Source code in pyagenity/state/execution_state.py
18 19 20 21 22 23 24 25 |
|
Attributes¶
MessageContextManager
¶
Bases: BaseContextManager[S]
Manages the context field for AI interactions.
This class trims the context (message history) based on a maximum number of user messages, ensuring the first message (usually a system prompt) is always preserved. Generic over AgentState or its subclasses.
Methods:
Name | Description |
---|---|
__init__ |
Initialize the MessageContextManager. |
atrim_context |
Asynchronous version of trim_context. |
trim_context |
Trim the context in the given AgentState based on the maximum number of user messages. |
Attributes:
Name | Type | Description |
---|---|---|
max_messages |
|
Source code in pyagenity/state/message_context_manager.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
Attributes¶
Functions¶
__init__
¶
__init__(max_messages=10)
Initialize the MessageContextManager.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
int
|
Maximum number of user messages to keep in context. Default is 10. |
10
|
Source code in pyagenity/state/message_context_manager.py
31 32 33 34 35 36 37 38 39 40 |
|
atrim_context
async
¶
atrim_context(state)
Asynchronous version of trim_context.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
AgentState
|
The agent state containing the context to trim. |
required |
Returns:
Name | Type | Description |
---|---|---|
S |
S
|
The updated agent state with trimmed context. |
Source code in pyagenity/state/message_context_manager.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
trim_context
¶
trim_context(state)
Trim the context in the given AgentState based on the maximum number of user messages.
The first message (typically a system prompt) is always preserved. Only the most recent
user messages up to max_messages
are kept, along with the first message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
AgentState
|
The agent state containing the context to trim. |
required |
Returns:
Name | Type | Description |
---|---|---|
S |
S
|
The updated agent state with trimmed context. |
Source code in pyagenity/state/message_context_manager.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
Modules¶
agent_state
¶
Agent state schema for PyAgenity agent graphs.
This module provides the AgentState class, which tracks message context, context summaries, and internal execution metadata for agent workflows. Supports subclassing for custom application fields.
Classes:
Name | Description |
---|---|
AgentState |
Common state schema that includes messages, context and internal execution metadata. |
Attributes:
Name | Type | Description |
---|---|---|
logger |
|
Attributes¶
Classes¶
AgentState
¶
Bases: BaseModel
Common state schema that includes messages, context and internal execution metadata.
This class can be subclassed to add application-specific fields while maintaining compatibility with the PyAgenity framework. All internal execution metadata is preserved through subclassing.
Notes:
- execution_meta
contains internal-only execution progress and interrupt info.
- Users may subclass AgentState
to add application fields; internal exec meta remains
available to the runtime and will be persisted with the state.
- When subclassing, add your fields but keep the core fields intact.
Example
class MyCustomState(AgentState): user_data: dict = Field(default_factory=dict) custom_field: str = "default"
Methods:
Name | Description |
---|---|
advance_step |
Advance the execution step in the metadata. |
clear_interrupt |
Clear any interrupt in the execution metadata. |
complete |
Mark the agent state as completed. |
error |
Mark the agent state as errored. |
is_interrupted |
Check if the agent state is currently interrupted. |
is_running |
Check if the agent state is currently running. |
is_stopped_requested |
Check if a stop has been requested for the agent state. |
set_current_node |
Set the current node in the execution metadata. |
set_interrupt |
Set an interrupt in the execution metadata. |
Attributes:
Name | Type | Description |
---|---|---|
context |
Annotated[list[Message], add_messages]
|
|
context_summary |
str | None
|
|
execution_meta |
ExecutionState
|
|
Source code in pyagenity/state/agent_state.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
|
Attributes¶
execution_meta
class-attribute
instance-attribute
¶execution_meta = Field(default_factory=lambda: ExecutionState(current_node=START))
Functions¶
advance_step
¶advance_step()
Advance the execution step in the metadata.
Source code in pyagenity/state/agent_state.py
90 91 92 93 94 95 96 |
|
clear_interrupt
¶clear_interrupt()
Clear any interrupt in the execution metadata.
Source code in pyagenity/state/agent_state.py
61 62 63 64 65 66 |
|
complete
¶complete()
Mark the agent state as completed.
Source code in pyagenity/state/agent_state.py
109 110 111 112 113 114 |
|
error
¶error(error_msg)
Mark the agent state as errored.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
error_msg
¶ |
str
|
Error message to record. |
required |
Source code in pyagenity/state/agent_state.py
116 117 118 119 120 121 122 123 124 |
|
is_interrupted
¶is_interrupted()
Check if the agent state is currently interrupted.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if interrupted, False otherwise. |
Source code in pyagenity/state/agent_state.py
79 80 81 82 83 84 85 86 87 88 |
|
is_running
¶is_running()
Check if the agent state is currently running.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if running, False otherwise. |
Source code in pyagenity/state/agent_state.py
68 69 70 71 72 73 74 75 76 77 |
|
is_stopped_requested
¶is_stopped_requested()
Check if a stop has been requested for the agent state.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if stop requested, False otherwise. |
Source code in pyagenity/state/agent_state.py
126 127 128 129 130 131 132 133 134 135 |
|
set_current_node
¶set_current_node(node)
Set the current node in the execution metadata.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
¶ |
str
|
Node to set as current. |
required |
Source code in pyagenity/state/agent_state.py
98 99 100 101 102 103 104 105 106 107 |
|
set_interrupt
¶set_interrupt(node, reason, status, data=None)
Set an interrupt in the execution metadata.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
¶ |
str
|
Node where the interrupt occurred. |
required |
reason
¶ |
str
|
Reason for the interrupt. |
required |
status
¶ |
Execution status to set. |
required | |
data
¶ |
dict | None
|
Optional additional interrupt data. |
None
|
Source code in pyagenity/state/agent_state.py
48 49 50 51 52 53 54 55 56 57 58 59 |
|
Functions¶
base_context
¶
Abstract base class for context management in PyAgenity agent graphs.
This module provides BaseContextManager, which defines the interface for trimming and managing message context in agent state objects.
Classes:
Name | Description |
---|---|
BaseContextManager |
Abstract base class for context management in AI interactions. |
Attributes:
Name | Type | Description |
---|---|---|
S |
|
|
logger |
|
Attributes¶
Classes¶
BaseContextManager
¶
Bases: ABC
Abstract base class for context management in AI interactions.
Subclasses should implement trim_context
as either a synchronous or asynchronous method.
Generic over AgentState or its subclasses.
Methods:
Name | Description |
---|---|
atrim_context |
Trim context based on message count asynchronously. |
trim_context |
Trim context based on message count. Can be sync or async. |
Source code in pyagenity/state/base_context.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
Functions¶
atrim_context
abstractmethod
async
¶atrim_context(state)
Trim context based on message count asynchronously.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state
¶ |
S
|
The state containing context to be trimmed. |
required |
Returns:
Type | Description |
---|---|
S
|
The state with trimmed context. |
Source code in pyagenity/state/base_context.py
43 44 45 46 47 48 49 50 51 52 53 54 |
|
trim_context
abstractmethod
¶trim_context(state)
Trim context based on message count. Can be sync or async.
Subclasses may implement as either a synchronous or asynchronous method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state
¶ |
S
|
The state containing context to be trimmed. |
required |
Returns:
Type | Description |
---|---|
S
|
The state with trimmed context, either directly or as an awaitable. |
Source code in pyagenity/state/base_context.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
execution_state
¶
Execution state management for graph execution in PyAgenity.
This module provides the ExecutionState class and related enums to track progress, interruptions, and pause/resume functionality for agent graph execution.
Classes:
Name | Description |
---|---|
ExecutionState |
Tracks the internal execution state of a graph. |
ExecutionStatus |
Status of graph execution. |
StopRequestStatus |
Status of graph execution. |
Attributes:
Name | Type | Description |
---|---|---|
logger |
|
Attributes¶
Classes¶
ExecutionState
¶
Bases: BaseModel
Tracks the internal execution state of a graph.
This class manages the execution progress, interrupt status, and internal data that should not be exposed to users.
Methods:
Name | Description |
---|---|
advance_step |
Advance to the next execution step. |
clear_interrupt |
Clear the interrupt state and resume execution. |
complete |
Mark execution as completed. |
error |
Mark execution as errored. |
from_dict |
Create an ExecutionState instance from a dictionary. |
is_interrupted |
Check if execution is currently interrupted. |
is_running |
Check if execution is currently running. |
is_stopped_requested |
Check if a stop has been requested for execution. |
set_current_node |
Update the current node in execution state. |
set_interrupt |
Set the interrupt state for execution. |
Attributes:
Name | Type | Description |
---|---|---|
current_node |
str
|
|
internal_data |
dict[str, Any]
|
|
interrupt_data |
dict[str, Any] | None
|
|
interrupt_reason |
str | None
|
|
interrupted_node |
str | None
|
|
status |
ExecutionStatus
|
|
step |
int
|
|
stop_current_execution |
StopRequestStatus
|
|
thread_id |
str | None
|
|
Source code in pyagenity/state/execution_state.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
Attributes¶
Functions¶
advance_step
¶advance_step()
Advance to the next execution step.
Source code in pyagenity/state/execution_state.py
134 135 136 137 138 139 140 |
|
clear_interrupt
¶clear_interrupt()
Clear the interrupt state and resume execution.
Source code in pyagenity/state/execution_state.py
110 111 112 113 114 115 116 117 118 |
|
complete
¶complete()
Mark execution as completed.
Source code in pyagenity/state/execution_state.py
153 154 155 156 157 158 |
|
error
¶error(error_msg)
Mark execution as errored.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
error_msg
¶ |
str
|
Error message to record. |
required |
Source code in pyagenity/state/execution_state.py
160 161 162 163 164 165 166 167 168 169 |
|
from_dict
classmethod
¶from_dict(data)
Create an ExecutionState instance from a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
¶ |
dict[str, Any]
|
Dictionary containing execution state fields. |
required |
Returns:
Name | Type | Description |
---|---|---|
ExecutionState |
ExecutionState
|
The deserialized execution state object. |
Source code in pyagenity/state/execution_state.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
is_interrupted
¶is_interrupted()
Check if execution is currently interrupted.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if interrupted, False otherwise. |
Source code in pyagenity/state/execution_state.py
120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
is_running
¶is_running()
Check if execution is currently running.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if running, False otherwise. |
Source code in pyagenity/state/execution_state.py
171 172 173 174 175 176 177 178 179 180 |
|
is_stopped_requested
¶is_stopped_requested()
Check if a stop has been requested for execution.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if stop requested, False otherwise. |
Source code in pyagenity/state/execution_state.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
set_current_node
¶set_current_node(node)
Update the current node in execution state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
¶ |
str
|
Node to set as current. |
required |
Source code in pyagenity/state/execution_state.py
142 143 144 145 146 147 148 149 150 151 |
|
set_interrupt
¶set_interrupt(node, reason, status, data=None)
Set the interrupt state for execution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
¶ |
str
|
Node where the interrupt occurred. |
required |
reason
¶ |
str
|
Reason for the interrupt. |
required |
status
¶ |
ExecutionStatus
|
Status to set for the interrupt. |
required |
data
¶ |
dict[str, Any] | None
|
Optional additional interrupt data. |
None
|
Source code in pyagenity/state/execution_state.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
|
ExecutionStatus
¶
Bases: Enum
Status of graph execution.
Attributes:
Name | Type | Description |
---|---|---|
COMPLETED |
|
|
ERROR |
|
|
INTERRUPTED_AFTER |
|
|
INTERRUPTED_BEFORE |
|
|
RUNNING |
|
Source code in pyagenity/state/execution_state.py
18 19 20 21 22 23 24 25 |
|
Attributes¶
StopRequestStatus
¶
Bases: Enum
Status of graph execution.
Attributes:
Name | Type | Description |
---|---|---|
NONE |
|
|
STOPPED |
|
|
STOP_REQUESTED |
|
Source code in pyagenity/state/execution_state.py
28 29 30 31 32 33 |
|
message_context_manager
¶
Message context management for agent state in PyAgenity.
This module provides MessageContextManager, which trims and manages the message history (context) for agent interactions, ensuring efficient context window usage.
Classes:
Name | Description |
---|---|
MessageContextManager |
Manages the context field for AI interactions. |
Attributes:
Name | Type | Description |
---|---|---|
S |
|
|
logger |
|
Attributes¶
Classes¶
MessageContextManager
¶
Bases: BaseContextManager[S]
Manages the context field for AI interactions.
This class trims the context (message history) based on a maximum number of user messages, ensuring the first message (usually a system prompt) is always preserved. Generic over AgentState or its subclasses.
Methods:
Name | Description |
---|---|
__init__ |
Initialize the MessageContextManager. |
atrim_context |
Asynchronous version of trim_context. |
trim_context |
Trim the context in the given AgentState based on the maximum number of user messages. |
Attributes:
Name | Type | Description |
---|---|---|
max_messages |
|
Source code in pyagenity/state/message_context_manager.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
Attributes¶
Functions¶
__init__
¶__init__(max_messages=10)
Initialize the MessageContextManager.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_messages
¶ |
int
|
Maximum number of user messages to keep in context. Default is 10. |
10
|
Source code in pyagenity/state/message_context_manager.py
31 32 33 34 35 36 37 38 39 40 |
|
atrim_context
async
¶atrim_context(state)
Asynchronous version of trim_context.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state
¶ |
AgentState
|
The agent state containing the context to trim. |
required |
Returns:
Name | Type | Description |
---|---|---|
S |
S
|
The updated agent state with trimmed context. |
Source code in pyagenity/state/message_context_manager.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
trim_context
¶trim_context(state)
Trim the context in the given AgentState based on the maximum number of user messages.
The first message (typically a system prompt) is always preserved. Only the most recent
user messages up to max_messages
are kept, along with the first message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state
¶ |
AgentState
|
The agent state containing the context to trim. |
required |
Returns:
Name | Type | Description |
---|---|---|
S |
S
|
The updated agent state with trimmed context. |
Source code in pyagenity/state/message_context_manager.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|