mirror of
https://github.com/openai/codex.git
synced 2026-10-27 00:00:53 +00:00
Record attempted tool calls in response metadata (#36181)
## What changed - Add the opt-in `executed_tool_call_metadata` feature to record model-attempted direct and code-mode tool calls. - Attach recorded names and arguments to the matching tool output in the next Responses request, preserving the metadata across sampling retries. - Bound pending calls and argument sizes, and emit truncation metadata when limits are exceeded. ## Testing - Cover disabled-by-default behavior, namespaced and nested calls, blocked or failed attempts, retry handling, and recorder limits. GitOrigin-RevId: 5ce917b73e797b0f6904d46477b9d2cf8ea71bf2
This commit is contained in:
@@ -1082,6 +1082,10 @@ impl Session {
|
||||
}).await;
|
||||
}
|
||||
|
||||
let executed_tool_calls = config
|
||||
.features
|
||||
.enabled(Feature::ExecutedToolCallMetadata)
|
||||
.then(|| Arc::new(crate::state::ExecutedToolCallRecorder::default()));
|
||||
let services = SessionServices {
|
||||
// Start with an empty connection set. The initialized set is
|
||||
// published after SessionConfigured so MCP events follow it.
|
||||
@@ -1159,6 +1163,7 @@ impl Session {
|
||||
session_configuration.parent_thread_id,
|
||||
),
|
||||
),
|
||||
executed_tool_calls,
|
||||
code_mode_service: crate::tools::code_mode::CodeModeService::new(
|
||||
Arc::clone(&code_mode_session_provider),
|
||||
&config.features,
|
||||
|
||||
@@ -5718,6 +5718,10 @@ pub(crate) async fn make_session_and_context() -> (Session, TurnContext) {
|
||||
));
|
||||
let network_approval = Arc::new(NetworkApprovalService::default());
|
||||
let mcp_runtime = Arc::new(codex_mcp::McpRuntime::empty(config.prefix_mcp_tool_names()));
|
||||
let executed_tool_calls = config
|
||||
.features
|
||||
.enabled(Feature::ExecutedToolCallMetadata)
|
||||
.then(|| Arc::new(crate::state::ExecutedToolCallRecorder::default()));
|
||||
let services = SessionServices {
|
||||
mcp_runtime,
|
||||
unified_exec_manager: UnifiedExecProcessManager::new(
|
||||
@@ -5793,6 +5797,7 @@ pub(crate) async fn make_session_and_context() -> (Session, TurnContext) {
|
||||
/*attestation_provider*/ None,
|
||||
config.http_client_factory(),
|
||||
),
|
||||
executed_tool_calls,
|
||||
code_mode_service: crate::tools::code_mode::CodeModeService::new(
|
||||
Arc::new(codex_code_mode::InProcessCodeModeSessionProvider),
|
||||
&config.features,
|
||||
@@ -7901,6 +7906,10 @@ where
|
||||
));
|
||||
let network_approval = Arc::new(NetworkApprovalService::default());
|
||||
let mcp_runtime = Arc::new(codex_mcp::McpRuntime::empty(config.prefix_mcp_tool_names()));
|
||||
let executed_tool_calls = config
|
||||
.features
|
||||
.enabled(Feature::ExecutedToolCallMetadata)
|
||||
.then(|| Arc::new(crate::state::ExecutedToolCallRecorder::default()));
|
||||
let services = SessionServices {
|
||||
mcp_runtime,
|
||||
unified_exec_manager: UnifiedExecProcessManager::new(
|
||||
@@ -7976,6 +7985,7 @@ where
|
||||
/*attestation_provider*/ None,
|
||||
config.http_client_factory(),
|
||||
),
|
||||
executed_tool_calls,
|
||||
code_mode_service: crate::tools::code_mode::CodeModeService::new(
|
||||
Arc::new(codex_code_mode::InProcessCodeModeSessionProvider),
|
||||
&config.features,
|
||||
|
||||
@@ -1336,6 +1336,7 @@ async fn run_sampling_request(
|
||||
let mut retries = 0;
|
||||
let mut initial_input = Some(input);
|
||||
let mut original_input = None;
|
||||
let mut executed_tool_calls_by_output = HashMap::new();
|
||||
loop {
|
||||
let prompt_input = if let Some(input) = initial_input.take() {
|
||||
input
|
||||
@@ -1344,6 +1345,13 @@ async fn run_sampling_request(
|
||||
.await
|
||||
.for_prompt(&turn_context.model_info.input_modalities)
|
||||
};
|
||||
let mut prompt_input = prompt_input;
|
||||
if let Some(executed_tool_calls) = sess.services.executed_tool_calls.as_ref()
|
||||
&& executed_tool_calls
|
||||
.attach_pending_to_prompt(&mut prompt_input, &mut executed_tool_calls_by_output)
|
||||
{
|
||||
codex_protocol::models::bound_executed_tool_calls_for_prompt(&mut prompt_input);
|
||||
}
|
||||
let prompt = build_prompt(
|
||||
prompt_input,
|
||||
router.as_ref(),
|
||||
|
||||
Reference in New Issue
Block a user