Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix OpenAI UnprocessableEntityError when AssistantAgent makes multiple tool calls#6799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
Copilot wants to merge5 commits intomain
base:main
Choose a base branch
Loading
fromcopilot/fix-6788

Conversation

Copilot
Copy link
Contributor

@CopilotCopilotAI commentedJul 11, 2025
edited
Loading

Problem

When anAssistantAgent makes multiple tool calls in response to a task, the OpenAI API returns anUnprocessableEntityError(422) with the error message:

'detail': [{'type': 'missing', 'loc': ['body', 'messages', 2, 'content'], 'msg': 'Field required'}]

This occurs because the transformed assistant message containstool_calls but is missing the requiredcontent field.

Root Cause

The issue was in the message transformation pipeline in_message_transform.py. When anAssistantMessage has tool calls but no thought, it uses thetools_assistant_transformer_funcs which only included:

  • _set_tool_calls (adds the tool_calls field)
  • Base transformers (adds role, name validation)

But it was missing a content field setter, resulting in messages like:

{"role":"assistant","tool_calls": [...]// Missing required "content" field}

According to OpenAI's API specification, assistant messages with tool calls must include acontent field (which can benull).

Solution

Added a new transformer function_set_null_content_for_tool_calls that setscontent: null for tool calls without thought, and updatedtools_assistant_transformer_funcs to include it.

Before:

tools_assistant_transformer_funcs=base_assistant_transformer_funcs+ [_set_tool_calls]# Result: {"role": "assistant", "tool_calls": [...]}  # Missing content

After:

tools_assistant_transformer_funcs=base_assistant_transformer_funcs+ [_set_tool_calls,_set_null_content_for_tool_calls,]# Result: {"role": "assistant", "tool_calls": [...], "content": null}  # Complete

Testing

Added comprehensive test coverage for both scenarios:

  • AssistantMessage with tool calls but no thought →content: null
  • AssistantMessage with tool calls and thought →content: thought_text

Impact

  • Fixes the exact issue: No more OpenAI UnprocessableEntityError(422) for multiple tool calls
  • Minimal and surgical: Only 7 lines added to core code, no existing functionality modified
  • Backward compatible: All existing scenarios continue to work unchanged
  • API compliant: Follows OpenAI specification requirements exactly

Fixes#6788.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn moreCopilot coding agent tips in the docs.

…nt field is always presentCo-authored-by: ekzhu <320302+ekzhu@users.noreply.github.com>
@CopilotCopilotAI changed the title[WIP] OpenAI.UnprocessableEntityError(422) when AssistantAgent invokes multiple tool callsFix OpenAI UnprocessableEntityError when AssistantAgent makes multiple tool callsJul 11, 2025
@CopilotCopilotAI requested a review fromekzhuJuly 11, 2025 11:56
Copilot finished work on behalf ofekzhuJuly 11, 2025 11:56


@pytest.mark.asyncio
async def test_assistant_message_tool_calls_content_field() -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use other tests as examples and change this test to use a mock client, see if the mock client is invoked with appropriate content.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Updated the test to use a mock client pattern following other tests in the file. The test now usesAsyncMock to mock the OpenAI client'screate method and verifies that the API call includes the requiredcontent field properly set. Commit:54e9897

…tingCo-authored-by: ekzhu <320302+ekzhu@users.noreply.github.com>
@CopilotCopilotAI requested a review fromekzhuJuly 17, 2025 18:14
Copilot finished work on behalf ofekzhuJuly 17, 2025 18:14
@codecovCodecov
Copy link

codecovbot commentedJul 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.92%. Comparing base(413d8f1) to head(3ceb3c1).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@##             main    #6799      +/-   ##==========================================- Coverage   80.81%   79.92%   -0.90%==========================================  Files         233      233                Lines       18074    18108      +34     ==========================================- Hits        14607    14473     -134- Misses       3467     3635     +168
FlagCoverage Δ
unittests79.92% <100.00%> (-0.90%)⬇️

Flags with carried forward coverage won't be shown.Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report?Share it here.

🚀 New features to boost your workflow:
  • ❄️Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

@ekzhuekzhuAwaiting requested review from ekzhu

Requested changes must be addressed to merge this pull request.

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

OpenAI.UnprocessableEntityError(422) when AssistantAgent invokes multiple tool calls
2 participants
@Copilot@ekzhu

[8]ページ先頭

©2009-2025 Movatter.jp