Skip to content

Commit 023205f

Browse files
temporal openai integration
1 parent 1724792 commit 023205f

File tree

21 files changed

+1509
-18
lines changed

21 files changed

+1509
-18
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
*.so
6+
.Python
7+
build/
8+
develop-eggs/
9+
dist/
10+
downloads/
11+
eggs/
12+
.eggs/
13+
lib/
14+
lib64/
15+
parts/
16+
sdist/
17+
var/
18+
wheels/
19+
*.egg-info/
20+
.installed.cfg
21+
*.egg
22+
MANIFEST
23+
24+
# Virtual environments
25+
.env
26+
.venv
27+
env/
28+
venv/
29+
ENV/
30+
env.bak/
31+
venv.bak/
32+
33+
# IDEs
34+
.vscode/
35+
.idea/
36+
*.swp
37+
*.swo
38+
*~
39+
40+
# OS
41+
.DS_Store
42+
.DS_Store?
43+
._*
44+
.Spotlight-V100
45+
.Trashes
46+
ehthumbs.db
47+
Thumbs.db
48+
49+
# Logs
50+
*.log
51+
logs/
52+
53+
# Development files
54+
.pytest_cache/
55+
.coverage
56+
.tox/
57+
.cache
58+
nosetests.xml
59+
coverage.xml
60+
61+
# Git
62+
.git/
63+
.gitignore
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Use the official Agentex base image
2+
FROM agentex-base:latest
3+
4+
# Set working directory
5+
WORKDIR /app
6+
7+
# Copy requirements and install dependencies
8+
COPY 040_openai_temporal_integration/pyproject.toml ./
9+
RUN pip install -e .
10+
11+
# Copy the agent code
12+
COPY 040_openai_temporal_integration/ ./
13+
14+
# Set environment variables
15+
ENV PYTHONPATH=/app
16+
ENV WORKFLOW_NAME=at040-openai-temporal-integration
17+
ENV WORKFLOW_TASK_QUEUE=040_openai_temporal_integration_queue
18+
ENV AGENT_NAME=at040-openai-temporal-integration
19+
20+
# Expose the default ACP port
21+
EXPOSE 8000
22+
23+
# Default command to run the worker
24+
CMD ["python", "project/run_worker.py"]
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Simplified OpenAI Agent Chat - Agent Platform Integration
2+
3+
This tutorial demonstrates the new **Agent Platform Integration** for Agentex that dramatically simplifies agent development while preserving all Agentex infrastructure benefits.
4+
5+
## Before vs After Comparison
6+
7+
| Aspect | Complex Manual (10_agentic/10_temporal/010_agent_chat) | Simplified Platform (this tutorial) |
8+
|--------|-------------------------------------------------------|--------------------------------------|
9+
| **Lines of code** | 277 lines | ~30 lines |
10+
| **Manual orchestration** | Required | Automatic |
11+
| **Activity definitions** | Manual `@activity.defn` for each operation | Built-in durability |
12+
| **State management** | Manual conversation state tracking | Automatic |
13+
| **Error handling** | Manual try/catch and retry logic | Built-in recovery |
14+
| **ACP integration** | Manual message creation/sending | Automatic via bridge |
15+
16+
## Key Benefits
17+
18+
### 🚀 **Dramatically Reduced Complexity**
19+
- **90% reduction in code** - from 277 lines to ~30 lines
20+
- **No manual orchestration** - agent execution is automatically durable
21+
- **No activity definitions** - tool calls are automatically temporal activities
22+
23+
### 🔧 **Preserved Agentex Infrastructure**
24+
- **ACP protocol compatibility** - external clients unchanged
25+
- **Kubernetes deployment** - same Helm charts and configs
26+
- **Multi-tenant hosting** - same agent discovery and routing
27+
- **Authentication & monitoring** - same observability stack
28+
29+
### 🎯 **Platform Agnostic Design**
30+
- **OpenAI Agents SDK** - this tutorial (implemented)
31+
- **LangChain** - future extension point
32+
- **CrewAI** - future extension point
33+
- **Custom frameworks** - extensible via strategy pattern
34+
35+
## Implementation Details
36+
37+
### Workflow Definition
38+
```python
39+
@workflow.defn(name=environment_variables.WORKFLOW_NAME)
40+
class SimplifiedOpenAIChatAgent(OpenAIAgentWorkflow):
41+
async def create_agent(self) -> Agent:
42+
return Agent(
43+
name="Tool-Enabled Assistant",
44+
model="gpt-4o-mini",
45+
instructions="You are a helpful assistant...",
46+
tools=[], # Add tools as needed
47+
)
48+
```
49+
50+
### Worker Setup
51+
```python
52+
worker = AgentexWorker(
53+
task_queue=environment_variables.WORKFLOW_TASK_QUEUE,
54+
agent_platform="openai", # Automatic optimization
55+
)
56+
await worker.run(activities=[], workflow=SimplifiedOpenAIChatAgent)
57+
```
58+
59+
## Architecture Benefits
60+
61+
### Automatic Durability
62+
- **Agent executions** become Temporal activities automatically
63+
- **Tool calls** are durable with automatic retries
64+
- **Conversation state** persists across workflow restarts
65+
66+
### Performance Optimizations
67+
- **Activity exclusion** - OpenAI provider activities automatically excluded
68+
- **Direct SDK integration** - bypasses activity overhead for simple cases
69+
- **Platform-specific configuration** - optimized worker settings per platform
70+
71+
### Future Extensibility
72+
- **Strategy pattern** - easy to add new agent platforms
73+
- **Unified interface** - same workflow pattern across all platforms
74+
- **Agentex compatibility** - seamless integration with existing infrastructure
75+
76+
## Running the Tutorial
77+
78+
1. **Set environment variables:**
79+
```bash
80+
export WORKFLOW_NAME="simplified-openai-chat"
81+
export WORKFLOW_TASK_QUEUE="simplified_openai_chat_queue"
82+
export AGENT_NAME="simplified-openai-chat"
83+
export OPENAI_API_KEY="your-openai-api-key"
84+
```
85+
86+
2. **Start the worker:**
87+
```bash
88+
python project/run_worker.py
89+
```
90+
91+
3. **Test via ACP API:**
92+
```bash
93+
curl -X POST http://localhost:8000/api \
94+
-H "Content-Type: application/json" \
95+
-d '{
96+
"method": "task/create",
97+
"params": {
98+
"agent_name": "simplified-openai-chat"
99+
}
100+
}'
101+
```
102+
103+
## Migration Guide
104+
105+
To migrate from the complex manual approach to this simplified approach:
106+
107+
1. **Replace workflow inheritance:**
108+
- From: `BaseWorkflow`
109+
- To: `OpenAIAgentWorkflow` (or other platform workflow)
110+
111+
2. **Replace manual orchestration:**
112+
- From: Manual `adk.providers.openai.run_agent_streamed_auto_send()`
113+
- To: Simple `create_agent()` implementation
114+
115+
3. **Update worker configuration:**
116+
- Add: `agent_platform="openai"` parameter
117+
- Remove: Manual activity registration
118+
119+
4. **Remove manual activities:**
120+
- Delete: Custom `@activity.defn` wrappers
121+
- Keep: Core business logic in simple functions
122+
123+
This approach maintains 100% compatibility with existing Agentex infrastructure while dramatically simplifying development.
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Agent Manifest Configuration
2+
# ---------------------------
3+
# This file defines how your agent should be built and deployed.
4+
5+
# Build Configuration
6+
# ------------------
7+
# The build config defines what gets packaged into your agent's Docker image.
8+
build:
9+
context:
10+
# Root directory for the build context
11+
root: ../ # Keep this as the default root
12+
13+
# Paths to include in the Docker build context
14+
# Must include your agent's directory (your custom agent code)
15+
include_paths:
16+
- 040_openai_temporal_integration
17+
18+
# Path to your agent's Dockerfile
19+
# This defines how your agent's image is built from the context
20+
# Relative to the root directory
21+
dockerfile: 040_openai_temporal_integration/Dockerfile
22+
23+
# Path to your agent's .dockerignore
24+
# Filters unnecessary files from the build context
25+
dockerignore: 040_openai_temporal_integration/.dockerignore
26+
27+
28+
# Local Development Configuration
29+
# -----------------------------
30+
# Only used when running the agent locally
31+
local_development:
32+
agent:
33+
port: 8000 # Port where your local ACP server is running
34+
host_address: host.docker.internal # Host address for Docker networking
35+
36+
# File paths for local development (relative to this manifest.yaml)
37+
paths:
38+
# Path to ACP server file
39+
acp: project/acp.py
40+
41+
# Path to temporal worker file
42+
worker: project/run_worker.py
43+
44+
45+
# Agent Configuration
46+
# -----------------
47+
agent:
48+
# Type of agent - either sync or agentic
49+
acp_type: agentic
50+
51+
# Unique name for your agent
52+
# Used for task routing and monitoring
53+
name: at040-openai-temporal-integration
54+
55+
# Description of what your agent does
56+
# Helps with documentation and discovery
57+
description: "Simplified OpenAI agent chat using agent platform integration"
58+
59+
# Temporal workflow configuration
60+
# This enables your agent to run as a Temporal workflow for long-running tasks
61+
temporal:
62+
enabled: true
63+
workflows:
64+
# Name of the workflow class
65+
# Must match the @workflow.defn name in your workflow.py
66+
- name: at040-openai-temporal-integration
67+
68+
# Queue name for task distribution
69+
# Used by Temporal to route tasks to your agent
70+
# Convention: <agent_name>_task_queue
71+
queue_name: 040_openai_temporal_integration_queue
72+
73+
# Optional: Credentials mapping
74+
# Maps Kubernetes secrets to environment variables
75+
# Common credentials include:
76+
credentials:
77+
- env_var_name: OPENAI_API_KEY
78+
secret_name: openai-api-key
79+
secret_key: api-key
80+
81+
# Optional: Set Environment variables for running your agent locally as well
82+
# as for deployment later on
83+
# env:
84+
# - name: OPENAI_BASE_URL
85+
# value: "https://api.openai.com/v1"
86+
# - name: ACCOUNT_ID
87+
# value: "your_account_id_here"
88+
89+
90+
# Deployment Configuration
91+
# -----------------------
92+
# Configuration for deploying your agent to Kubernetes clusters
93+
deployment:
94+
# Container image configuration
95+
image:
96+
repository: "" # Update with your container registry
97+
tag: "latest" # Default tag, should be versioned in production
98+
99+
imagePullSecrets:
100+
- name: my-registry-secret # Update with your image pull secret name
101+
102+
# Global deployment settings that apply to all clusters
103+
# These can be overridden using --override-file with custom configuration files
104+
global:
105+
agent:
106+
name: "at040-openai-temporal-integration"
107+
description: "Simplified OpenAI agent chat using agent platform integration"
108+
109+
# Default replica count
110+
replicaCount: 1
111+
112+
# Default resource requirements
113+
resources:
114+
requests:
115+
cpu: "500m"
116+
memory: "1Gi"
117+
limits:
118+
cpu: "1000m"
119+
memory: "2Gi"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Simplified OpenAI Agent Platform Tutorial
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import os
2+
3+
from agentex.lib.sdk.fastacp.fastacp import FastACP
4+
from agentex.lib.types.fastacp import TemporalACPConfig
5+
6+
7+
# Create the ACP server
8+
acp = FastACP.create(
9+
acp_type="agentic",
10+
config=TemporalACPConfig(
11+
# When deployed to the cluster, the Temporal address will automatically be set to the cluster address
12+
# For local development, we set the address manually to talk to the local Temporal service set up via docker compose
13+
type="temporal",
14+
temporal_address=os.getenv("TEMPORAL_ADDRESS", "localhost:7233")
15+
)
16+
)
17+
18+
19+
# Notice that we don't need to register any handlers when we use type="temporal"
20+
# If you look at the code in agentex.sdk.fastacp.impl.temporal_acp
21+
# you can see that the handlers are automatically registered to forward all ACP events
22+
# to the temporal workflow via the temporal client.
23+
24+
# The temporal workflow is responsible for handling the ACP events and sending responses
25+
# This is handled by the workflow method that is decorated with @workflow.signal(name=SignalName.RECEIVE_EVENT)

0 commit comments

Comments
 (0)