Skip to content

Commit 34518cc

Browse files
htahir1claudestrickvl
authored
Update agent framework integrations (#4090)
* Update agent framework integrations * Update agent framework integrations * Update agent framework integrations * Update README and optimize agent execution script * Refactor script to improve readability and maintainability * Update agent framework README files with pipeline deployment support - Add zenml init/login setup steps in separate blocks - Update deployment commands to use run.agent_pipeline format - Replace -service naming with -agent naming convention - Add comprehensive deployment documentation sections - Include both CLI and HTTP API invocation examples - Maintain consistent structure across all framework examples 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * Refactor exception handling for file deletion --------- Co-authored-by: Claude <[email protected]> Co-authored-by: Alex Strick van Linschoten <[email protected]>
1 parent 900a588 commit 34518cc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+938
-288
lines changed

examples/agent_framework_integrations/README.md

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,34 @@ Choose any framework and get started in minutes:
4444
export OPENAI_API_KEY="your-api-key-here"
4545
cd framework-name/
4646
uv venv --python 3.11
47-
source .venv/bin/activate
47+
source .venv/bin/activate
4848
uv pip install -r requirements.txt
4949
python run.py
5050
```
5151

52+
### 🌐 Pipeline Deployments
53+
54+
All examples support **real-time deployment as HTTP services** using ZenML's [Pipeline Deployment feature](https://docs.zenml.io/concepts/deployment):
55+
56+
```bash
57+
# Deploy any agent pipeline as a persistent HTTP service
58+
zenml pipeline deploy agent_pipeline --name my-agent-service
59+
60+
# Invoke via CLI
61+
zenml deployment invoke my-agent-service --query="Your question here"
62+
63+
# Invoke via HTTP API
64+
curl -X POST http://localhost:8000/invoke \
65+
-H "Content-Type: application/json" \
66+
-d '{"parameters": {"query": "Your question here"}}'
67+
```
68+
69+
This transforms batch-style agent workflows into **real-time APIs** perfect for:
70+
- **Web applications**: Integrate agents directly into your apps
71+
- **Microservices**: Deploy agents as independent services
72+
- **Production inference**: Serve models with preprocessing pipelines
73+
- **Interactive demos**: Create shareable agent endpoints
74+
5275
## 📊 Frameworks Overview
5376

5477
| Framework | Type | Key Features | Technologies |
@@ -78,16 +101,13 @@ All examples follow these established patterns:
78101
### 📦 Pipeline Architecture
79102
```python
80103
@pipeline
81-
def agent_pipeline() -> str:
82-
# 1. External artifact input
83-
query = ExternalArtifact(value="Your query")
84-
85-
# 2. Agent execution
104+
def agent_pipeline(query: str = "Your default query") -> str:
105+
# 1. Agent execution with parameterized input
86106
results = run_agent(query)
87-
88-
# 3. Response formatting
107+
108+
# 2. Response formatting
89109
summary = format_response(results)
90-
110+
91111
return summary
92112
```
93113

@@ -124,14 +144,14 @@ def agent_pipeline() -> str:
124144

125145
## 🔄 Implementation Notes
126146

127-
### Production vs. Demos
128-
**These examples demonstrate single-query execution for simplicity.** In production, ZenML's value comes from:
147+
### Production Use Cases
148+
**These examples support both batch and real-time execution.** ZenML's value in production includes:
129149
- **Batch processing**: Process hundreds/thousands of queries overnight
130-
- **Agent evaluation**: Compare different frameworks on test datasets
150+
- **Real-time serving**: Deploy agents as HTTP APIs for instant responses
151+
- **Agent evaluation**: Compare different frameworks on test datasets
131152
- **Data pipelines**: Use agents to process document collections
132153
- **A/B testing**: Systematic comparison of agent configurations
133-
134-
For real-time serving, use FastAPI/Flask directly. Use ZenML for the operational layer.
154+
- **Microservices**: Independent, scalable agent deployments
135155

136156
### Async Frameworks
137157
Some frameworks require async handling within ZenML steps:
@@ -174,6 +194,8 @@ ZenML is an extensible, open-source MLOps framework for creating production-read
174194
- 🎯 **Production ready**: Built-in monitoring, logging, and error handling
175195
- 🔧 **Tool agnostic**: Works with any agent framework
176196
- ☁️ **Cloud native**: Deploy anywhere with consistent behavior
197+
- 🌐 **Real-time APIs**: Deploy agents as HTTP services instantly
198+
- 🚀 **Pipeline deployments**: Transform batch workflows into live services
177199

178200
## 📖 Learn More
179201

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright (c) ZenML GmbH 2025. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at:
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12+
# or implied. See the License for the specific language governing
13+
# permissions and limitations under the License.
14+
"""Agent framework integrations examples."""
15+
Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,48 @@
11
# Autogen + ZenML
22

3-
Multi-agent conversation framework integrated with ZenML.
3+
Multi-agent conversation framework integrated with ZenML for travel planning with collaborative agents.
4+
5+
## 🚀 Quick Run
46

5-
## Run
67
```bash
78
export OPENAI_API_KEY="your-api-key-here"
89
uv venv --python 3.11
910
source .venv/bin/activate
1011
uv pip install -r requirements.txt
12+
```
13+
14+
Initialize ZenML and login:
15+
```bash
16+
zenml init
17+
zenml login
18+
```
19+
20+
Run the pipeline:
21+
```bash
1122
python run.py
1223
```
1324

14-
## Features
15-
- Multi-agent conversations with UserProxy and Assistant agents
16-
- Async runtime management with proper cleanup
17-
- Travel planning use case with collaborative agents
25+
## 🌐 Pipeline Deployment
26+
27+
Deploy this agent as a real-time HTTP service:
28+
29+
```bash
30+
# Deploy the pipeline as an HTTP service
31+
zenml pipeline deploy run.agent_pipeline --name autogen-agent
32+
33+
# Invoke via CLI
34+
zenml deployment invoke autogen-agent --destination="Tokyo" --days=3
35+
36+
# Invoke via HTTP API
37+
curl -X POST http://localhost:8000/invoke \
38+
-H "Content-Type: application/json" \
39+
-d '{"parameters": {"destination": "Tokyo", "days": 3}}'
40+
```
41+
42+
## ✨ Features
43+
44+
- **Multi-Agent Collaboration**: Weather specialist and travel advisor agents
45+
- **Async Runtime Management**: Proper agent lifecycle with cleanup
46+
- **Travel Planning**: Comprehensive itinerary generation with weather integration
47+
- **Real-time Deployment**: Deploy as HTTP API for instant responses
48+
- **ZenML Orchestration**: Full pipeline tracking and artifact management
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright (c) ZenML GmbH 2025. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at:
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12+
# or implied. See the License for the specific language governing
13+
# permissions and limitations under the License.
14+
"""AutoGen agent example."""
15+
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
autogen-core>=0.4.0
1+
autogen-core>=0.7.5
22
autogen-ext[openai]>=0.4.0
33
zenml[local]
4+
jinja2>=3.1.0
5+
secure>=0.3.0

examples/agent_framework_integrations/autogen/run.py

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
)
2020
from pydantic import BaseModel
2121

22-
from zenml import ExternalArtifact, pipeline, step
22+
from zenml import pipeline, step
2323
from zenml.config import DockerSettings, PythonPackageInstaller
2424

2525
docker_settings = DockerSettings(
@@ -32,29 +32,29 @@
3232

3333

3434
class TravelQuery(BaseModel):
35-
"""User wants to plan a trip"""
35+
"""User wants to plan a trip."""
3636

3737
destination: str
3838
days: int
3939

4040

4141
class WeatherInfo(BaseModel):
42-
"""Weather information for a destination"""
42+
"""Weather information for a destination."""
4343

4444
destination: str
4545
forecast: str
4646
temperature: str
4747

4848

4949
class AttractionInfo(BaseModel):
50-
"""Tourist attractions for a destination"""
50+
"""Tourist attractions for a destination."""
5151

5252
destination: str
5353
attractions: List[str]
5454

5555

5656
class TravelPlan(BaseModel):
57-
"""Complete travel plan combining all information"""
57+
"""Complete travel plan combining all information."""
5858

5959
destination: str
6060
days: int
@@ -67,16 +67,17 @@ class TravelPlan(BaseModel):
6767

6868

6969
class WeatherAgent(RoutedAgent):
70-
"""Expert in weather information"""
70+
"""Expert in weather information."""
7171

7272
def __init__(self):
73+
"""Initialize the Weather Specialist agent."""
7374
super().__init__("Weather Specialist")
7475

7576
@message_handler
7677
async def check_weather(
7778
self, message: TravelQuery, ctx: MessageContext
7879
) -> WeatherInfo:
79-
"""Get weather for the destination"""
80+
"""Get weather for the destination."""
8081
# Simulate weather API call
8182
weather_data = {
8283
"Paris": ("Partly cloudy with chance of rain", "15°C"),
@@ -101,16 +102,17 @@ async def check_weather(
101102

102103

103104
class AttractionAgent(RoutedAgent):
104-
"""Expert in tourist attractions"""
105+
"""Expert in tourist attractions."""
105106

106107
def __init__(self):
108+
"""Initialize the Tourism Specialist agent."""
107109
super().__init__("Tourism Specialist")
108110

109111
@message_handler
110112
async def find_attractions(
111113
self, message: TravelQuery, ctx: MessageContext
112114
) -> AttractionInfo:
113-
"""Find top attractions for the destination"""
115+
"""Find top attractions for the destination."""
114116
# Simulate attraction database
115117
attractions_db = {
116118
"Paris": [
@@ -153,16 +155,17 @@ class TravelCoordinator(RoutedAgent):
153155
"""Coordinates between specialists to create a travel plan and returns it."""
154156

155157
def __init__(self):
158+
"""Initialize the Travel Coordinator agent."""
156159
super().__init__("Travel Coordinator")
157160

158161
@message_handler
159162
async def coordinate_travel_plan(
160163
self, message: TravelQuery, _
161164
) -> TravelPlan:
162-
"""
163-
Receives a query, fans out to specialist agents, gathers results,
164-
and returns a complete travel plan. This is the main entrypoint
165-
for an external request.
165+
"""Receive a query, fan out to specialist agents, and gather results.
166+
167+
This is the main entrypoint for an external request that creates
168+
a complete travel plan.
166169
"""
167170
print(f"📋 Coordinator: Planning trip to {message.destination}")
168171

@@ -213,16 +216,10 @@ async def setup_runtime() -> AgentRuntime:
213216

214217
@step
215218
def run_autogen_agents(
216-
query: str,
219+
destination: str,
220+
days: int,
217221
) -> Annotated[Dict[str, Any], "agent_results"]:
218222
"""Execute the autogen multi-agent system and return results."""
219-
# Parse destination and days from query string
220-
# Format: "Plan a X-day trip to DESTINATION"
221-
parts = query.split(" to ")
222-
destination = parts[1] if len(parts) > 1 else "Unknown"
223-
days_part = [w for w in query.split() if w.endswith("-day")][0]
224-
days = int(days_part.replace("-day", ""))
225-
226223
# Create TravelQuery for the agents
227224
travel_query = TravelQuery(destination=destination, days=days)
228225

@@ -290,17 +287,14 @@ def format_travel_plan(
290287

291288

292289
@pipeline(settings={"docker": docker_settings}, enable_cache=False)
293-
def autogen_travel_pipeline() -> str:
290+
def agent_pipeline(destination: str = "Paris", days: int = 4) -> str:
294291
"""ZenML pipeline that orchestrates the autogen multi-agent travel system.
295292
296293
Returns:
297294
Formatted travel plan summary
298295
"""
299-
# External artifact for travel query
300-
travel_query = ExternalArtifact(value="Plan a 4-day trip to Paris")
301-
302296
# Run the autogen agents
303-
plan_data = run_autogen_agents(travel_query)
297+
plan_data = run_autogen_agents(destination=destination, days=days)
304298

305299
# Format the results
306300
summary = format_travel_plan(plan_data)
@@ -310,6 +304,6 @@ def autogen_travel_pipeline() -> str:
310304

311305
if __name__ == "__main__":
312306
print("🚀 Running autogen travel pipeline...")
313-
run_result = autogen_travel_pipeline()
307+
run_result = agent_pipeline()
314308
print("Pipeline completed successfully!")
315309
print("Check the ZenML dashboard for detailed results and artifacts.")

examples/agent_framework_integrations/aws-strands/README.md

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)