core / task / task_planner¶
core.task.task_planner
¶
Created on Thu Mar 27 21:32:01 2025
@author: zfoong
TaskPlanner
¶
Source code in core\task\task_planner.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 | |
__init__(llm_interface, db_interface=None, fewshot_top_k=1, context_engine=None)
¶
Interface between high-level task descriptions and the LLM planner.
The planner owns prompt construction, few-shot retrieval, and serialization helpers required to produce actionable task plans. It can optionally leverage stored task documents as examples to guide plan quality.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
llm_interface
|
Client used to send prompts to the language model. |
required | |
db_interface
|
Optional[DatabaseInterface]
|
Optional database layer for retrieving few-shot task documents. |
None
|
fewshot_top_k
|
int
|
Number of example task documents to include in the prompt when available. |
1
|
context_engine
|
Optional[ContextEngine]
|
Optional engine for generating system prompts and contextual wrappers. |
None
|
Source code in core\task\task_planner.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
plan_task(task_name, task_instruction)
async
¶
Request an initial step-by-step plan from the LLM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_name
|
str
|
Name of the task being planned (for logging/trace). |
required |
task_instruction
|
str
|
Natural-language instruction provided by the caller describing the desired outcome. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A JSON string representing the planned steps produced by the LLM. |
Source code in core\task\task_planner.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
update_plan(task_instruction, task_plan, event_stream, advance_next=False)
async
¶
Ask the LLM to update the plan given current steps + recent events. If advance_next=True, the agent is explicitly asking to move to the next step; the prompt includes that directive to encourage baton move.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_instruction
|
str
|
The original user instruction that anchors the task. |
required |
task_plan
|
Any
|
Current representation of the plan ( |
required |
event_stream
|
str
|
Serialized recent events that should inform the updated plan. |
required |
advance_next
|
bool
|
Whether to explicitly request movement to the next step in the refreshed plan. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
A JSON string representing the updated plan, or a serialized |
str
|
snapshot of the provided plan when serialization or the LLM call |
str
|
fails. |
Source code in core\task\task_planner.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
ask_plan(user_query)
async
¶
Build and send the initial planning prompt to the LLM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_query
|
str
|
Natural-language description of the task to plan. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A JSON string representing the LLM's proposed plan. |
Source code in core\task\task_planner.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |