Allow per-turn overrides for direct-only tool namespaces (#59481)

## What changed

- Add `direct_only_tool_namespaces` to `TurnStartOptions`. Omission inherits the thread configuration; an empty list clears direct-only routing for that turn. Steering ignores the option.
- Persist explicit overrides in turn context and restore them when recovering an interrupted turn, including turns started by standalone tool output.
- Keep subsequent turns and spawned or resumed child agents on the thread's routing defaults.

## Testing

Add coverage for routing changes across turns in Responses and Responses Lite, recovery without carrying overrides into subsequent turns, and child-agent inheritance.

GitOrigin-RevId: cea1a997424572d4cd372cd15b098626904c6796
This commit is contained in:
Henry Levy
2026-11-04 19:58:49 +00:00
committed by copyberry
parent 41cbd5b9b2
commit d78f68f8d1
24 changed files with 322 additions and 39 deletions
@@ -4689,6 +4689,41 @@ async fn build_agent_spawn_config_uses_captured_step_settings_and_turn_context_v
assert_eq!(config, expected);
}
#[tokio::test]
async fn child_agents_inherit_thread_routing_when_parent_overrides_it_for_one_turn() {
let home = tempfile::tempdir().expect("create test home");
let (session, _, _events) = make_session_and_context_with_auth_config_home_and_rx(
CodexAuth::from_api_key("test"),
Vec::new(),
home.path(),
|config| config.code_mode.direct_only_tool_namespaces = vec!["thread_tools".into()],
)
.await;
let turn = session
.new_turn_with_default_settings(
"parent-turn".into(),
crate::session::turn_context::NewTurnContextOptions {
direct_only_tool_namespaces: Some(vec!["user_message".into()]),
..Default::default()
},
)
.await;
assert_eq!(
turn.config.code_mode.direct_only_tool_namespaces,
["user_message"]
);
let resumed = build_agent_resume_config(&turn).expect("resume config");
let step = StepContext::for_test(turn);
let spawned =
build_agent_spawn_config(&BaseInstructions::default(), &step).expect("spawn config");
for config in [spawned, resumed] {
assert_eq!(
config.code_mode.direct_only_tool_namespaces,
["thread_tools"]
);
}
}
#[tokio::test]
async fn build_agent_resume_config_clears_base_instructions() {
let (_session, mut turn) = make_session_and_context().await;