Skip to content

Commit 2fd9adb

Browse files
htahir1strickvl
andcommitted
Add agent framework integration examples (#3898)
* Added agent framework examples * Rename * Update ZenML logo image path in README.md * Add OPENAI_API_KEY export to all agent frameworks.- Set OPENAI_API_KEY for each agent framework.- Add export command to set the API key * Add production vs. demos explanation in README.md * Update user guide examples and table with new agent data * Update docs/book/user-guide/toc.md Co-authored-by: Alex Strick van Linschoten <[email protected]> * Update examples/agent_framework_integrations/README.md Co-authored-by: Alex Strick van Linschoten <[email protected]> --------- Co-authored-by: Alex Strick van Linschoten <[email protected]> (cherry picked from commit 653cfd1)
1 parent 495251c commit 2fd9adb

File tree

36 files changed

+1492
-3
lines changed

36 files changed

+1492
-3
lines changed

docs/book/user-guide/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ Complete end-to-end implementations that showcase ZenML in real-world scenarios.
2424
Focused code snippets and templates that address specific ML workflow challenges.\
2525
[See all examples in GitHub →](https://github.com/zenml-io/zenml-projects)
2626

27-
<table data-view="cards"><thead><tr><th></th><th></th><th data-hidden data-card-cover data-type="files"></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>Quickstart</strong></td><td>Bridging Local Development and Cloud Deployment</td><td><a href=".gitbook/assets/example-01.png">example-01.png</a></td><td><a href="https://github.com/zenml-io/zenml/blob/main/examples/quickstart">https://github.com/zenml-io/zenml/blob/main/examples/quickstart</a></td></tr><tr><td><strong>End-to-End Batch Inference</strong></td><td>Supervised ML project built with the ZenML framework and its integration.</td><td><a href=".gitbook/assets/example-02.png">example-02.png</a></td><td><a href="https://github.com/zenml-io/zenml/tree/main/examples/e2e">https://github.com/zenml-io/zenml/tree/main/examples/e2e</a></td></tr><tr><td><strong>Basic NLP with BERT</strong></td><td>Build NLP models with production-ready ML pipeline framework</td><td><a href=".gitbook/assets/example-03.png">example-03.png</a></td><td><a href="https://github.com/zenml-io/zenml/tree/main/examples/e2e_nlp">https://github.com/zenml-io/zenml/tree/main/examples/e2e_nlp</a></td></tr><tr><td><strong>Computer Vision with YoloV8</strong></td><td>End-to-end computer vision pipeline with modular design</td><td><a href=".gitbook/assets/example-04.png">example-04.png</a></td><td><a href="https://github.com/zenml-io/zenml-projects/tree/main/end-to-end-computer-vision">https://github.com/zenml-io/zenml-projects/tree/main/end-to-end-computer-vision</a></td></tr><tr><td><strong>LLM Finetuning</strong></td><td>LLM fine-tuning pipeline with PEFT approach</td><td><a href=".gitbook/assets/example-05.png">example-05.png</a></td><td><a href="https://github.com/zenml-io/zenml/tree/main/examples/llm_finetuning">https://github.com/zenml-io/zenml/tree/main/examples/llm_finetuning</a></td></tr><tr><td><strong>Agent Architecture Comparison</strong></td><td>Compare AI agents with LangGraph workflows, LiteLLM integration, and automatic visualizations.</td><td><a href=".gitbook/assets/example-06.png">example-06.png</a></td><td><a href="https://github.com/zenml-io/zenml/blob/main/examples/agent_comparison">https://github.com/zenml-io/zenml/blob/main/examples/agent_comparison</a></td></tr><tr><td><strong>Minimal Agent Production</strong></td><td>Document analysis service with pipelines, evaluation, and a simple web UI.</td><td><a href=".gitbook/assets/example-07.png">example-07.png</a></td><td><a href="https://github.com/zenml-io/zenml/blob/main/examples/minimal_agent_production">https://github.com/zenml-io/zenml/blob/main/examples/minimal_agent_production</a></td></tr></tbody></table>
27+
<table data-view="cards"><thead><tr><th></th><th></th><th data-hidden data-card-cover data-type="files"></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>Quickstart</strong></td><td>Bridging Local Development and Cloud Deployment</td><td><a href=".gitbook/assets/example-01.png">example-01.png</a></td><td><a href="https://github.com/zenml-io/zenml/blob/main/examples/quickstart">https://github.com/zenml-io/zenml/blob/main/examples/quickstart</a></td></tr><tr><td><strong>End-to-End Batch Inference</strong></td><td>Supervised ML project built with the ZenML framework and its integration.</td><td><a href=".gitbook/assets/example-02.png">example-02.png</a></td><td><a href="https://github.com/zenml-io/zenml/tree/main/examples/e2e">https://github.com/zenml-io/zenml/tree/main/examples/e2e</a></td></tr><tr><td><strong>Agent Architecture Comparison</strong></td><td>Compare AI agents with LangGraph workflows, LiteLLM integration, and automatic visualizations.</td><td><a href=".gitbook/assets/example-06.png">example-06.png</a></td><td><a href="https://github.com/zenml-io/zenml/blob/main/examples/agent_comparison">https://github.com/zenml-io/zenml/blob/main/examples/agent_comparison</a></td></tr><tr><td><strong>Agent Framework Integrations</strong></td><td>Production-ready integrations for 11 popular agent frameworks including LangChain, CrewAI, AutoGen, and more.</td><td><a href=".gitbook/assets/example-06.png">example-06.png</a></td><td><a href="https://github.com/zenml-io/zenml/tree/main/examples/agent_framework_integrations">https://github.com/zenml-io/zenml/tree/main/examples/agent_framework_integrations</a></td></tr><tr><td><strong>Minimal Agent Production</strong></td><td>Document analysis service with pipelines, evaluation, and a simple web UI.</td><td><a href=".gitbook/assets/example-07.png">example-07.png</a></td><td><a href="https://github.com/zenml-io/zenml/blob/main/examples/minimal_agent_production">https://github.com/zenml-io/zenml/blob/main/examples/minimal_agent_production</a></td></tr><tr><td><strong>Basic NLP with BERT</strong></td><td>Build NLP models with production-ready ML pipeline framework</td><td><a href=".gitbook/assets/example-03.png">example-03.png</a></td><td><a href="https://github.com/zenml-io/zenml/tree/main/examples/e2e_nlp">https://github.com/zenml-io/zenml/tree/main/examples/e2e_nlp</a></td></tr><tr><td><strong>Computer Vision with YoloV8</strong></td><td>End-to-end computer vision pipeline with modular design</td><td><a href=".gitbook/assets/example-04.png">example-04.png</a></td><td><a href="https://github.com/zenml-io/zenml-projects/tree/main/end-to-end-computer-vision">https://github.com/zenml-io/zenml-projects/tree/main/end-to-end-computer-vision</a></td></tr><tr><td><strong>LLM Finetuning</strong></td><td>LLM fine-tuning pipeline with PEFT approach</td><td><a href=".gitbook/assets/example-05.png">example-05.png</a></td><td><a href="https://github.com/zenml-io/zenml/tree/main/examples/llm_finetuning">https://github.com/zenml-io/zenml/tree/main/examples/llm_finetuning</a></td></tr></tbody></table>

docs/book/user-guide/toc.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,11 @@
7676
## Examples
7777

7878
* [Quickstart](https://github.com/zenml-io/zenml/blob/main/examples/quickstart)
79+
* [Agent Quickstart](https://github.com/zenml-io/zenml/tree/main/examples/minimal_agent_production)
80+
* [Agent examples](https://github.com/zenml-io/zenml/tree/main/examples/agent_framework_integrations/)
7981
* [End-to-End Batch Inference](https://github.com/zenml-io/zenml/tree/main/examples/e2e)
80-
* [Basic NLP with BERT](https://github.com/zenml-io/zenml/tree/main/examples/e2e_nlp)
82+
* [Forecasting time-series prediction](https://github.com/zenml-io/zenml-projects/tree/main/floracasts)
83+
* [ML classification](https://github.com/zenml-io/zenml-projects/tree/main/oncoclear)
8184
* [Computer Vision with YoloV8](https://github.com/zenml-io/zenml-projects/tree/main/end-to-end-computer-vision)
82-
* [LLM Finetuning](https://github.com/zenml-io/zenml/tree/main/examples/llm_finetuning)
85+
* [Deep research agentic workflow](https://github.com/zenml-io/zenml-projects/tree/main/deep_research)
8386
* [More Projects...](https://github.com/zenml-io/zenml-projects)
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
<br />
2+
<div align="center">
3+
<a href="https://zenml.io">
4+
<img src="../../docs/book/.gitbook/assets/header.png" alt="ZenML Logo" width="600">
5+
</a>
6+
7+
<h3 align="center">Agent Frameworks Integration Examples</h3>
8+
9+
<p align="center">
10+
Production-ready agent orchestration with ZenML
11+
<br />
12+
<a href="https://zenml.io/features">Features</a>
13+
·
14+
<a href="https://zenml.io/roadmap">Roadmap</a>
15+
·
16+
<a href="https://github.com/zenml-io/zenml/issues">Report Bug</a>
17+
·
18+
<a href="https://zenml.io/discussion">Vote New Features</a>
19+
·
20+
<a href="https://blog.zenml.io/">Read Blog</a>
21+
<br />
22+
<br />
23+
<a href="https://zenml.io/slack">
24+
<img src="https://img.shields.io/badge/JOIN US ON SLACK-4A154B?style=for-the-badge&logo=slack&logoColor=white" alt="Slack">
25+
</a>
26+
<a href="https://www.linkedin.com/company/zenml/">
27+
<img src="https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge&logo=linkedin&logoColor=white" alt="LinkedIn">
28+
</a>
29+
<a href="https://twitter.com/zenml_io">
30+
<img src="https://img.shields.io/badge/Twitter-1DA1F2?style=for-the-badge&logo=twitter&logoColor=white" alt="Twitter">
31+
</a>
32+
</p>
33+
</div>
34+
35+
# 🤖 Agent Frameworks + ZenML
36+
37+
This collection demonstrates how to integrate popular agent frameworks with ZenML for production-grade AI agent orchestration. Each example follows consistent patterns and best practices, making it easy to adapt any framework for your specific use case.
38+
39+
## 🚀 Quick Start
40+
41+
Choose any framework and get started in minutes:
42+
43+
```bash
44+
export OPENAI_API_KEY="your-api-key-here"
45+
cd framework-name/
46+
uv venv --python 3.11
47+
source .venv/bin/activate
48+
uv pip install -r requirements.txt
49+
python run.py
50+
```
51+
52+
## 📊 Frameworks Overview
53+
54+
| Framework | Type | Key Features | Technologies |
55+
|-----------|------|-------------|-------------|
56+
| [Autogen](autogen/) | 🤝 Multi-Agent | Multi-agent conversations, Role-based collaboration | autogen, openai |
57+
| [AWS Strands](aws-strands/) | ⚡ Simple | Direct agent calls, Built-in tools | aws-agents, bedrock |
58+
| [CrewAI](crewai/) | 👥 Crews | Agent crews, Task delegation | crewai, openai |
59+
| [Google ADK](google-adk/) | 🧠 Gemini | Google AI agents, Gemini models | google-adk, gemini |
60+
| [Haystack](haystack/) | 🔍 RAG | Retrieval pipelines, Document processing | haystack, openai |
61+
| [LangChain](langchain/) | 🔗 Chains | Runnable chains, Tool composition | langchain, openai |
62+
| [LangGraph](langgraph/) | 🕸️ Graphs | ReAct agents, Graph workflows | langgraph, openai |
63+
| [LlamaIndex](llama_index/) | 📚 Functions | Function agents, Async execution | llama-index, openai |
64+
| [OpenAI Agents SDK](openai_agents_sdk/) | 🏗️ Structured | Official OpenAI agents, Structured execution | openai-agents, openai |
65+
| [PydanticAI](pydanticai/) | ✅ Type-Safe | Type-safe agents, Validation | pydantic-ai, openai |
66+
| [Semantic Kernel](semantic-kernel/) | 🧩 Plugins | Plugin architecture, Microsoft ecosystem | semantic-kernel, openai |
67+
68+
## 🎯 Core Patterns
69+
70+
All examples follow these established patterns:
71+
72+
### 🔧 Environment Setup
73+
- **uv for environments**: `uv venv --python 3.11`
74+
- **Fast installs**: `uv pip install -r requirements.txt`
75+
- **Consistent Python version**: 3.11 across all frameworks
76+
77+
### 📦 Pipeline Architecture
78+
```python
79+
@pipeline
80+
def agent_pipeline() -> str:
81+
# 1. External artifact input
82+
query = ExternalArtifact(value="Your query")
83+
84+
# 2. Agent execution
85+
results = run_agent(query)
86+
87+
# 3. Response formatting
88+
summary = format_response(results)
89+
90+
return summary
91+
```
92+
93+
### 🛡️ Error Handling
94+
- Comprehensive try-catch blocks
95+
- Status tracking with success/error states
96+
- Graceful degradation for agent failures
97+
98+
### 📊 Artifact Management
99+
- **Annotated outputs**: `Annotated[Type, "artifact_name"]`
100+
- **ZenML integration**: Full pipeline orchestration
101+
- **Artifact storage**: S3-backed artifact management
102+
103+
## 🏗️ Framework-Specific Features
104+
105+
### Multi-Agent Systems
106+
- **Autogen**: Conversational multi-agent workflows
107+
- **CrewAI**: Role-based agent crews with task delegation
108+
109+
### Simple Execution
110+
- **AWS Strands**: Direct callable interface with `agent(query)`
111+
- **PydanticAI**: Clean `agent.run_sync(query)` API
112+
- **Google ADK**: Gemini-powered agents with simple calls
113+
114+
### Advanced Orchestration
115+
- **LangChain**: Composable chains with tool integration
116+
- **LangGraph**: ReAct pattern with graph-based workflows
117+
- **Semantic Kernel**: Plugin-based architecture
118+
119+
### Specialized Use Cases
120+
- **Haystack**: RAG pipelines with retrieval components
121+
- **LlamaIndex**: Function agents with async capabilities
122+
- **OpenAI Agents SDK**: Structured execution with OpenAI
123+
124+
## 🔄 Implementation Notes
125+
126+
### Production vs. Demos
127+
**These examples demonstrate single-query execution for simplicity.** In production, ZenML's value comes from:
128+
- **Batch processing**: Process hundreds/thousands of queries overnight
129+
- **Agent evaluation**: Compare different frameworks on test datasets
130+
- **Data pipelines**: Use agents to process document collections
131+
- **A/B testing**: Systematic comparison of agent configurations
132+
133+
For real-time serving, use FastAPI/Flask directly. Use ZenML for the operational layer.
134+
135+
### Async Frameworks
136+
Some frameworks require async handling within ZenML steps:
137+
- **LlamaIndex**: `asyncio.run(agent.run(query))`
138+
- **Semantic Kernel**: Event loop management for chat completion
139+
140+
### Tool Integration
141+
Different frameworks have varying tool patterns:
142+
- **Decorators**: `@tool`, `@function_tool`, `@kernel_function`
143+
- **Functions**: Regular Python functions as tools
144+
- **Classes**: Tool classes with specific interfaces
145+
146+
### Response Extraction
147+
Each framework returns different response types:
148+
- **String responses**: Direct text output
149+
- **Object responses**: `.output`, `.content`, `.final_output` attributes
150+
- **Complex responses**: Nested structures requiring extraction
151+
152+
## 📋 Requirements
153+
154+
- **Python**: 3.11+
155+
- **ZenML**: Latest version
156+
- **UV**: For fast package management
157+
- **OpenAI API Key**: Most examples use OpenAI (set `OPENAI_API_KEY`)
158+
159+
## 🆘 Getting Help
160+
161+
- 💬 [Join our Slack community](https://zenml.io/slack)
162+
- 📖 [Check our documentation](https://docs.zenml.io/)
163+
- 🐛 [Report issues](https://github.com/zenml-io/zenml/issues)
164+
- 💡 [Request features](https://zenml.io/discussion)
165+
166+
## 🌟 About ZenML
167+
168+
ZenML is an extensible, open-source MLOps framework for creating production-ready ML pipelines. These agent framework integrations showcase ZenML's flexibility in orchestrating AI workflows beyond traditional ML use cases.
169+
170+
**Why ZenML for Agent Orchestration?**
171+
- 🔄 **Reproducible workflows**: Version and track agent executions
172+
- 📊 **Artifact management**: Store and version agent inputs/outputs
173+
- 🎯 **Production ready**: Built-in monitoring, logging, and error handling
174+
- 🔧 **Tool agnostic**: Works with any agent framework
175+
- ☁️ **Cloud native**: Deploy anywhere with consistent behavior
176+
177+
## 📖 Learn More
178+
179+
| Resource | Description |
180+
|----------|-------------|
181+
| 🧘 **[ZenML 101]** | New to ZenML? Start here! |
182+
|**[Core Concepts]** | Understand ZenML fundamentals |
183+
| 🤖 **[LLMOps Guide]** | Complete guide to LLMOps with ZenML |
184+
| 📓 **[Documentation]** | Full ZenML documentation |
185+
| 📒 **[API Reference]** | Detailed API documentation |
186+
|**[Examples]** | More ZenML examples |
187+
188+
[ZenML 101]: https://docs.zenml.io/user-guides/starter-guide
189+
[Core Concepts]: https://docs.zenml.io/getting-started/core-concepts
190+
[LLMOps Guide]: https://docs.zenml.io/user-guides/llmops-guide
191+
[Documentation]: https://docs.zenml.io/
192+
[SDK Reference]: https://sdkdocs.zenml.io/
193+
[Examples]: https://github.com/zenml-io/zenml/tree/main/examples
194+
195+
---
196+
197+
*This collection demonstrates the power and flexibility of ZenML for orchestrating diverse agent frameworks in production environments.*
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Autogen + ZenML
2+
3+
Multi-agent conversation framework integrated with ZenML.
4+
5+
## Run
6+
```bash
7+
export OPENAI_API_KEY="your-api-key-here"
8+
uv venv --python 3.11
9+
source .venv/bin/activate
10+
uv pip install -r requirements.txt
11+
python run.py
12+
```
13+
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
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
autogen-core>=0.4.0
2+
autogen-ext[openai]>=0.4.0
3+
zenml
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
"""ZenML Pipeline for Autogen Multi-Agent Travel Assistant.
2+
3+
This pipeline encapsulates the autogen multi-agent system in a ZenML pipeline,
4+
demonstrating how to integrate agent frameworks with ZenML for orchestration
5+
and artifact management.
6+
"""
7+
8+
import asyncio
9+
from typing import Annotated, Any, Dict
10+
11+
from autogen_agent import TravelQuery, setup_runtime
12+
from autogen_core import AgentId
13+
14+
from zenml import ExternalArtifact, pipeline, step
15+
16+
17+
@step
18+
def run_autogen_agents(
19+
query: str,
20+
) -> Annotated[Dict[str, Any], "agent_results"]:
21+
"""Execute the autogen multi-agent system and return results."""
22+
# Parse destination and days from query string
23+
# Format: "Plan a X-day trip to DESTINATION"
24+
parts = query.split(" to ")
25+
destination = parts[1] if len(parts) > 1 else "Unknown"
26+
days_part = [w for w in query.split() if w.endswith("-day")][0]
27+
days = int(days_part.replace("-day", ""))
28+
29+
# Create TravelQuery for the agents
30+
travel_query = TravelQuery(destination=destination, days=days)
31+
32+
async def _run_agents():
33+
# Setup the autogen runtime
34+
runtime = await setup_runtime()
35+
36+
# Start the runtime
37+
runtime.start()
38+
39+
try:
40+
# Send the query to the coordinator agent
41+
result = await runtime.send_message(
42+
travel_query, AgentId("coordinator", "default")
43+
)
44+
return result
45+
46+
finally:
47+
# Always stop the runtime
48+
await runtime.stop()
49+
50+
# Run the async function
51+
travel_plan = asyncio.run(_run_agents())
52+
53+
# Convert to dict for ZenML artifact storage
54+
return {
55+
"destination": travel_plan.destination,
56+
"days": travel_plan.days,
57+
"weather": {
58+
"destination": travel_plan.weather.destination,
59+
"forecast": travel_plan.weather.forecast,
60+
"temperature": travel_plan.weather.temperature,
61+
},
62+
"attractions": {
63+
"destination": travel_plan.attractions.destination,
64+
"attractions": travel_plan.attractions.attractions,
65+
},
66+
}
67+
68+
69+
@step
70+
def format_travel_plan(
71+
plan_data: Dict[str, Any],
72+
) -> Annotated[str, "formatted_plan"]:
73+
"""Format the travel plan into a readable summary."""
74+
weather = plan_data["weather"]
75+
attractions = plan_data["attractions"]
76+
77+
summary = f"""🏖️ TRAVEL PLAN FOR {plan_data["destination"].upper()}
78+
{"=" * 50}
79+
80+
📅 Duration: {plan_data["days"]} days
81+
82+
🌤️ Weather Forecast:
83+
• Condition: {weather["forecast"]}
84+
• Temperature: {weather["temperature"]}
85+
86+
🏛️ Top Attractions:
87+
"""
88+
89+
for i, attraction in enumerate(attractions["attractions"], 1):
90+
summary += f" {i}. {attraction}\n"
91+
92+
return summary.strip()
93+
94+
95+
@pipeline
96+
def autogen_travel_pipeline() -> str:
97+
"""ZenML pipeline that orchestrates the autogen multi-agent travel system.
98+
99+
Returns:
100+
Formatted travel plan summary
101+
"""
102+
# External artifact for travel query
103+
travel_query = ExternalArtifact(value="Plan a 4-day trip to Paris")
104+
105+
# Run the autogen agents
106+
plan_data = run_autogen_agents(travel_query)
107+
108+
# Format the results
109+
summary = format_travel_plan(plan_data)
110+
111+
return summary
112+
113+
114+
if __name__ == "__main__":
115+
print("🚀 Running autogen travel pipeline...")
116+
run_result = autogen_travel_pipeline()
117+
print("Pipeline completed successfully!")
118+
print("Check the ZenML dashboard for detailed results and artifacts.")
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# AWS Strands + ZenML
2+
3+
AWS Strands agent framework integrated with ZenML.
4+
5+
## Run
6+
```bash
7+
export OPENAI_API_KEY="your-api-key-here"
8+
uv venv --python 3.11
9+
source .venv/bin/activate
10+
uv pip install -r requirements.txt
11+
python run.py
12+
```
13+
14+
## Features
15+
- Simple agent execution with callable interface
16+
- Built-in tools using `@tool` decorator
17+
- Math calculation capabilities
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
strands-agents[openai]>=1.0.0
2+
strands-agents-tools>=0.0.1
3+
zenml

0 commit comments

Comments
 (0)