mirror of
https://github.com/openai/codex.git
synced 2026-11-13 14:46:14 +00:00
chore: move memory prompt builder into extension (#24558)
## Why The memories extension now owns the read-path developer instructions it injects at thread start. Keeping that prompt builder and template in `codex-memories-read` left the extension depending on a helper crate for extension-specific prompt assembly, and kept async template/truncation dependencies in the read crate after the remaining read surface no longer needed them. ## What changed - Moved `prompts.rs`, its tests, and `templates/memories/read_path.md` from `memories/read` into `ext/memories`. - Wired `MemoryExtension` to call the local prompt builder and added the moved templates to `ext/memories/BUILD.bazel` compile data. - Removed the now-unused prompt export and prompt-related dependencies from `codex-memories-read`. ## Testing - Not run locally.
This commit is contained in:
1 parent
d579dafb70
commit
de513a83f3
11 files changed
+11
-24
No files matched your search
Generated
+1
-5
@@ -3182,10 +3182,10 @@ dependencies = [
|
|||||||
"codex-core",
|
"codex-core",
|
||||||
"codex-extension-api",
|
"codex-extension-api",
|
||||||
"codex-features",
|
"codex-features",
|
||||||
"codex-memories-read",
|
|
||||||
"codex-tools",
|
"codex-tools",
|
||||||
"codex-utils-absolute-path",
|
"codex-utils-absolute-path",
|
||||||
"codex-utils-output-truncation",
|
"codex-utils-output-truncation",
|
||||||
|
"codex-utils-template",
|
||||||
"pretty_assertions",
|
"pretty_assertions",
|
||||||
"schemars 0.8.22",
|
"schemars 0.8.22",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -3202,11 +3202,7 @@ dependencies = [
|
|||||||
"codex-protocol",
|
"codex-protocol",
|
||||||
"codex-shell-command",
|
"codex-shell-command",
|
||||||
"codex-utils-absolute-path",
|
"codex-utils-absolute-path",
|
||||||
"codex-utils-output-truncation",
|
|
||||||
"codex-utils-template",
|
|
||||||
"pretty_assertions",
|
"pretty_assertions",
|
||||||
"tempfile",
|
|
||||||
"tokio",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -3,4 +3,7 @@ load("//:defs.bzl", "codex_rust_crate")
|
|||||||
codex_rust_crate(
|
codex_rust_crate(
|
||||||
name = "memories",
|
name = "memories",
|
||||||
crate_name = "codex_memories_extension",
|
crate_name = "codex_memories_extension",
|
||||||
|
compile_data = glob([
|
||||||
|
"templates/**",
|
||||||
|
]),
|
||||||
)
|
)
|
||||||
@@ -17,10 +17,10 @@ async-trait = { workspace = true }
|
|||||||
codex-core = { workspace = true }
|
codex-core = { workspace = true }
|
||||||
codex-extension-api = { workspace = true }
|
codex-extension-api = { workspace = true }
|
||||||
codex-features = { workspace = true }
|
codex-features = { workspace = true }
|
||||||
codex-memories-read = { workspace = true }
|
|
||||||
codex-tools = { workspace = true }
|
codex-tools = { workspace = true }
|
||||||
codex-utils-absolute-path = { workspace = true }
|
codex-utils-absolute-path = { workspace = true }
|
||||||
codex-utils-output-truncation = { workspace = true }
|
codex-utils-output-truncation = { workspace = true }
|
||||||
|
codex-utils-template = { workspace = true }
|
||||||
schemars = { workspace = true }
|
schemars = { workspace = true }
|
||||||
serde = { workspace = true, features = ["derive"] }
|
serde = { workspace = true, features = ["derive"] }
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ use codex_extension_api::ThreadLifecycleContributor;
|
|||||||
use codex_extension_api::ThreadStartInput;
|
use codex_extension_api::ThreadStartInput;
|
||||||
use codex_extension_api::ToolContributor;
|
use codex_extension_api::ToolContributor;
|
||||||
use codex_features::Feature;
|
use codex_features::Feature;
|
||||||
use codex_memories_read::build_memory_tool_developer_instructions;
|
|
||||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||||
|
|
||||||
use crate::local::LocalMemoriesBackend;
|
use crate::local::LocalMemoriesBackend;
|
||||||
|
use crate::prompts::build_memory_tool_developer_instructions;
|
||||||
use crate::tools;
|
use crate::tools;
|
||||||
|
|
||||||
/// Contributes Codex memory read-path prompt context and memory read tools.
|
/// Contributes Codex memory read-path prompt context and memory read tools.
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
mod backend;
|
mod backend;
|
||||||
mod extension;
|
mod extension;
|
||||||
mod local;
|
mod local;
|
||||||
|
mod prompts;
|
||||||
mod schema;
|
mod schema;
|
||||||
mod tools;
|
mod tools;
|
||||||
|
|
||||||
@@ -11,6 +12,7 @@ pub(crate) const MAX_LIST_RESULTS: usize = 2_000;
|
|||||||
pub(crate) const DEFAULT_SEARCH_MAX_RESULTS: usize = 200;
|
pub(crate) const DEFAULT_SEARCH_MAX_RESULTS: usize = 200;
|
||||||
pub(crate) const MAX_SEARCH_RESULTS: usize = 200;
|
pub(crate) const MAX_SEARCH_RESULTS: usize = 200;
|
||||||
pub(crate) const DEFAULT_READ_MAX_TOKENS: usize = 20_000;
|
pub(crate) const DEFAULT_READ_MAX_TOKENS: usize = 20_000;
|
||||||
|
pub(crate) const MEMORY_TOOL_DEVELOPER_INSTRUCTIONS_SUMMARY_TOKEN_LIMIT: usize = 2_500;
|
||||||
|
|
||||||
pub(crate) const MEMORY_TOOLS_NAMESPACE: &str = "memories/";
|
pub(crate) const MEMORY_TOOLS_NAMESPACE: &str = "memories/";
|
||||||
pub(crate) const LIST_TOOL_NAME: &str = "list";
|
pub(crate) const LIST_TOOL_NAME: &str = "list";
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
use crate::MEMORY_TOOL_DEVELOPER_INSTRUCTIONS_SUMMARY_TOKEN_LIMIT;
|
use crate::MEMORY_TOOL_DEVELOPER_INSTRUCTIONS_SUMMARY_TOKEN_LIMIT;
|
||||||
use crate::memory_root;
|
|
||||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||||
use codex_utils_output_truncation::TruncationPolicy;
|
use codex_utils_output_truncation::TruncationPolicy;
|
||||||
use codex_utils_output_truncation::truncate_text;
|
use codex_utils_output_truncation::truncate_text;
|
||||||
@@ -21,14 +20,14 @@ fn parse_embedded_template(source: &'static str, template_name: &str) -> Templat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build the read-path prompt that is added to developer instructions.
|
/// Build the memory read-path prompt that is added to developer instructions.
|
||||||
///
|
///
|
||||||
/// Large `memory_summary.md` files are truncated at
|
/// Large `memory_summary.md` files are truncated at
|
||||||
/// [MEMORY_TOOL_DEVELOPER_INSTRUCTIONS_SUMMARY_TOKEN_LIMIT].
|
/// [MEMORY_TOOL_DEVELOPER_INSTRUCTIONS_SUMMARY_TOKEN_LIMIT].
|
||||||
pub async fn build_memory_tool_developer_instructions(
|
pub(crate) async fn build_memory_tool_developer_instructions(
|
||||||
codex_home: &AbsolutePathBuf,
|
codex_home: &AbsolutePathBuf,
|
||||||
) -> Option<String> {
|
) -> Option<String> {
|
||||||
let base_path = memory_root(codex_home);
|
let base_path = codex_home.join("memories");
|
||||||
let memory_summary_path = base_path.join("memory_summary.md");
|
let memory_summary_path = base_path.join("memory_summary.md");
|
||||||
let memory_summary = fs::read_to_string(&memory_summary_path)
|
let memory_summary = fs::read_to_string(&memory_summary_path)
|
||||||
.await
|
.await
|
||||||
File renamed without changes.
File renamed without changes.
@@ -3,7 +3,4 @@ load("//:defs.bzl", "codex_rust_crate")
|
|||||||
codex_rust_crate(
|
codex_rust_crate(
|
||||||
name = "read",
|
name = "read",
|
||||||
crate_name = "codex_memories_read",
|
crate_name = "codex_memories_read",
|
||||||
compile_data = glob([
|
|
||||||
"templates/**",
|
|
||||||
]),
|
|
||||||
)
|
)
|
||||||
@@ -16,11 +16,6 @@ workspace = true
|
|||||||
codex-protocol = { workspace = true }
|
codex-protocol = { workspace = true }
|
||||||
codex-shell-command = { workspace = true }
|
codex-shell-command = { workspace = true }
|
||||||
codex-utils-absolute-path = { workspace = true }
|
codex-utils-absolute-path = { workspace = true }
|
||||||
codex-utils-output-truncation = { workspace = true }
|
|
||||||
codex-utils-template = { workspace = true }
|
|
||||||
tokio = { workspace = true, features = ["fs"] }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
pretty_assertions = { workspace = true }
|
pretty_assertions = { workspace = true }
|
||||||
tempfile = { workspace = true }
|
|
||||||
tokio = { workspace = true, features = ["fs", "macros"] }
|
|
||||||
@@ -6,15 +6,10 @@
|
|||||||
|
|
||||||
pub mod citations;
|
pub mod citations;
|
||||||
mod metrics;
|
mod metrics;
|
||||||
mod prompts;
|
|
||||||
pub mod usage;
|
pub mod usage;
|
||||||
|
|
||||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||||
|
|
||||||
pub use prompts::build_memory_tool_developer_instructions;
|
|
||||||
|
|
||||||
const MEMORY_TOOL_DEVELOPER_INSTRUCTIONS_SUMMARY_TOKEN_LIMIT: usize = 2_500;
|
|
||||||
|
|
||||||
pub fn memory_root(codex_home: &AbsolutePathBuf) -> AbsolutePathBuf {
|
pub fn memory_root(codex_home: &AbsolutePathBuf) -> AbsolutePathBuf {
|
||||||
codex_home.join("memories")
|
codex_home.join("memories")
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user