Skip to content

Python: fix(openai): make function result call_id optional and omit when absent - #8041

Closed
JHf0912 wants to merge 2 commits into
microsoft:mainfrom
JHf0912:fix/7922-function-result-call-id
Closed

Python: fix(openai): make function result call_id optional and omit when absent#8041
JHf0912 wants to merge 2 commits into
microsoft:mainfrom
JHf0912:fix/7922-function-result-call-id

Conversation

@JHf0912

@JHf0912 JHf0912 commented Sep 3, 2026

Copy link
Copy Markdown

Problem

Content.from_function_result still requires call_id: str, although the OpenAI Responses API no longer requires a call id on function call results. Consumers translating between OpenAI-spec SDKs and MAF must fight the type system — the AG-UI tests already pass call_id=None with # type: ignore comments — and _prepare_content_for_openai emits "call_id": null in function_call_output items when the id is absent.

Solution

Relax Content.from_function_result to accept call_id: str | None = None, a backward-compatible widening since every existing caller passes a str. In the Responses client, omit the call_id key when absent instead of sending null, keeping the payload unchanged when a call id is present. As regression evidence, the now-redundant triple-checker type: ignore comment in the AG-UI tests is removed.

Changes

  • python/packages/core/agent_framework/_types.py: widen signature + docstring update
  • python/packages/openai/agent_framework_openai/_chat_client.py: conditional call_id emission in the function_call_output branch
  • Tests: new cases in test_types.py (core) and test_openai_chat_client.py (openai); type-ignore cleanup in test_run_common.py (ag-ui)

Testing

  • New unit tests: result without call id → key omitted; result with call id → key preserved (regression)
  • Affected suites pass: core test_types.py, openai test_openai_chat_client.py, ag-ui test_run_common.py
  • Regression sweep on packages calling from_function_result (anthropic / a2a / bedrock / chatkit): all green
  • pyright strict: 0 errors; ruff: clean

Notes for Reviewer

  • The function_call (assistant-side) branch that drops content without a call id is intentionally unchanged — the API still requires it there.
  • Shell call output branches (shell_call_output / local_shell_call) keep their own id schemes and were not touched.
  • The signature change is backward compatible: all existing call sites pass a str.

Fixes #7922

Copilot AI balanced review requested due to automatic review settings September 3, 2026 16:20
@JHf0912
JHf0912 deployed to github-app-auth September 3, 2026 16:20 — with GitHub Actions Active
@JHf0912
JHf0912 deployed to github-app-auth September 3, 2026 16:20 — with GitHub Actions Active
@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Sep 3, 2026
@JHf0912
JHf0912 deployed to github-app-auth September 3, 2026 16:20 — with GitHub Actions Active
@github-actions github-actions Bot changed the title fix(openai): make function result call_id optional and omit when absent Python: fix(openai): make function result call_id optional and omit when absent Sep 3, 2026

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

The focused, backward-compatible change correctly implements the updated API contract with appropriate regression coverage.

Pull request overview

Makes function-result call IDs optional and aligns OpenAI Responses payload serialization accordingly.

Changes:

  • Allows function results without a call_id.
  • Omits absent call IDs from OpenAI payloads while preserving present IDs.
  • Adds regression tests and removes obsolete type suppressions.
File summaries
File Description
python/packages/core/agent_framework/_types.py Makes call_id optional.
python/packages/core/tests/core/test_types.py Tests missing call IDs.
python/packages/openai/agent_framework_openai/_chat_client.py Conditionally emits call_id.
python/packages/openai/tests/openai/test_openai_chat_client.py Tests payload serialization.
python/packages/ag-ui/tests/ag_ui/test_run_common.py Removes obsolete type ignores.
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 0
  • Review effort level: Balanced

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

@JHf0912

JHf0912 commented Sep 4, 2026

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

The OpenAI Responses API no longer requires a call id on function call
results, but Content.from_function_result still required a str and the
Responses client emitted "call_id": null when the id was absent. Relax
the signature to str | None = None and omit the key in outbound
function_call_output items, keeping the existing behavior when a call id
is present.

Fixes microsoft#7922
The signature now accepts call_id=None, so the triple-checker ignore
comment is no longer needed.
@JHf0912
JHf0912 force-pushed the fix/7922-function-result-call-id branch from ea9a5c2 to c7720e3 Compare September 4, 2026 06:46
@JHf0912
JHf0912 deployed to github-app-auth September 4, 2026 06:46 — with GitHub Actions Active
@eavanvalkenburg

Copy link
Copy Markdown
Member

This is a duplicate of #7928

@JHf0912

JHf0912 commented Sep 4, 2026

Copy link
Copy Markdown
Author

Thanks for the pointer, Eduard van Valkenburg (@eavanvalkenburg). I see it now: #7988 established the Content.id / call_id identity contract, and making anonymous function results generally valid would weaken it — orphan results could leak through invocation, approvals, history, compaction, and non-OpenAI adapters. That rationale makes sense.

I'll close this PR. Since #7922 remains open for a Responses-boundary redesign, I'd be glad to contribute there — e.g., compiling the schema-level matrix of id-less wire combinations and drafting a boundary-scoped design that does not touch core semantics. Happy to coordinate if that would be useful.

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

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: OpenAI RAPI no longer requires the call id on a function call result

3 participants