Skip to content

Commit cf26d18

Browse files
authored
Update the OpenAI Agents SDK example (#4105)
1 parent ba6cdf7 commit cf26d18

File tree

4 files changed

+724
-7
lines changed

4 files changed

+724
-7
lines changed

examples/agent_framework_integrations/openai_agents_sdk/README.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,37 @@ Deploy this agent as a real-time HTTP service:
2929
```bash
3030
# Deploy the pipeline as an HTTP service
3131
zenml pipeline deploy run.agent_pipeline --name openai-agents-agent
32+
```
33+
34+
Once deployed, you can interact with the service in multiple ways:
3235

33-
# Invoke via CLI
36+
### 🎨 Custom Web UI
37+
Navigate to the root endpoint in your browser to access an interactive web interface:
38+
```
39+
http://localhost:8000/
40+
```
41+
42+
The UI provides:
43+
- Free-form query input with example suggestions
44+
- Real-time agent responses with markdown rendering
45+
- Visual feedback and error handling
46+
47+
### 📚 API Documentation
48+
FastAPI automatically generates interactive API documentation:
49+
```
50+
http://localhost:8000/docs # Swagger UI
51+
http://localhost:8000/redoc # ReDoc alternative
52+
```
53+
54+
### 🔧 Programmatic Access
55+
56+
**Via ZenML CLI:**
57+
```bash
3458
zenml deployment invoke openai-agents-agent --query="Tell me a fun fact about Tokyo"
59+
```
3560

36-
# Invoke via HTTP API
61+
**Via HTTP API:**
62+
```bash
3763
curl -X POST http://localhost:8000/invoke \
3864
-H "Content-Type: application/json" \
3965
-d '{"parameters": {"query": "What are some interesting facts about space exploration?"}}'
@@ -45,4 +71,4 @@ curl -X POST http://localhost:8000/invoke \
4571
- **Function Tools**: Built-in tools with `@function_tool` decorator
4672
- **Tracing & Monitoring**: Comprehensive execution tracking
4773
- **Real-time Deployment**: Deploy as HTTP API for instant responses
48-
- **ZenML Orchestration**: Full pipeline tracking and artifact management
74+
- **ZenML Orchestration**: Full pipeline tracking and artifact management

examples/agent_framework_integrations/openai_agents_sdk/openai_agent.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def get_city_info(city: str) -> str:
3333
"paris": "Paris is the capital of France, famous for the Eiffel Tower, art museums, and cuisine.",
3434
"new york": "New York City is the most populous city in the United States, known for its skyline, culture, and diversity.",
3535
"london": "London is the capital of England and the United Kingdom, famous for its history, architecture, and royal heritage.",
36+
"munich": "Munich is the capital of Bavaria, Germany's third-largest city, famous for Oktoberfest, beer gardens, BMW headquarters, and its proximity to the Alps.",
3637
}
3738

3839
city_lower = city.lower()
@@ -48,6 +49,6 @@ def get_city_info(city: str) -> str:
4849
instructions="""You are a helpful travel assistant. You can provide weather information
4950
and general facts about cities around the world. When users ask about cities, use your
5051
available tools to get specific information. Be friendly and informative in your responses.""",
51-
model="gpt-4o-mini",
52+
model="gpt-5-nano",
5253
tools=[get_weather, get_city_info],
5354
)

examples/agent_framework_integrations/openai_agents_sdk/run.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,30 @@
88
from typing import Annotated, Any, Dict
99

1010
from zenml import pipeline, step
11-
from zenml.config import DockerSettings, PythonPackageInstaller
11+
from zenml.config import (
12+
DeploymentSettings,
13+
DockerSettings,
14+
SecureHeadersConfig,
15+
)
16+
17+
deploy_settings = DeploymentSettings(
18+
app_title="Travel Assistant",
19+
app_description=(
20+
"A travel assistant that can provide weather information and general facts about cities around the world."
21+
),
22+
app_version="0.1",
23+
dashboard_files_path="ui",
24+
secure_headers=SecureHeadersConfig(
25+
csp=(
26+
"default-src 'none'; "
27+
"script-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net; "
28+
"connect-src 'self' https://cdn.jsdelivr.net; "
29+
"style-src 'self' 'unsafe-inline'"
30+
),
31+
),
32+
)
1233

1334
docker_settings = DockerSettings(
14-
python_package_installer=PythonPackageInstaller.UV,
1535
requirements="requirements.txt", # relative to the pipeline directory
1636
environment={
1737
"OPENAI_API_KEY": os.getenv("OPENAI_API_KEY"),
@@ -162,7 +182,13 @@ def format_openai_response(
162182
return formatted.strip()
163183

164184

165-
@pipeline(settings={"docker": docker_settings}, enable_cache=False)
185+
@pipeline(
186+
settings={
187+
"docker": docker_settings,
188+
"deployment": deploy_settings,
189+
},
190+
enable_cache=False,
191+
)
166192
def agent_pipeline(query: str = "Tell me a fun fact about Tokyo") -> str:
167193
"""ZenML pipeline that orchestrates the OpenAI Agents SDK.
168194

0 commit comments

Comments
 (0)