improvement: rewrite ADK adapter to use Portkey Responses API#421
improvement: rewrite ADK adapter to use Portkey Responses API#421viraj-s15 wants to merge 5 commits intoPortkey-AI:mainfrom
Conversation
|
thankyou @viraj-s15 we'll get this tested and reviewed |
There was a problem hiding this comment.
Pull request overview
Migrates the Google ADK adapter to use Portkey’s Responses API (responses.create) instead of Chat Completions, updating request/response translation and streaming handling to align with Responses output items and stream events.
Changes:
- Rewrites
PortkeyAdkrequest shaping to build Responsesinputitems (messages, tool calls/outputs, and optional reasoning config). - Refactors streaming to an event-driven loop based on Responses stream event types and emits ADK
LlmResponsepartials/final. - Updates/expands unit tests and adds an example demonstrating streaming + thinking/reasoning across providers.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
portkey_ai/integrations/adk.py |
Core migration to Responses API, adds reasoning mapping + new streaming/event translation. |
tests/integrations/test_adk_adapter.py |
Updates tests to mock Responses API output items/events; adds coverage for reasoning + function calls. |
examples/hello_world_portkey_adk.py |
Adjusts example response parsing to the new output/parts behavior. |
examples/adk_streaming_thinking_usage.py |
New example demonstrating streaming + thinking usage across multiple providers/models. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Thanks for taking the time to review, will address any review comments |
|
Great job on the PR @viraj-s15 🙇 I have one concern and I've addressed it in the review comment. Let me know what you think of it. I tried your changes locally, all the changes worked except streaming tool calling. Once we get over this, we should be good to merge. |
Function calls during streaming were silently lost because the adapter only expected them in the response.completed event. Track function calls from response.output_item.added and response.function_call_arguments.delta events, then merge into the final response when missing. Also adds _ensure_strict_json_schema to set additionalProperties: false on tool parameter schemas required by strict mode, and expands test coverage for parallel function calls, merge enrichment, and nested schema handling. Made-with: Cursor
Show the part's type attribute (when available) instead of the Python class name so unrecognized Gemini parts are easier to identify. Made-with: Cursor
Thanks for the review, your concern is indeed valid, have addressed it, ready for another look when you get the chance 🫡 . |
|
Thanks again for working on fixing the streaming function call issue @viraj-s15. I've tested the changes locally and everything is working as expected. This PR can be merged now 🚀 |
Rewrite ADK adapter to use Portkey Responses API
Description
Core Migration: Migrated
portkey_ai/integrations/adk.pyfrom Chat Completions to the Portkey Responses API (responses.create), replacing the entire request/response translation layer.Reasoning/Thinking Support: Added support for mapping ADK
thinking_budgetto Responsesreasoning.effort(low/medium/high) with automatic summary and encrypted content passthrough.Streaming Refactor: Rewrote streaming from accumulation-based chunk processing (~120 lines) to clean event-driven handling (~30 lines) using Responses stream events:
response.reasoning_text.delta,response.output_text.deltaandresponse.completedTesting & Documentation: Updated unit tests and added a streaming+thinking example (
examples/adk_streaming_thinking_usage.py).Motivation
This discussion: https://discord.com/channels/1143393887742861333/1462080485583749318/1462080485583749318
TL;DR: The Portkey Responses API has native reasoning support, structured streaming events, and a unified interface across acrooss multiple providers.
Known Limitations
Gemini reasoning not surfaced
Gemini reasoning might not surfaced via Portkey Responses endpoint, when using
@vertex-ai/gemini-3-flash-previewwith reasoning enabled, the model consumes reasoning tokens internally (usage.output_tokens_details.reasoning_tokens > 0) but Portkey does not return reasoning output items for Gemini. This seems to be occurring in LiteLLM too (BerriAI/litellm#10227), also found this discussion in the google forums (discuss.ai.google.dev). The adapter will surface Gemini reasoning automatically once it starts being including these items in the response.Anthropic streaming + reasoning thoughts not surfaced
When using
@anthropic/claude-sonnet-4-6(or other Claude models) with reasoning enabled in streaming mode,response.reasoning_text.deltaevents are not emitted by Portkey's Responses API. Non-streaming reasoning works correctly (boththoughtandtextitems are returned). This might be limitation in Portkey Anthropic adapter, it translates Responses API requests to Anthropic Chat Completions internally, and the thinking deltas are not being re mapped to Responses SSE events during streaming. The adapter code already handlesresponse.reasoning_text.deltaevents, so Claude streaming thoughts will surface automatically once Portkey's adapter starts emitting them.