mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Allow hosts to customize wait_for_environment descriptions (#35106)
## What changed - Add `WaitForEnvironmentToolConfig` as thread extension data for overriding the model-visible tool and `environment_id` descriptions. - Preserve the default descriptions when no override is provided or when the configured descriptions exceed the input or serialized tool-spec limits. - Keep `wait_for_environment` availability gated by the deferred executor feature independently of whether a host override is present. ## Testing - Cover default, custom, oversized, and feature-disabled tool configurations. - Verify the custom descriptions in the deferred-environment integration flow. GitOrigin-RevId: 6b49a73a434becd99ea5df911be53f3706a17c0a
This commit is contained in:
1 parent
a28374e0db
commit
81da9deb06
12 files changed
+317
-42
No files matched your search
@@ -78,6 +78,7 @@ pub(crate) use unified_exec::ExecCommandHandlerOptions;
|
||||
pub use unified_exec::WriteStdinHandler;
|
||||
pub use view_image::ViewImageHandler;
|
||||
pub(crate) use wait_for_environment::WaitForEnvironmentHandler;
|
||||
pub use wait_for_environment::WaitForEnvironmentToolConfig;
|
||||
|
||||
pub(crate) fn parse_arguments<T>(arguments: &str) -> Result<T, FunctionCallError>
|
||||
where
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use codex_tools::JsonSchema;
|
||||
use codex_tools::JsonToolOutput;
|
||||
use codex_tools::ResponsesApiTool;
|
||||
@@ -7,6 +5,7 @@ use codex_tools::ToolName;
|
||||
use codex_tools::ToolSpec;
|
||||
use serde::Deserialize;
|
||||
use serde_json::json;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use crate::function_tool::FunctionCallError;
|
||||
use crate::tools::context::ToolInvocation;
|
||||
@@ -17,6 +16,24 @@ use crate::tools::registry::CoreToolRuntime;
|
||||
use crate::tools::registry::ToolExecutor;
|
||||
|
||||
const WAIT_FOR_ENVIRONMENT_TOOL_NAME: &str = "wait_for_environment";
|
||||
const DEFAULT_TOOL_DESCRIPTION: &str = "Wait for a selected execution environment marked as `starting` to become available. Use this when the current task needs that environment's files, commands, or installed capabilities. Do not wait if the task can be completed using tools already available, such as connectors. Waiting may take several minutes and blocks other tool calls. If startup fails, continue without that environment.";
|
||||
const DEFAULT_ENVIRONMENT_ID_DESCRIPTION: &str =
|
||||
"The exact environment ID marked as `starting` in `<environment_context>`.";
|
||||
const MAX_COMBINED_DESCRIPTION_BYTES: usize = 1_024;
|
||||
const MAX_SERIALIZED_TOOL_SPEC_BYTES: usize = 1_000;
|
||||
|
||||
/// Model-visible descriptions supplied by a host that supports deferred environments.
|
||||
///
|
||||
/// The two tool-schema descriptions must not exceed 1,024 UTF-8 bytes in total, and Core
|
||||
/// also limits the complete serialized tool specification to 1,000 bytes. Oversized
|
||||
/// descriptions fall back to Core defaults.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct WaitForEnvironmentToolConfig {
|
||||
/// Explains when and why the model should call `wait_for_environment`.
|
||||
pub tool_description: String,
|
||||
/// Explains how the model should select the `environment_id` argument.
|
||||
pub environment_id_description: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
@@ -24,7 +41,44 @@ struct WaitForEnvironmentArgs {
|
||||
environment_id: String,
|
||||
}
|
||||
|
||||
pub(crate) struct WaitForEnvironmentHandler;
|
||||
pub(crate) struct WaitForEnvironmentHandler {
|
||||
tool_description: String,
|
||||
environment_id_description: String,
|
||||
}
|
||||
|
||||
impl WaitForEnvironmentHandler {
|
||||
pub(crate) fn new(config: &WaitForEnvironmentToolConfig) -> Self {
|
||||
let combined_description_bytes = config
|
||||
.tool_description
|
||||
.len()
|
||||
.saturating_add(config.environment_id_description.len());
|
||||
if combined_description_bytes <= MAX_COMBINED_DESCRIPTION_BYTES {
|
||||
let handler = Self {
|
||||
tool_description: config.tool_description.clone(),
|
||||
environment_id_description: config.environment_id_description.clone(),
|
||||
};
|
||||
if serde_json::to_vec(&handler.spec())
|
||||
.is_ok_and(|serialized| serialized.len() <= MAX_SERIALIZED_TOOL_SPEC_BYTES)
|
||||
{
|
||||
return handler;
|
||||
}
|
||||
}
|
||||
|
||||
tracing::warn!(
|
||||
"oversized wait_for_environment tool configuration; falling back to Core defaults"
|
||||
);
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for WaitForEnvironmentHandler {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
tool_description: DEFAULT_TOOL_DESCRIPTION.to_string(),
|
||||
environment_id_description: DEFAULT_ENVIRONMENT_ID_DESCRIPTION.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToolExecutor<ToolInvocation> for WaitForEnvironmentHandler {
|
||||
fn tool_name(&self) -> ToolName {
|
||||
@@ -34,17 +88,13 @@ impl ToolExecutor<ToolInvocation> for WaitForEnvironmentHandler {
|
||||
fn spec(&self) -> ToolSpec {
|
||||
ToolSpec::Function(ResponsesApiTool {
|
||||
name: WAIT_FOR_ENVIRONMENT_TOOL_NAME.to_string(),
|
||||
description: "Wait for a selected execution environment marked as `starting` to become available. Use this when the current task needs that environment's files, commands, or installed capabilities. Do not wait if the task can be completed using tools already available, such as connectors. Waiting may take several minutes and blocks other tool calls. If startup fails, continue without that environment."
|
||||
.to_string(),
|
||||
description: self.tool_description.clone(),
|
||||
strict: false,
|
||||
defer_loading: None,
|
||||
parameters: JsonSchema::object(
|
||||
BTreeMap::from([(
|
||||
"environment_id".to_string(),
|
||||
JsonSchema::string(Some(
|
||||
"The exact environment ID marked as `starting` in `<environment_context>`."
|
||||
.to_string(),
|
||||
)),
|
||||
JsonSchema::string(Some(self.environment_id_description.clone())),
|
||||
)]),
|
||||
/*required*/ Some(vec!["environment_id".to_string()]),
|
||||
/*additional_properties*/ Some(false.into()),
|
||||
|
||||
Reference in new issue
Block a user