mirror of
https://github.com/openai/codex.git
synced 2026-11-29 00:00:54 +00:00
Allow replacing dynamic tools between model steps (#57553)
## What changed Add `CodexThread::replace_dynamic_tools` to replace the tool catalog without starting a turn. Updates apply to subsequent model steps and future turns while preserving in-flight calls; an empty list clears the catalog. Require host opt-in through `allow_persistent_dynamic_tool_updates` for persistent threads. Persist replacements before publishing them, restore the latest catalog on resume, and preserve replacements and explicit clears through compaction. Keep explicit resume overrides separate from the persisted catalog. ## Testing Add coverage for pending calls during replacement, replacement and clearing across restart, compaction recovery, resume overrides, submission ordering after caller cancellation, host opt-in, and persistence failures. GitOrigin-RevId: fd2634906895a9b72ae7892ddd9435dced45eccb
This commit is contained in:
@@ -164,14 +164,14 @@ fn test_tool_router(
|
||||
|
||||
#[tokio::test]
|
||||
async fn parallel_support_does_not_match_namespaced_local_tool_names() -> anyhow::Result<()> {
|
||||
let (_, turn) = make_session_and_context().await;
|
||||
let (session, turn) = make_session_and_context().await;
|
||||
let turn = Arc::new(turn);
|
||||
let step_context = StepContext::for_test(Arc::clone(&turn));
|
||||
let router = test_tool_router(
|
||||
step_context.as_ref(),
|
||||
Vec::new(),
|
||||
Vec::new(),
|
||||
&turn.dynamic_tools,
|
||||
session.dynamic_tools().await.as_ref(),
|
||||
);
|
||||
|
||||
let parallel_tool_name = ["exec_command"]
|
||||
@@ -313,7 +313,7 @@ fn build_tool_call_normalizes_default_function_and_custom_namespaces() -> anyhow
|
||||
|
||||
#[tokio::test]
|
||||
async fn mcp_parallel_support_uses_handler_data() -> anyhow::Result<()> {
|
||||
let (_, turn) = make_session_and_context().await;
|
||||
let (session, turn) = make_session_and_context().await;
|
||||
let turn = Arc::new(turn);
|
||||
let step_context = StepContext::for_test(Arc::clone(&turn));
|
||||
let router = test_tool_router(
|
||||
@@ -354,7 +354,7 @@ async fn mcp_parallel_support_uses_handler_data() -> anyhow::Result<()> {
|
||||
},
|
||||
],
|
||||
Vec::new(),
|
||||
&turn.dynamic_tools,
|
||||
session.dynamic_tools().await.as_ref(),
|
||||
);
|
||||
|
||||
let call = ToolCall {
|
||||
@@ -415,14 +415,14 @@ async fn mcp_parallel_support_uses_handler_data() -> anyhow::Result<()> {
|
||||
|
||||
#[tokio::test]
|
||||
async fn tools_without_handlers_do_not_support_parallel() -> anyhow::Result<()> {
|
||||
let (_, turn) = make_session_and_context().await;
|
||||
let (session, turn) = make_session_and_context().await;
|
||||
let turn = Arc::new(turn);
|
||||
let step_context = StepContext::for_test(Arc::clone(&turn));
|
||||
let router = test_tool_router(
|
||||
step_context.as_ref(),
|
||||
Vec::new(),
|
||||
Vec::new(),
|
||||
&turn.dynamic_tools,
|
||||
session.dynamic_tools().await.as_ref(),
|
||||
);
|
||||
|
||||
assert!(!router.tool_supports_parallel(&ToolCall {
|
||||
@@ -573,7 +573,7 @@ async fn extension_tool_executors_are_model_visible_and_dispatchable() -> anyhow
|
||||
&session,
|
||||
&codex_extension_api::ExtensionData::new(turn.sub_id.clone()),
|
||||
),
|
||||
&turn.dynamic_tools,
|
||||
session.dynamic_tools().await.as_ref(),
|
||||
);
|
||||
|
||||
assert!(
|
||||
|
||||
@@ -127,6 +127,7 @@ pub(crate) fn build_tool_router(
|
||||
apps_enabled: bool,
|
||||
step_store: &ExtensionData,
|
||||
tool_suggest_candidates: Option<&crate::tools::router::ToolSuggestCandidates>,
|
||||
dynamic_tools: &[DynamicToolSpec],
|
||||
) -> CodexResult<ToolRouter> {
|
||||
let default_agent_type_description =
|
||||
crate::agent::role::spawn_tool_spec::build(&std::collections::BTreeMap::new());
|
||||
@@ -170,7 +171,7 @@ pub(crate) fn build_tool_router(
|
||||
extension_tool_executors(session, step_store),
|
||||
&mut registry,
|
||||
);
|
||||
append_dynamic_tool_runtimes(&turn_context.dynamic_tools, &mut registry);
|
||||
append_dynamic_tool_runtimes(dynamic_tools, &mut registry);
|
||||
let hosted_specs = hosted_model_tool_specs(
|
||||
turn_context,
|
||||
model_info,
|
||||
|
||||
@@ -601,6 +601,7 @@ async fn reviewer_tool_policy_exclude_optional_core_tools() {
|
||||
/*apps_enabled*/ false,
|
||||
&turn.extension_data,
|
||||
/*tool_suggest_candidates*/ None,
|
||||
session.dynamic_tools().await.as_ref(),
|
||||
)
|
||||
.expect("build internal Guardian tool router");
|
||||
|
||||
@@ -653,6 +654,7 @@ async fn reviewer_tool_policy_respect_managed_shell_restrictions() {
|
||||
/*apps_enabled*/ false,
|
||||
&turn.extension_data,
|
||||
/*tool_suggest_candidates*/ None,
|
||||
session.dynamic_tools().await.as_ref(),
|
||||
)
|
||||
.expect("build internal Guardian tool router");
|
||||
|
||||
@@ -689,6 +691,7 @@ async fn reviewer_tool_policy_preserve_code_mode() {
|
||||
/*apps_enabled*/ false,
|
||||
&turn.extension_data,
|
||||
/*tool_suggest_candidates*/ None,
|
||||
session.dynamic_tools().await.as_ref(),
|
||||
)
|
||||
.expect("build internal Guardian tool router");
|
||||
|
||||
@@ -759,6 +762,7 @@ async fn reviewer_tool_policy_require_managed_secondary_environments() {
|
||||
/*apps_enabled*/ false,
|
||||
&turn.extension_data,
|
||||
/*tool_suggest_candidates*/ None,
|
||||
session.dynamic_tools().await.as_ref(),
|
||||
)
|
||||
.expect("build internal Guardian tool router");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user