Skip to content

improvement: rewrite ADK adapter to use Portkey Responses API#421

Open
viraj-s15 wants to merge 5 commits intoPortkey-AI:mainfrom
viraj-s15:feature/adk-responses-endpoint
Open

improvement: rewrite ADK adapter to use Portkey Responses API#421
viraj-s15 wants to merge 5 commits intoPortkey-AI:mainfrom
viraj-s15:feature/adk-responses-endpoint

Conversation

@viraj-s15
Copy link
Copy Markdown

@viraj-s15 viraj-s15 commented Mar 7, 2026

Rewrite ADK adapter to use Portkey Responses API

Description

  • Core Migration: Migrated portkey_ai/integrations/adk.py from 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_budget to Responses reasoning.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.delta and response.completed

  • Testing & 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-preview with 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.delta events are not emitted by Portkey's Responses API. Non-streaming reasoning works correctly (both thought and text items 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 handles response.reasoning_text.delta events, so Claude streaming thoughts will surface automatically once Portkey's adapter starts emitting them.

@viraj-s15 viraj-s15 changed the title integration: rewrite ADK adapter to use Portkey Responses API improvement: rewrite ADK adapter to use Portkey Responses API Mar 7, 2026
@narengogi
Copy link
Copy Markdown
Member

thankyou @viraj-s15 we'll get this tested and reviewed

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 PortkeyAdk request shaping to build Responses input items (messages, tool calls/outputs, and optional reasoning config).
  • Refactors streaming to an event-driven loop based on Responses stream event types and emits ADK LlmResponse partials/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.

@viraj-s15
Copy link
Copy Markdown
Author

thankyou @viraj-s15 we'll get this tested and reviewed

Thanks for taking the time to review, will address any review comments

narengogi
narengogi previously approved these changes Mar 24, 2026
@kiran-4444
Copy link
Copy Markdown

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
@viraj-s15
Copy link
Copy Markdown
Author

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.

Thanks for the review, your concern is indeed valid, have addressed it, ready for another look when you get the chance 🫡 .

@kiran-4444
Copy link
Copy Markdown

kiran-4444 commented Apr 10, 2026

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 🚀

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.

4 participants