Skip to content

Commit ee006bf

Browse files
author
Fede Kamelhar
committed
feat: Adding portkey.ai gateway as a custom model
This PR adds first-class support for **Portkey**, a gateway platform for LLM providers, into the Strands SDK. It enables a unified, configurable, and extensible way to interact with multiple AI models (OpenAI, Anthropic via Bedrock, Gemini, and more) through a single abstraction. The integration emphasizes **tool use** and **streaming completions**, and lays foundational support for future capabilities like **multi-modal interactions** (images, audio — coming in a future PR). --- [Portkey](https://portkey.ai) is a powerful LLM gateway that provides: - **Unified API access** to multiple model providers - **Smart routing** based on performance, reliability, or cost - **Built-in observability** and analytics (latency, usage) - **Retry, fallback, and caching strategies** - **Key and model management** for dynamic overrides Portkey is becoming the go-to model abstraction layer for companies scaling LLM usage — including Notion, Descript, Ramp, and others — because it makes managing model complexity simple, modular, and scalable. --- This integration supports and has been tested with: - **OpenAI** (GPT-4, GPT-3.5) - **Anthropic**, via **Amazon Bedrock** - **Amazon Bedrock-native models** - **Google Gemini** - **Other providers** supported by Portkey configuration - **Tool Use capabilities** for: - OpenAI (native function-calling support) - Anthropic (via Bedrock with partial support) --- Adding Portkey unlocks significant benefits: | Benefit | Description | |--------|-------------| | **Model Agility** | Swap providers without changing SDK logic | | **Unified Tooling** | Consistent handling of `tool_calls` across models | | **Resilience** | Add retries, rate limits, and observability | | **Flexibility** | Customize parameters like temperature, tokens, and stream | | **Cost Optimization** | Route to cheaper models or fallback options | --- Portkey is not just a convenience — it is a **requirement** for SDK adoption in many real-world AI systems. Leading companies already standardize on Portkey. Without first-class support, **these companies cannot use the SDK**, as their LLM access, observability, and governance are fully routed through Portkey. - **Notion** – internal AI copilots with dynamic routing - **Ramp** – cost-based model fallback and observability - **Descript** – creative workflows across providers - **Puzzle**, **DeepOpinion**, and other AI-first orgs 📎 **Reference**: [Portkey Customers](https://www.portkey.ai/customers) Supporting Portkey makes the Strands SDK **immediately compatible** with the infrastructure already powering major AI systems — greatly reducing integration effort. --- This implementation extends the `Model` interface within the **Strands SDK**, Amazon’s agent platform for intelligent task automation. - ✅ Streaming responses - ✅ Tool calling (`tool_calls` / `tool_use`) - ✅ System prompt injection - ✅ Token configuration per model - ✅ Model-agnostic formatting of inputs/outputs > 🧠 **Coming Soon**: In a follow-up PR, we will add **multi-modal capabilities** (images and audio input), further expanding the power of Strands agents to handle rich sensory data. --- This PR introduces a new model provider class: - `PortkeyModel`, implementing the full `Model` interface - Handles provider-specific tool use behavior (OpenAI vs Bedrock) - Formats and streams messages with structured deltas - Manages tool call life cycle: initiation, input, completion - Defensive checks for context window and malformed payloads - Full support for `ToolSpec` mapping and schema encoding All logic is structured to allow future expansion to other Portkey-supported capabilities (e.g., caching, retry policies, routing rules). --- This feature was validated across the following dimensions: - ✔️ Basic chat completions - ✔️ Streaming token responses - ✔️ Tool calling with input parameters - ✔️ Tool result handoff - ✔️ Multiple model backends: - OpenAI GPT-4 (tools) - Anthropic Claude (via Bedrock) - Gemini (streaming + simple use) - Bedrock-native (Jurassic, Titan) --- - [ ] Add multi-modal support (images, audio) - [ ] Integrate Portkey usage metrics into internal observability stack - [ ] Add routing and fallback policies via Portkey configuration - [ ] Enable A/B experimentation between providers at runtime --- - [Portkey.ai Documentation](https://docs.portkey.ai/) - [Portkey Customer Base](https://www.portkey.ai/customers) - [Amazon Bedrock Overview](https://docs.aws.amazon.com/bedrock/) - [OpenAI Function Calling](https://platform.openai.com/docs/guides/function-calling) - [Strands SDK](https://github.com/aws/strands-sdk) --- feat: Adding portkey.ai gateway as a custom model feat: Adding portkey.ai gateway as a custom model feat: Adding portkey.ai gateway as a custom model feat: Adding portkey.ai gateway as a custom model
1 parent aff928c commit ee006bf

5 files changed

Lines changed: 630 additions & 1 deletion

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ from strands import Agent
118118
from strands.models import BedrockModel
119119
from strands.models.ollama import OllamaModel
120120
from strands.models.llamaapi import LlamaAPIModel
121+
from strands.models.portkey import PortkeyModel
121122

122123
# Bedrock
123124
bedrock_model = BedrockModel(
@@ -142,6 +143,17 @@ llama_model = LlamaAPIModel(
142143
)
143144
agent = Agent(model=llama_model)
144145
response = agent("Tell me about Agentic AI")
146+
147+
# Portkey for all models
148+
portkey_model = PortkeyModel(
149+
api_key="<PORTKEY_API_KEY>",
150+
model_id="anthropic.claude-3-5-sonnet-20241022-v2:0",
151+
virtual_key="<BEDROCK_VIRTUAL_KEY>",
152+
provider="bedrock",
153+
base_url="http://portkey-service-gateway.service.prod.example.com/v1",
154+
)
155+
agent = Agent(model=portkey_model)
156+
response = agent("Tell me about Agentic AI")
145157
```
146158

147159
Built-in providers:

pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ packages = ["src/strands"]
5050
anthropic = [
5151
"anthropic>=0.21.0,<1.0.0",
5252
]
53+
# Optional dependencies for different AI providers
54+
portkey = [
55+
"portkey-ai>=1.0.0,<2.0.0",
56+
]
57+
5358
dev = [
5459
"commitizen>=4.4.0,<5.0.0",
5560
"hatch>=1.0.0,<2.0.0",
@@ -107,7 +112,7 @@ lint-fix = [
107112
]
108113

109114
[tool.hatch.envs.hatch-test]
110-
features = ["anthropic", "litellm", "llamaapi", "ollama", "openai"]
115+
features = ["anthropic", "litellm", "llamaapi", "ollama", "openai", "portkey"]
111116
extra-dependencies = [
112117
"moto>=5.1.0,<6.0.0",
113118
"pytest>=8.0.0,<9.0.0",

src/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)