mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Canonicalize default tools under the functions namespace (#37022)
## What changed - Group top-level function and custom tool definitions into a single `functions` namespace for Responses Lite providers that support namespaced tools. - Normalize missing, empty, and explicit `functions` namespaces to the same tool identity across registration, routing, lifecycle hooks, configuration, and tool search. - Keep default tool names unprefixed in code mode, display output, and dispatch traces while preserving explicit non-default namespaces. ## Testing - Add coverage for Responses Lite serialization, tool search results, namespace normalization and collision handling, routing, lifecycle events, and code-mode namespace policies. GitOrigin-RevId: d48414005b5d22d39b11a198e19c47814d3a19f2
This commit is contained in:
1 parent
1e489adad0
commit
f21dc46388
29 files changed
+522
-78
No files matched your search
@@ -290,7 +290,8 @@ impl ToolRegistry {
|
||||
runtime: Arc<dyn CoreToolRuntime>,
|
||||
exposure: ToolExposure,
|
||||
) {
|
||||
match self.tools.entry(runtime.tool_name()) {
|
||||
let tool_name = runtime.tool_name().with_default_namespace();
|
||||
match self.tools.entry(tool_name) {
|
||||
Entry::Vacant(entry) => {
|
||||
entry.insert(RegisteredTool { runtime, exposure });
|
||||
}
|
||||
@@ -302,7 +303,7 @@ impl ToolRegistry {
|
||||
}
|
||||
|
||||
pub(crate) fn prepend_trusted(&mut self, runtime: Arc<dyn CoreToolRuntime>) {
|
||||
let tool_name = runtime.tool_name();
|
||||
let tool_name = runtime.tool_name().with_default_namespace();
|
||||
if self.tools.contains_key(&tool_name) {
|
||||
error_or_panic(format!("tool {tool_name} already registered"));
|
||||
return;
|
||||
@@ -323,8 +324,8 @@ impl ToolRegistry {
|
||||
runtime: Arc<dyn CoreToolRuntime>,
|
||||
exposure: ToolExposure,
|
||||
) -> bool {
|
||||
let tool_name = runtime.tool_name();
|
||||
if tool_name.namespace.is_none() && tool_name.name == "shell_command" {
|
||||
let tool_name = runtime.tool_name().with_default_namespace();
|
||||
if tool_name.is_default_namespace() && tool_name.name == "shell_command" {
|
||||
tracing::warn!(tool_name = %tool_name, "skipping external tool with reserved name");
|
||||
if self.tools.contains_key(&tool_name) {
|
||||
self.record_collision(tool_name);
|
||||
@@ -358,7 +359,9 @@ impl ToolRegistry {
|
||||
}
|
||||
|
||||
pub(crate) fn remove(&mut self, tool_name: &ToolName) -> Option<Arc<dyn CoreToolRuntime>> {
|
||||
self.tools.shift_remove(tool_name).map(|tool| tool.runtime)
|
||||
self.tools
|
||||
.shift_remove(&tool_name.clone().with_default_namespace())
|
||||
.map(|tool| tool.runtime)
|
||||
}
|
||||
|
||||
pub(crate) fn entries(&self) -> impl Iterator<Item = &RegisteredTool> {
|
||||
@@ -372,7 +375,7 @@ impl ToolRegistry {
|
||||
pub(crate) fn deferred_tool_namespaces(&self) -> BTreeMap<String, String> {
|
||||
let mut namespaces = BTreeMap::<String, String>::new();
|
||||
for (name, tool) in &self.tools {
|
||||
if !tool.exposure.is_deferred() {
|
||||
if !tool.exposure.is_deferred() || name.is_default_namespace() {
|
||||
continue;
|
||||
}
|
||||
let Some(namespace) = &name.namespace else {
|
||||
@@ -410,7 +413,9 @@ impl ToolRegistry {
|
||||
}
|
||||
|
||||
pub(crate) fn tool(&self, name: &ToolName) -> Option<Arc<dyn CoreToolRuntime>> {
|
||||
self.tools.get(name).map(|tool| Arc::clone(&tool.runtime))
|
||||
self.tools
|
||||
.get(&name.clone().with_default_namespace())
|
||||
.map(|tool| Arc::clone(&tool.runtime))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -422,7 +427,9 @@ impl ToolRegistry {
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn tool_exposure(&self, name: &ToolName) -> Option<ToolExposure> {
|
||||
self.tools.get(name).map(|tool| tool.exposure)
|
||||
self.tools
|
||||
.get(&name.clone().with_default_namespace())
|
||||
.map(|tool| tool.exposure)
|
||||
}
|
||||
|
||||
pub(crate) fn create_diff_consumer(
|
||||
@@ -433,7 +440,7 @@ impl ToolRegistry {
|
||||
}
|
||||
|
||||
pub(crate) fn supports_parallel_tool_calls(&self, name: &ToolName) -> Option<bool> {
|
||||
let tool = self.tools.get(name)?;
|
||||
let tool = self.tools.get(&name.clone().with_default_namespace())?;
|
||||
Some(tool.exposure != ToolExposure::Hidden && tool.runtime.supports_parallel_tool_calls())
|
||||
}
|
||||
|
||||
@@ -504,7 +511,6 @@ impl ToolRegistry {
|
||||
return Err(err);
|
||||
}
|
||||
};
|
||||
|
||||
let telemetry_tags = tool.telemetry_tags(&invocation);
|
||||
let mut tool_result_tags =
|
||||
Vec::with_capacity(base_tool_result_tags.len() + telemetry_tags.len() + 1);
|
||||
@@ -773,10 +779,8 @@ async fn handle_any_tool(
|
||||
|
||||
fn function_hook_tool_name(invocation: &ToolInvocation) -> HookToolName {
|
||||
if invocation.tool_name.name == "spawn_agent"
|
||||
&& matches!(
|
||||
invocation.tool_name.namespace.as_deref(),
|
||||
None | Some(MULTI_AGENT_V1_NAMESPACE)
|
||||
)
|
||||
&& (invocation.tool_name.is_default_namespace()
|
||||
|| invocation.tool_name.namespace.as_deref() == Some(MULTI_AGENT_V1_NAMESPACE))
|
||||
{
|
||||
return HookToolName::spawn_agent();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user