Plan act reflect
Classes:
Name | Description |
---|---|
PlanActReflectAgent |
Plan -> Act -> Reflect looping agent. |
Attributes:
Name | Type | Description |
---|---|---|
StateT |
|
Attributes¶
Classes¶
PlanActReflectAgent
¶
Plan -> Act -> Reflect looping agent.
Pattern
PLAN -> (condition) -> ACT | REFLECT | END ACT -> REFLECT REFLECT -> PLAN
Default condition (_should_act): - If last assistant message contains tool calls -> ACT - If last message is from a tool -> REFLECT - Else -> END
Provide a custom condition to override this heuristic and implement
- Budget / depth limiting
- Confidence-based early stop
- Dynamic branch selection (e.g., different tool nodes)
Parameters (constructor): state: Optional initial state instance context_manager: Custom context manager publisher: Optional publisher for streaming / events id_generator: ID generation strategy container: InjectQ DI container
compile(...) arguments: plan_node: Callable (state -> state). Produces next thought / tool requests tool_node: ToolNode executing declared tools reflect_node: Callable (state -> state). Consumes tool results & may adjust plan condition: Optional Callable[[AgentState], str] returning next node name or END checkpointer/store/interrupt_before/interrupt_after/callback_manager: Standard graph compilation options
Returns:
Type | Description |
---|---|
CompiledGraph ready for invoke / ainvoke. |
Notes
- Node names can be customized via (callable, "NAME") tuples.
- condition must return one of: tool_node_name, reflect_node_name, END.
Methods:
Name | Description |
---|---|
__init__ |
|
compile |
Compile the Plan-Act-Reflect loop. |
Source code in pyagenity/prebuilt/agent/plan_act_reflect.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
Functions¶
__init__
¶
__init__(state=None, context_manager=None, publisher=None, id_generator=DefaultIDGenerator(), container=None)
Source code in pyagenity/prebuilt/agent/plan_act_reflect.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
compile
¶
compile(plan_node, tool_node, reflect_node, *, condition=None, checkpointer=None, store=None, interrupt_before=None, interrupt_after=None, callback_manager=CallbackManager())
Compile the Plan-Act-Reflect loop.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
Callable | tuple[Callable, str]
|
Callable or (callable, name) |
required |
|
ToolNode | tuple[ToolNode, str]
|
ToolNode or (ToolNode, name) |
required |
|
Callable | tuple[Callable, str]
|
Callable or (callable, name) |
required |
|
Callable[[AgentState], str] | None
|
Optional decision function. Defaults to internal heuristic. |
None
|
|
Standard graph options. |
required |
Returns:
Type | Description |
---|---|
CompiledGraph
|
CompiledGraph |
Source code in pyagenity/prebuilt/agent/plan_act_reflect.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|