-
Notifications
You must be signed in to change notification settings - Fork 939
Add Python tool call/result content types and update connectors and samples #2971
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
eavanvalkenburg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking good so far, there are also samples with image generation and code, can you update those as well @copilot
python/packages/core/agent_framework/openai/_responses_client.py
Outdated
Show resolved
Hide resolved
python/packages/core/agent_framework/openai/_responses_client.py
Outdated
Show resolved
Hide resolved
Updated the OpenAI image generation and code interpreter samples to use the new tool call/result content shapes and proper tool lists (1079faa). Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some additional comments, and the McpServer contents also need handling, also those names should be MCP instead of Mcp (python standard vs dotnet standard) @copilot
python/packages/core/agent_framework/openai/_responses_client.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couple of notes, and OpenAI Assistants also supports Code Interpreter, so that needs handling. Anthropic also support HostedMCPTool and Code interpreter, so those types need handling as well. @copilot
python/packages/core/agent_framework/openai/_responses_client.py
Outdated
Show resolved
Hide resolved
Updated MCP content naming, parsing, and connector handling; also added option translation for image generation tools as requested (3866935).
Added code interpreter and MCP handling across Responses, Assistants, and Anthropic connectors to emit the new content types (3866935). |
|
@copilot FunctionApprovalRequestContent also needs to allow MCPServerToolCallContent as the function_call inside of it. |
|
@copilot python/packages/core/agent_framework/openai/_responses_client.py:348 is not needed, folks should use the Tool type |
|
@copilot a couple of tests failed, run |
Added a guard to skip lightning tests when agentlightning isn’t installed and fixed the missing FunctionCallContent import; Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Co-authored-by: eavanvalkenburg <[email protected]>
…tool support Co-authored-by: eavanvalkenburg <[email protected]>
Co-authored-by: eavanvalkenburg <[email protected]>
Co-authored-by: eavanvalkenburg <[email protected]>
Co-authored-by: eavanvalkenburg <[email protected]>
Co-authored-by: eavanvalkenburg <[email protected]>
Co-authored-by: eavanvalkenburg <[email protected]>
Co-authored-by: eavanvalkenburg <[email protected]>
Co-authored-by: eavanvalkenburg <[email protected]>
Co-authored-by: eavanvalkenburg <[email protected]>
Co-authored-by: eavanvalkenburg <[email protected]>
Co-authored-by: eavanvalkenburg <[email protected]>
Co-authored-by: eavanvalkenburg <[email protected]>
6825e70 to
949d615
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds Python parity with .NET's MEAI by introducing new content types for tool calls and results (code interpreter, MCP server, image generation), extending HostedFileContent with optional metadata, and updating connectors to emit these specialized types.
Key Changes:
- Added six new content types:
CodeInterpreterToolCallContent,CodeInterpreterToolResultContent,ImageGenerationToolCallContent,ImageGenerationToolResultContent,MCPServerToolCallContent,MCPServerToolResultContent - Added
HostedImageGenerationToolwith typed options for image generation parameters - Updated OpenAI Responses and Assistants clients to emit paired tool call/result contents and surface specialized tool types
- Updated Anthropic connector to distinguish MCP server and code interpreter tool calls from generic function calls
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
python/packages/core/agent_framework/_types.py |
Added six new content types for code interpreter, image generation, and MCP server tool calls/results; extended HostedFileContent with optional media_type and name; updated Contents union and _parse_content function; modified FunctionApprovalRequestContent to accept MCPServerToolCallContent |
python/packages/core/agent_framework/_tools.py |
Added HostedImageGenerationTool with typed options; updated _auto_invoke_function to handle MCPServerToolCallContent |
python/packages/core/agent_framework/openai/_responses_client.py |
Updated response parsing to emit paired call/result contents for code interpreter, image generation, and MCP server; added HostedImageGenerationTool conversion with option mapping; removed raw dict parameter remapping for image generation |
python/packages/core/agent_framework/openai/_assistants_client.py |
Added support for code interpreter and MCP tool calls in assistants API by detecting tool types and creating appropriate content types |
python/packages/anthropic/agent_framework_anthropic/_chat_client.py |
Updated to emit MCPServerToolCallContent for mcp_tool_use and CodeInterpreterToolCallContent for code execution tools; changed mcp_tool_result to emit MCPServerToolResultContent |
python/packages/core/agent_framework/_workflows/_handoff.py |
Updated type signatures to accept MCPServerToolCallContent in addition to FunctionCallContent for handoff resolution |
python/samples/getting_started/agents/openai/openai_responses_client_with_code_interpreter.py |
Updated to use new CodeInterpreterToolCallContent and CodeInterpreterToolResultContent types to extract code and outputs |
python/samples/getting_started/agents/openai/openai_responses_client_image_generation.py |
Updated to use HostedImageGenerationTool and ImageGenerationToolResultContent for cleaner image generation handling |
python/packages/core/tests/core/test_types.py |
Added tests for new content types including HostedFileContent optional fields, code interpreter, image generation, and MCP server tool content types |
python/packages/core/tests/core/test_tools.py |
Added tests for HostedImageGenerationTool with default and custom options |
python/packages/core/tests/openai/test_openai_responses_client.py |
Updated tests to verify paired call/result content emission, added HostedImageGenerationTool conversion test, updated parameter handling tests |
python/packages/ollama/pyproject.toml |
Fixed typo: changed "extend" to "extends" for pyright configuration |
python/packages/lab/lightning/tests/test_lightning.py |
Added pytest.importorskip guard to skip tests when agentlightning is not installed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Motivation and Context
MEAI introduced new content types for tool calls/results (code interpreter, MCP server, image generation) and enhancements to hosted file metadata; Python core needed parity so connectors can emit/consume these shapes.
Description
CodeInterpreterToolCallContent,CodeInterpreterToolResultContent,ImageGenerationToolCallContent,ImageGenerationToolResultContent,MCPServerToolCallContent,MCPServerToolResultContent; extendedHostedFileContentwith optionalmedia_typeandname; updatedContentsunion and serialization.FunctionApprovalRequestContentnow acceptsMCPServerToolCallContentin addition to standard function calls.HostedImageGenerationToolwith typed options/additional properties and translate those options to OpenAI Responses parameters.FunctionCallContentfor non-code-execution tools, fixed missingChatResponse/CitationAnnotationimports and code-block handling to satisfy type checks, and ensured MCP parsing/typing is consistent.agentlightningis not installed.Example:
Contribution Checklist
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.