Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions codex-rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions codex-rs/memories/write/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ codex-config = { workspace = true }
codex-features = { workspace = true }
codex-git-utils = { workspace = true }
codex-login = { workspace = true }
codex-model-provider = { workspace = true }
codex-otel = { workspace = true }
codex-protocol = { workspace = true }
codex-rollout = { workspace = true }
Expand All @@ -39,6 +40,7 @@ tracing = { workspace = true, features = ["log"] }
uuid = { workspace = true, features = ["v4", "v5"] }

[dev-dependencies]
codex-model-provider-info = { workspace = true }
codex-models-manager = { workspace = true }
core_test_support = { workspace = true }
pretty_assertions = { workspace = true }
Expand Down
2 changes: 0 additions & 2 deletions codex-rs/memories/write/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ signal to remove stale memories derived only from those resources.
}

mod stage_one {
pub(super) const MODEL: &str = "gpt-5.4-mini";
pub(super) const REASONING_EFFORT: codex_protocol::openai_models::ReasoningEffort =
codex_protocol::openai_models::ReasoningEffort::Low;
pub(super) const CONCURRENCY_LIMIT: usize = 8;
Expand All @@ -101,7 +100,6 @@ mod stage_one {
}

mod stage_two {
pub(super) const MODEL: &str = "gpt-5.4";
pub(super) const REASONING_EFFORT: codex_protocol::openai_models::ReasoningEffort =
codex_protocol::openai_models::ReasoningEffort::Medium;
pub(super) const JOB_LEASE_SECONDS: i64 = 3_600;
Expand Down
11 changes: 6 additions & 5 deletions codex-rs/memories/write/src/phase1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,12 @@ async fn build_request_context(
context: &MemoryStartupContext,
config: &Config,
) -> StageOneRequestContext {
let model_name = config
.memories
.extract_model
.clone()
.unwrap_or(crate::stage_one::MODEL.to_string());
let model_name = config.memories.extract_model.clone().unwrap_or_else(|| {
context
.provider()
.memory_extraction_preferred_model()
.to_string()
});
context
.stage_one_request_context(config, &model_name, crate::stage_one::REASONING_EFFORT)
.await
Expand Down
7 changes: 4 additions & 3 deletions codex-rs/memories/write/src/phase2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::workspace::write_workspace_diff;
use codex_config::Constrained;
use codex_core::config::Config;
use codex_features::Feature;
use codex_model_provider::ModelProvider;
use codex_protocol::ThreadId;
use codex_protocol::protocol::AgentStatus;
use codex_protocol::protocol::AskForApproval;
Expand Down Expand Up @@ -76,7 +77,7 @@ pub async fn run(context: Arc<MemoryStartupContext>, config: Arc<Config>) {
}

// 3. Build the locked-down config used by the consolidation agent.
let Some(agent_config) = agent::get_config(config.as_ref()) else {
let Some(agent_config) = agent::get_config(config.as_ref(), context.provider()) else {
// If we can't get the config, we can't consolidate.
tracing::error!("failed to get agent config");
job::failed(
Expand Down Expand Up @@ -297,7 +298,7 @@ mod agent {
use super::*;
use tracing::warn;

pub(super) fn get_config(config: &Config) -> Option<Config> {
pub(super) fn get_config(config: &Config, provider: &dyn ModelProvider) -> Option<Config> {
let root = memory_root(&config.codex_home);
let mut agent_config = config.clone();

Expand Down Expand Up @@ -339,7 +340,7 @@ mod agent {
.memories
.consolidation_model
.clone()
.unwrap_or(crate::stage_two::MODEL.to_string()),
.unwrap_or_else(|| provider.memory_consolidation_preferred_model().to_string()),
);
agent_config.model_reasoning_effort = Some(crate::stage_two::REASONING_EFFORT);

Expand Down
54 changes: 54 additions & 0 deletions codex-rs/memories/write/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ use codex_login::AuthManager;
use codex_login::CodexAuth;
use codex_login::auth_env_telemetry::collect_auth_env_telemetry;
use codex_login::default_client::originator;
use codex_model_provider::ModelProvider;
use codex_model_provider::SharedModelProvider;
use codex_model_provider::create_model_provider;
use codex_otel::SessionTelemetry;
use codex_otel::TelemetryAuthMode;
use codex_protocol::SessionId;
Expand Down Expand Up @@ -68,6 +71,7 @@ pub(crate) struct MemoryStartupContext {
thread: Arc<CodexThread>,
thread_manager: Arc<ThreadManager>,
auth_manager: Arc<AuthManager>,
provider: SharedModelProvider,
session_telemetry: SessionTelemetry,
}

Expand All @@ -79,6 +83,51 @@ impl MemoryStartupContext {
thread: Arc<CodexThread>,
config: &Config,
source: SessionSource,
) -> Self {
let provider = create_model_provider(
config.model_provider.clone(),
Some(Arc::clone(&auth_manager)),
);
Self::new_with_provider(
thread_manager,
auth_manager,
thread_id,
thread,
config,
source,
provider,
)
}

#[cfg(test)]
pub(crate) fn new_for_testing(
thread_manager: Arc<ThreadManager>,
auth_manager: Arc<AuthManager>,
thread_id: ThreadId,
thread: Arc<CodexThread>,
config: &Config,
source: SessionSource,
provider: SharedModelProvider,
) -> Self {
Self::new_with_provider(
thread_manager,
auth_manager,
thread_id,
thread,
config,
source,
provider,
)
}

fn new_with_provider(
thread_manager: Arc<ThreadManager>,
auth_manager: Arc<AuthManager>,
thread_id: ThreadId,
thread: Arc<CodexThread>,
config: &Config,
source: SessionSource,
provider: SharedModelProvider,
) -> Self {
let auth = auth_manager.auth_cached();
let auth = auth.as_ref();
Expand Down Expand Up @@ -109,6 +158,7 @@ impl MemoryStartupContext {
thread,
thread_manager,
auth_manager,
provider,
session_telemetry,
}
}
Expand All @@ -121,6 +171,10 @@ impl MemoryStartupContext {
self.thread.state_db()
}

pub(crate) fn provider(&self) -> &dyn ModelProvider {
self.provider.as_ref()
}

pub(crate) fn counter(&self, name: &str, inc: i64, tags: &[(&str, &str)]) {
self.session_telemetry.counter(name, inc, tags);
}
Expand Down
Loading
Loading