Skip to content

Python: Preserve tool call IDs in chat history XML - #14440

Open
Gali (Jokasa7) wants to merge 1 commit into
microsoft:mainfrom
Jokasa7:JoyCx/fix-chat-history-xml-call-id
Open

Gali (Jokasa7) wants to merge 1 commit into
microsoft:mainfrom
Jokasa7:JoyCx/fix-chat-history-xml-call-id

Conversation

@Jokasa7

Copy link
Copy Markdown

Motivation and Context

Python ChatHistory.to_prompt() / str(history) followed by ChatHistory.from_rendered_prompt() drops call_id from function calls and results. For Responses API content, the item id and the tool-call correlation call_id are distinct. After this XML round trip, the existing Responses request adapter emits call_id=None for tool outputs (and for function calls when store_enabled=False). The JSON round trip already preserves these fields.

Description

Serialize the existing optional call_id field as an XML attribute in FunctionCallContent and FunctionResultContent, and read it when reconstructing each object. XML without the attribute continues to deserialize with call_id=None. This does not change the existing id field or introduce an ID fallback.

Regression tests exercise both public XML serialization entry points, legacy content without a correlation ID, and the actual Responses request preparation for both store_enabled modes.

Validation

  • New regression cases against the original implementation: 4 failed, 2 passed.
  • pytest tests/unit/contents tests/unit/agents/openai_responses: 438 passed, with 71 existing deprecation warnings.
  • Official Python pre-commit checks passed both for all changed files and for the whole repository in a clean worktree with this same patch.
  • Full-package mypy semantic_kernel: 23 errors in 6 files, identical line-for-line in a clean worktree at the original commit using the same environment. These errors are in unchanged code; this is not a claim of a clean full-package type check.
  • An independent agent review also checked XML escaping, multiple calls, and backward compatibility. No live provider request was sent; request payload generation was verified locally.

Contribution Checklist

  • The code builds clean without any errors or warnings — the full-package type-check limitation is recorded above.
  • The PR follows the SK Contribution Guidelines and the pre-submission formatting script raises no violations.
  • All unit tests pass, and I have added new tests where possible — the relevant 438 tests passed; the entire optional-provider suite was not run.
  • The added tests preserve legacy XML behavior and keep item IDs separate from tool-call correlation IDs.

Prepared with AI assistance, including the implementation, tests, and this description. Local regression verification and an independent agent review are recorded above.

Copilot AI lite review requested due to automatic review settings September 13, 2026 13:19
@Jokasa7
Gali (Jokasa7) requested a review from a team as a code owner September 13, 2026 13:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

All reviewed changes and regression coverage are complete with no unresolved blocking issues.

Pull request overview

Preserves Responses API tool-call call_id values through chat-history XML serialization and deserialization.

Changes:

  • Adds XML serialization and restoration for call_id.
  • Adds XML round-trip and legacy compatibility tests.
  • Verifies Responses request payloads for both storage modes.
File summaries
File Description
python/tests/unit/contents/test_chat_history.py Tests XML round-trip preservation and legacy behavior.
python/tests/unit/agents/openai_responses/test_openai_responses_thread_actions.py Tests prepared Responses payloads.
python/semantic_kernel/contents/function_result_content.py Persists function-result call_id in XML.
python/semantic_kernel/contents/function_call_content.py Persists function-call call_id in XML.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants