Skip to content

Preserve tool call/result roundtrip and raw payloads across Claude, Gemini and OpenAI adapters#147

Merged
CJackHwang merged 3 commits intodevfrom
codex/fix-tool-call-history-retrieval
Mar 22, 2026
Merged

Preserve tool call/result roundtrip and raw payloads across Claude, Gemini and OpenAI adapters#147
CJackHwang merged 3 commits intodevfrom
codex/fix-tool-call-history-retrieval

Conversation

@CJackHwang
Copy link
Owner

Motivation

  • Improve handling of tool calls and tool results so roundtrip metadata and raw payloads are preserved across the Claude, Gemini and OpenAI adapters and avoid injecting legacy history markers.
  • Normalize assistant tool-call representations into structured envelopes so downstream code can reliably detect tool_calls and tool messages.

Description

  • Rewrote normalizeClaudeMessages to split text blocks, convert tool_use blocks into assistant tool_calls envelopes, convert tool_result blocks into tool messages, and preserve raw unknown blocks as JSON via formatClaudeBlockRaw.
  • Updated tool prompt generation in buildClaudeToolPrompt to remove legacy marker instructions and keep clear instructions about not printing tool-call JSON, and added helpers normalizeClaudeToolUseToAssistant and normalizeClaudeToolResultToToolMessage.
  • Enhanced OpenAI normalization in normalizeOpenAIMessagesForPrompt, splitting logic into buildAssistantContentForPrompt, buildToolContentForPrompt, and normalizeAssistantToolCallsForPrompt so assistant tool_calls and tool/function roles are preserved as tool messages with serialized envelopes.
  • Adjusted responses input normalization in normalizeResponsesInputItemWithState to preserve assistant tool_calls and to include tool_call_id/name metadata for tool/function roles.
  • Updated prompt rendering in MessagesPrepare to handle tool role formatting when building the final prompt.
  • Added/updated tests: new Gemini tests in convert_messages_test.go, extended Claude tests in handler_util_test.go, and multiple updates to OpenAI normalization tests in message_normalize_test.go to assert preservation of tool envelopes and metadata.

Testing

  • Ran unit tests with go test ./... across the repository and all tests completed successfully.
  • Updated OpenAI unit tests in internal/adapter/openai/message_normalize_test.go to reflect preserved tool role and assistant tool_calls, and those tests passed.
  • Added Gemini tests in internal/adapter/gemini/convert_messages_test.go and updated Claude tests in internal/adapter/claude/handler_util_test.go, and both test suites passed.

Codex Task

@vercel
Copy link

vercel bot commented Mar 22, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ds2api Ready Ready Preview, Comment Mar 22, 2026 5:06am

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 59bf78d2c4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@CJackHwang CJackHwang merged commit e828006 into dev Mar 22, 2026
3 checks passed
@CJackHwang CJackHwang deleted the codex/fix-tool-call-history-retrieval branch March 22, 2026 05:06
CJackHwang added a commit that referenced this pull request Mar 22, 2026
Merge pull request #147 from CJackHwang/codex/fix-tool-call-history-retrieval

Preserve tool call/result roundtrip and raw payloads across Claude, Gemini and OpenAI adapters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant