mirror of
https://github.com/openai/codex.git
synced 2026-11-09 08:40:33 +00:00
Revert "fix(bazel): replace askama templates with include_str! in memories" (#12795)
Reverts openai/codex#11778
This commit is contained in:
1 parent
947092283a
commit
7b39e76a66
6 files changed
+105
-13
No files matched your search
@@ -2,18 +2,43 @@ use crate::memories::memory_root;
|
||||
use crate::memories::phase_one;
|
||||
use crate::truncate::TruncationPolicy;
|
||||
use crate::truncate::truncate_text;
|
||||
use askama::Template;
|
||||
use codex_protocol::openai_models::ModelInfo;
|
||||
use std::path::Path;
|
||||
use tokio::fs;
|
||||
use tracing::warn;
|
||||
|
||||
const CONSOLIDATION_TEMPLATE: &str = include_str!("../../templates/memories/consolidation.md");
|
||||
const STAGE_ONE_INPUT_TEMPLATE: &str = include_str!("../../templates/memories/stage_one_input.md");
|
||||
const READ_PATH_TEMPLATE: &str = include_str!("../../templates/memories/read_path.md");
|
||||
#[derive(Template)]
|
||||
#[template(path = "memories/consolidation.md", escape = "none")]
|
||||
struct ConsolidationPromptTemplate<'a> {
|
||||
memory_root: &'a str,
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "memories/stage_one_input.md", escape = "none")]
|
||||
struct StageOneInputTemplate<'a> {
|
||||
rollout_path: &'a str,
|
||||
rollout_cwd: &'a str,
|
||||
rollout_contents: &'a str,
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "memories/read_path.md", escape = "none")]
|
||||
struct MemoryToolDeveloperInstructionsTemplate<'a> {
|
||||
base_path: &'a str,
|
||||
memory_summary: &'a str,
|
||||
}
|
||||
|
||||
/// Builds the consolidation subagent prompt for a specific memory root.
|
||||
pub(super) fn build_consolidation_prompt(memory_root: &Path) -> String {
|
||||
let memory_root = memory_root.display().to_string();
|
||||
CONSOLIDATION_TEMPLATE.replace("{{ memory_root }}", &memory_root)
|
||||
let template = ConsolidationPromptTemplate {
|
||||
memory_root: &memory_root,
|
||||
};
|
||||
template.render().unwrap_or_else(|err| {
|
||||
warn!("failed to render memories consolidation prompt template: {err}");
|
||||
format!("## Memory Phase 2 (Consolidation)\nConsolidate Codex memories in: {memory_root}")
|
||||
})
|
||||
}
|
||||
|
||||
/// Builds the stage-1 user message containing rollout metadata and content.
|
||||
@@ -40,10 +65,12 @@ pub(super) fn build_stage_one_input_message(
|
||||
|
||||
let rollout_path = rollout_path.display().to_string();
|
||||
let rollout_cwd = rollout_cwd.display().to_string();
|
||||
Ok(STAGE_ONE_INPUT_TEMPLATE
|
||||
.replace("{{ rollout_path }}", &rollout_path)
|
||||
.replace("{{ rollout_cwd }}", &rollout_cwd)
|
||||
.replace("{{ rollout_contents }}", &truncated_rollout_contents))
|
||||
Ok(StageOneInputTemplate {
|
||||
rollout_path: &rollout_path,
|
||||
rollout_cwd: &rollout_cwd,
|
||||
rollout_contents: &truncated_rollout_contents,
|
||||
}
|
||||
.render()?)
|
||||
}
|
||||
|
||||
/// Build prompt used for read path. This prompt must be added to the developer instructions. In
|
||||
@@ -65,11 +92,11 @@ pub(crate) async fn build_memory_tool_developer_instructions(codex_home: &Path)
|
||||
return None;
|
||||
}
|
||||
let base_path = base_path.display().to_string();
|
||||
Some(
|
||||
READ_PATH_TEMPLATE
|
||||
.replace("{{ base_path }}", &base_path)
|
||||
.replace("{{ memory_summary }}", &memory_summary),
|
||||
)
|
||||
let template = MemoryToolDeveloperInstructionsTemplate {
|
||||
base_path: &base_path,
|
||||
memory_summary: &memory_summary,
|
||||
};
|
||||
template.render().ok()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in new issue
Block a user