fix: slim down token usage
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use serde_json::json;
|
||||
|
||||
use crate::model::{self, ControllerState, PlannerResponse, TaskConfig};
|
||||
use crate::prompt;
|
||||
|
||||
pub fn planning_schema() -> serde_json::Value {
|
||||
json!({
|
||||
@@ -23,19 +24,13 @@ pub fn planning_schema() -> serde_json::Value {
|
||||
}
|
||||
|
||||
pub fn build_planning_prompt(
|
||||
config: &TaskConfig,
|
||||
_config: &TaskConfig,
|
||||
goal_md: &str,
|
||||
standards_md: &str,
|
||||
state: &ControllerState,
|
||||
latest_user_input: &str,
|
||||
) -> String {
|
||||
let transcript = state
|
||||
.planning_session
|
||||
.transcript
|
||||
.iter()
|
||||
.map(|turn| format!("{}: {}", turn.role, turn.content))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
let transcript = prompt::compact_turns(&state.planning_session.transcript, 6, 240);
|
||||
|
||||
format!(
|
||||
concat!(
|
||||
@@ -43,34 +38,27 @@ pub fn build_planning_prompt(
|
||||
"You are only handling the planning phase.\n\n",
|
||||
"Rules:\n",
|
||||
"- Ask at most one follow-up question if the goal is still ambiguous.\n",
|
||||
"- If you have enough information, return kind=final.\n",
|
||||
"- If you have enough information, return kind=final immediately.\n",
|
||||
"- Always include all response keys.\n",
|
||||
"- Use null for any field that does not apply in the current response.\n",
|
||||
"- The final plan must be decision-complete for autonomous execution.\n",
|
||||
"- The plan should be maintainable and production-quality.\n",
|
||||
"- The controller directory contains only Markdown and TOON files.\n\n",
|
||||
"Task config paths:\n",
|
||||
"- goal: {goal}\n",
|
||||
"- plan: {plan}\n",
|
||||
"- state: {state}\n",
|
||||
"- standards: {standards}\n\n",
|
||||
"Current goal markdown:\n{goal_md}\n\n",
|
||||
"Current standards markdown:\n{standards_md}\n\n",
|
||||
"Transcript so far:\n{transcript}\n\n",
|
||||
"- Prefer 3 to 6 steps unless the goal truly needs more.\n",
|
||||
"- Keep each step.note to one short sentence.\n\n",
|
||||
"Current goal summary:\n{goal_md}\n\n",
|
||||
"Current standards summary:\n{standards_md}\n\n",
|
||||
"Recent transcript:\n{transcript}\n\n",
|
||||
"Latest user input:\n{latest}\n\n",
|
||||
"When returning kind=final, include:\n",
|
||||
"- goal_md: rewritten goal markdown\n",
|
||||
"- standards_md: rewritten standards markdown\n",
|
||||
"- plan: structured machine-readable plan object with ordered steps, verification, cleanup requirements, and statuses.\n"
|
||||
"- plan: structured machine-readable plan object with ordered steps, concise step notes, verification, cleanup requirements, and statuses.\n",
|
||||
"- Each step.notes field should explain the reason for the step or the current constraint in one short sentence.\n"
|
||||
),
|
||||
goal = config.goal_file.display(),
|
||||
plan = config.plan_file.display(),
|
||||
state = config.state_file.display(),
|
||||
standards = config.standards_file.display(),
|
||||
goal_md = goal_md,
|
||||
standards_md = standards_md,
|
||||
goal_md = prompt::compact_markdown(goal_md, 10, 1400),
|
||||
standards_md = prompt::compact_markdown(standards_md, 10, 1200),
|
||||
transcript = transcript,
|
||||
latest = latest_user_input,
|
||||
latest = prompt::truncate_text(latest_user_input, 400),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user