mirror of
https://github.com/openai/codex.git
synced 2026-05-02 18:37:01 +00:00
[tool search] support namespaced deferred dynamic tools (#18413)
Deferred dynamic tools need to round-trip a namespace so a tool returned by `tool_search` can be called through the same registry key that core uses for dispatch. This change adds namespace support for dynamic tool specs/calls, persists it through app-server thread state, and routes dynamic tool calls by full `ToolName` while still sending the app the leaf tool name. Deferred dynamic tools must provide a namespace; non-deferred dynamic tools may remain top-level. It also introduces `LoadableToolSpec` as the shared function-or-namespace Responses shape used by both `tool_search` output and dynamic tool registration, so dynamic tools use the same wrapping logic in both paths. Validation: - `cargo test -p codex-tools` - `cargo test -p codex-core tool_search` --------- Co-authored-by: Sayan Sisodiya <sayan@openai.com>
This commit is contained in:
@@ -8,6 +8,8 @@ use ts_rs::TS;
|
||||
#[derive(Debug, Clone, Serialize, PartialEq, JsonSchema, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct DynamicToolSpec {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub namespace: Option<String>,
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
pub input_schema: JsonValue,
|
||||
@@ -20,6 +22,8 @@ pub struct DynamicToolSpec {
|
||||
pub struct DynamicToolCallRequest {
|
||||
pub call_id: String,
|
||||
pub turn_id: String,
|
||||
#[serde(default)]
|
||||
pub namespace: Option<String>,
|
||||
pub tool: String,
|
||||
pub arguments: JsonValue,
|
||||
}
|
||||
@@ -44,6 +48,7 @@ pub enum DynamicToolCallOutputContentItem {
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct DynamicToolSpecDe {
|
||||
namespace: Option<String>,
|
||||
name: String,
|
||||
description: String,
|
||||
input_schema: JsonValue,
|
||||
@@ -57,6 +62,7 @@ impl<'de> Deserialize<'de> for DynamicToolSpec {
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let DynamicToolSpecDe {
|
||||
namespace,
|
||||
name,
|
||||
description,
|
||||
input_schema,
|
||||
@@ -65,6 +71,7 @@ impl<'de> Deserialize<'de> for DynamicToolSpec {
|
||||
} = DynamicToolSpecDe::deserialize(deserializer)?;
|
||||
|
||||
Ok(Self {
|
||||
namespace,
|
||||
name,
|
||||
description,
|
||||
input_schema,
|
||||
@@ -99,6 +106,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
actual,
|
||||
DynamicToolSpec {
|
||||
namespace: None,
|
||||
name: "lookup_ticket".to_string(),
|
||||
description: "Fetch a ticket".to_string(),
|
||||
input_schema: json!({
|
||||
|
||||
@@ -2441,6 +2441,9 @@ pub struct DynamicToolCallResponseEvent {
|
||||
pub call_id: String,
|
||||
/// Turn ID that this dynamic tool call belongs to.
|
||||
pub turn_id: String,
|
||||
/// Dynamic tool namespace, when one was provided.
|
||||
#[serde(default)]
|
||||
pub namespace: Option<String>,
|
||||
/// Dynamic tool name.
|
||||
pub tool: String,
|
||||
/// Dynamic tool call arguments.
|
||||
|
||||
Reference in New Issue
Block a user