feat: codex integration#84
Draft
haoshan98 wants to merge 8 commits into
Draft
Conversation
Signed-off-by: haoshan98 <haoshanw@gmail.com>
Signed-off-by: haoshan98 <haoshanw@gmail.com>
Signed-off-by: haoshan98 <haoshanw@gmail.com>
Signed-off-by: haoshan98 <haoshanw@gmail.com>
Signed-off-by: haoshan98 <haoshanw@gmail.com>
Signed-off-by: haoshan98 <haoshanw@gmail.com>
Collaborator
|
awesome @haoshan98 let me know when this is ready for review |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Codex CLI Tool Call Responses Compatibility
Summary
This PR adds Codex CLI compatibility to
agentic-apias a stateful Responses API gateway in front of anOpenAI-compatible vLLM endpoint.
The primary runtime path is:
A typical local validation path is:
The gateway keeps Codex-facing request and response shapes stable while adapting tool declarations and tool calls to
the upstream model server's stricter function-tool surface. This lets Codex use
agentic-apiwith both HTTP/SSE andWebSocket Responses transports, while preserving stateful continuation through
previous_response_idand storedconversation history.
What Changed
Codex Responses Gateway
/v1/responsesbehavior for the latestmainHTTP and WebSocket server paths.main's more general tool framework and routed Codex-specific namespace flattening through thatframework instead of bypassing it.
store=falserequests without continuation IDs on the proxy path, with compatibility normalization for modelaliases, instructions, namespace tools, tool choice, and returned tool calls.
store=trueand WebSocket sessions on the stateful executor path with response storage, continuation, andhydration.
Tool Shape Support
The typed Responses request path now accepts the Codex tool shapes emitted by Codex CLI:
functionnamespacetool_searchcustomKnown tool types preserve extra fields, and unknown tool types remain raw JSON rather than being discarded. On the typed
stateful executor path, namespace members are flattened into upstream-safe
functiontools for vLLM. Non-function Codexdeclarations remain accepted and preserved in metadata for continuations.
Namespace Flattening And Restoration
Codex namespace tools, such as MCP tools, are represented as grouped namespace/member declarations:
{ "type": "namespace", "name": "mcp__agentic_fixture", "tools": [ { "type": "function", "name": "add_numbers" } ] }To avoid upstreams that reserve or reject
mcp__function names, namespace members are flattened using anupstream-visible name with an agentic-specific prefix:
When the upstream model returns that flat tool call,
agentic-apirestores the Codex-facing shape:{ "type": "function_call", "namespace": "mcp__agentic_fixture", "name": "add_numbers" }The normalization layer also accepts observed variants where safe:
mcp__agentic_fixture.add_numbersmcp__agentic_fixture_add_numbersCollision checks prevent unsafe flattening when a namespaced member would conflict with a top-level function name.
Tool Choice Preservation
tool_choicenow preserves optional namespace information. Explicit namespaced choices are flattened only for upstreamrequests and restored for Codex-facing response/storage paths.
Stateful Continuation
The executor stores the effective request metadata needed for continuations:
Later requests using
previous_response_idorconversation_idhydrate the prior context and reuse the effectiveCodex-compatible tool metadata unless the client explicitly overrides it.
Storage Rehydration Cleanup
Stored input/output item markers are used internally to avoid ambiguity, but raw rehydrated items strip internal markers
such as
_agentic_item_kindbefore returning data to the client or forwarding hydrated history upstream.Model Listing And Readiness
mainmodel-list route by adapting/v1/modelsbehavior for Codex clients while preservingupstream proxy behavior where applicable.
skip_llm_ready_checksupport for the startup LLM readiness check used by hosted/OpenAI-compatible vLLMendpoints where
/healthmay not exist. The/readyroute still keeps its existing upstream health probe semantics.WebSocket Support
Codex can now be configured with:
With
supports_websockets = true, Codex uses the Responses WebSocket path when available. The gateway preserves the sametool normalization, model aliasing, and stateful continuation semantics across HTTP/SSE and WebSocket transports.
Running A Codex Session
The PR includes
scripts/codex-start-gateway.shto startagentic-serveragainst a configured vLLM endpoint and registerthe Codex-facing model alias.
Start the gateway:
From the repo root, run a Codex HTTP/SSE session:
From the repo root, run a Codex WebSocket session:
Cassette Recording
This PR adds Codex cassette recording support under:
The main recorder wrapper is:
It records YAML replay cassettes for the matrix covered by tests:
The
alltarget now regenerates every cassette used by the Codex cassette tests. Direct vLLM recording requires anexplicit
VLLM_URLorV_API_BASEinstead of defaulting to a private LAN endpoint.Example:
Cassette Replay Tests
Replay and normalization tests were added for the recorded Codex cassettes:
crates/agentic-core/tests/accumulator_cassette_test.rsprevious_response_idplusfunction_call_outputcontinuation shapecrates/agentic-core/tests/tool_normalization_test.rsRequestPayloadstreamfieldagentic_ns__mcp__agentic_fixture__add_numbersThese tests make the Codex integration behavior replayable without requiring live OpenAI, vLLM, or Codex CLI access in
normal CI-style test runs.
Scope Boundaries
This PR does not implement:
agentic-apiCodex still owns MCP tool discovery and execution.
agentic-apipreserves, normalizes, forwards, stores, and restoresResponses API data so Codex can continue its loop correctly.
Test Plan
Formatting and diff checks:
Core Rust tests:
Additional checks run during review:
Cassette regeneration was run successfully with:
and
cargo testpassed afterward.Manual live validation during development covered:
agentic-apiagentic-apiwithsupports_websockets = truemcp__agentic_fixture.add_numbers