mirror of
https://github.com/openai/codex.git
synced 2026-11-25 23:30:49 +00:00
Support structured dynamic tool results in Code Mode (#63766)
## Why Dynamic tool clients could return JSON as text in `contentItems`, so Code Mode scripts had to parse that text to access fields in the result. ## What changed App server dynamic tool requests advertise `supportedResultFormat: "structuredContent"`. Clients can reply with `structuredContent` and a `success` flag, report a failure with `errorMessage` and `success: false`, or continue using `contentItems`. Code Mode exposes structured replies as MCP-style tool results, with the original JSON under `structuredContent` and failure status in `isError`. Completed tool items include a text representation of the reply. Matching post-tool-use hooks can receive the structured result for successful calls. ## Testing Add protocol tests for the wire formats and rejection of ambiguous replies, plus an app server integration test that exercises structured results, content items, and errors through Code Mode. GitOrigin-RevId: d63152633b43bd5bd236f6e0dcb41ee7e98e7947
This commit is contained in:
@@ -1,5 +1,13 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"definitions": {
|
||||
"DynamicToolResultFormat": {
|
||||
"enum": [
|
||||
"structuredContent"
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"arguments": true,
|
||||
"callId": {
|
||||
@@ -11,6 +19,17 @@
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"supportedResultFormat": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/DynamicToolResultFormat"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
],
|
||||
"description": "Optional response format supported by the runtime serving this call."
|
||||
},
|
||||
"threadId": {
|
||||
"type": "string"
|
||||
},
|
||||
|
||||
@@ -1,6 +1,58 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/DynamicToolCallContentItems"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"structuredContent": true,
|
||||
"success": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"structuredContent",
|
||||
"success"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"errorMessage": {
|
||||
"type": "string"
|
||||
},
|
||||
"success": {
|
||||
"const": false,
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"errorMessage",
|
||||
"success"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
],
|
||||
"definitions": {
|
||||
"DynamicToolCallContentItems": {
|
||||
"properties": {
|
||||
"contentItems": {
|
||||
"items": {
|
||||
"$ref": "#/definitions/DynamicToolCallOutputContentItem"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"success": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"contentItems",
|
||||
"success"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"DynamicToolCallOutputContentItem": {
|
||||
"oneOf": [
|
||||
{
|
||||
@@ -66,21 +118,26 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"contentItems": {
|
||||
"items": {
|
||||
"$ref": "#/definitions/DynamicToolCallOutputContentItem"
|
||||
},
|
||||
"type": "array"
|
||||
"description": "A dynamic tool reply carrying content items, structured JSON, or an error message.",
|
||||
"oneOf": [
|
||||
{
|
||||
"required": [
|
||||
"contentItems"
|
||||
],
|
||||
"title": "ContentItemsDynamicToolCallResponse"
|
||||
},
|
||||
"success": {
|
||||
"type": "boolean"
|
||||
{
|
||||
"required": [
|
||||
"structuredContent"
|
||||
],
|
||||
"title": "StructuredContentDynamicToolCallResponse"
|
||||
},
|
||||
{
|
||||
"required": [
|
||||
"errorMessage"
|
||||
],
|
||||
"title": "ErrorMessageDynamicToolCallResponse"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"contentItems",
|
||||
"success"
|
||||
],
|
||||
"title": "DynamicToolCallResponse",
|
||||
"type": "object"
|
||||
"title": "DynamicToolCallResult"
|
||||
}
|
||||
@@ -484,6 +484,17 @@
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"supportedResultFormat": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/DynamicToolResultFormat"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
],
|
||||
"description": "Optional response format supported by the runtime serving this call."
|
||||
},
|
||||
"threadId": {
|
||||
"type": "string"
|
||||
},
|
||||
@@ -503,6 +514,12 @@
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"DynamicToolResultFormat": {
|
||||
"enum": [
|
||||
"structuredContent"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"ExecCommandApprovalParams": {
|
||||
"properties": {
|
||||
"approvalId": {
|
||||
|
||||
+88
-14
@@ -3096,6 +3096,24 @@
|
||||
"title": "CommandExecutionRequestApprovalResponse",
|
||||
"type": "object"
|
||||
},
|
||||
"DynamicToolCallContentItems": {
|
||||
"properties": {
|
||||
"contentItems": {
|
||||
"items": {
|
||||
"$ref": "#/definitions/v2/DynamicToolCallOutputContentItem"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"success": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"contentItems",
|
||||
"success"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"DynamicToolCallParams": {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"properties": {
|
||||
@@ -3109,6 +3127,17 @@
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"supportedResultFormat": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/DynamicToolResultFormat"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
],
|
||||
"description": "Optional response format supported by the runtime serving this call."
|
||||
},
|
||||
"threadId": {
|
||||
"type": "string"
|
||||
},
|
||||
@@ -3131,23 +3160,68 @@
|
||||
},
|
||||
"DynamicToolCallResponse": {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"properties": {
|
||||
"contentItems": {
|
||||
"items": {
|
||||
"$ref": "#/definitions/v2/DynamicToolCallOutputContentItem"
|
||||
},
|
||||
"type": "array"
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/DynamicToolCallContentItems"
|
||||
},
|
||||
"success": {
|
||||
"type": "boolean"
|
||||
{
|
||||
"properties": {
|
||||
"structuredContent": true,
|
||||
"success": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"structuredContent",
|
||||
"success"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"errorMessage": {
|
||||
"type": "string"
|
||||
},
|
||||
"success": {
|
||||
"const": false,
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"errorMessage",
|
||||
"success"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"contentItems",
|
||||
"success"
|
||||
],
|
||||
"title": "DynamicToolCallResponse",
|
||||
"type": "object"
|
||||
"description": "A dynamic tool reply carrying content items, structured JSON, or an error message.",
|
||||
"oneOf": [
|
||||
{
|
||||
"required": [
|
||||
"contentItems"
|
||||
],
|
||||
"title": "ContentItemsDynamicToolCallResponse"
|
||||
},
|
||||
{
|
||||
"required": [
|
||||
"structuredContent"
|
||||
],
|
||||
"title": "StructuredContentDynamicToolCallResponse"
|
||||
},
|
||||
{
|
||||
"required": [
|
||||
"errorMessage"
|
||||
],
|
||||
"title": "ErrorMessageDynamicToolCallResponse"
|
||||
}
|
||||
],
|
||||
"title": "DynamicToolCallResult"
|
||||
},
|
||||
"DynamicToolResultFormat": {
|
||||
"enum": [
|
||||
"structuredContent"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"ExecCommandApprovalParams": {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
+6
-1
@@ -2,5 +2,10 @@
|
||||
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { JsonValue } from "../serde_json/JsonValue";
|
||||
import type { DynamicToolResultFormat } from "./DynamicToolResultFormat";
|
||||
|
||||
export type DynamicToolCallParams = { threadId: string, turnId: string, callId: string, namespace: string | null, tool: string, arguments: JsonValue, };
|
||||
export type DynamicToolCallParams = {
|
||||
/**
|
||||
* Optional response format supported by the runtime serving this call.
|
||||
*/
|
||||
supportedResultFormat?: DynamicToolResultFormat, threadId: string, turnId: string, callId: string, namespace: string | null, tool: string, arguments: JsonValue, };
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// GENERATED CODE! DO NOT MODIFY BY HAND!
|
||||
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { JsonValue } from "../serde_json/JsonValue";
|
||||
import type { DynamicToolCallResponse } from "./DynamicToolCallResponse";
|
||||
|
||||
/**
|
||||
* A dynamic tool reply carrying content items, structured JSON, or an error message.
|
||||
*/
|
||||
export type DynamicToolCallResult = DynamicToolCallResponse | { structuredContent: JsonValue, success: boolean, } | { errorMessage: string, success: false, };
|
||||
@@ -0,0 +1,5 @@
|
||||
// GENERATED CODE! DO NOT MODIFY BY HAND!
|
||||
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
|
||||
export type DynamicToolResultFormat = "structuredContent";
|
||||
@@ -143,10 +143,12 @@ export type { DesktopOnboardingEntrypoint } from "./DesktopOnboardingEntrypoint"
|
||||
export type { DynamicToolCallOutputContentItem } from "./DynamicToolCallOutputContentItem";
|
||||
export type { DynamicToolCallParams } from "./DynamicToolCallParams";
|
||||
export type { DynamicToolCallResponse } from "./DynamicToolCallResponse";
|
||||
export type { DynamicToolCallResult } from "./DynamicToolCallResult";
|
||||
export type { DynamicToolCallStatus } from "./DynamicToolCallStatus";
|
||||
export type { DynamicToolFunctionSpec } from "./DynamicToolFunctionSpec";
|
||||
export type { DynamicToolNamespaceSpec } from "./DynamicToolNamespaceSpec";
|
||||
export type { DynamicToolNamespaceTool } from "./DynamicToolNamespaceTool";
|
||||
export type { DynamicToolResultFormat } from "./DynamicToolResultFormat";
|
||||
export type { DynamicToolSpec } from "./DynamicToolSpec";
|
||||
export type { EnvironmentConnectionNotification } from "./EnvironmentConnectionNotification";
|
||||
export type { EnvironmentSkillsParams } from "./EnvironmentSkillsParams";
|
||||
|
||||
Reference in New Issue
Block a user