Skip to content

Commit d3f1fb6

Browse files
declan-scaleclaude
andcommitted
feat(cli): add default-openai-agents init template (async base)
Add the missing async-base OpenAI Agents SDK template, wiring DEFAULT_OPENAI_AGENTS into the init flow (enum, project files, async prompt). The scaffolded acp.py imports OpenAITurn from the agentex.lib.adk facade, matching the other Turn-based templates. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 86ce557 commit d3f1fb6

12 files changed

Lines changed: 731 additions & 0 deletions

File tree

src/agentex/lib/cli/commands/init.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class TemplateType(str, Enum):
2929
DEFAULT = "default"
3030
DEFAULT_LANGGRAPH = "default-langgraph"
3131
DEFAULT_PYDANTIC_AI = "default-pydantic-ai"
32+
DEFAULT_OPENAI_AGENTS = "default-openai-agents"
3233
SYNC = "sync"
3334
SYNC_OPENAI_AGENTS = "sync-openai-agents"
3435
SYNC_OPENAI_AGENTS_LOCAL_SANDBOX = "sync-openai-agents-local-sandbox"
@@ -69,6 +70,7 @@ def create_project_structure(
6970
TemplateType.DEFAULT: ["acp.py"],
7071
TemplateType.DEFAULT_LANGGRAPH: ["acp.py", "graph.py", "tools.py"],
7172
TemplateType.DEFAULT_PYDANTIC_AI: ["acp.py", "agent.py", "tools.py"],
73+
TemplateType.DEFAULT_OPENAI_AGENTS: ["acp.py"],
7274
TemplateType.SYNC: ["acp.py"],
7375
TemplateType.SYNC_OPENAI_AGENTS: ["acp.py"],
7476
TemplateType.SYNC_OPENAI_AGENTS_LOCAL_SANDBOX: ["acp.py", "agent.py", "tools.py"],
@@ -184,6 +186,7 @@ def validate_agent_name(text: str) -> bool | str:
184186
"Which Async template would you like to use?",
185187
choices=[
186188
{"name": "Basic Async ACP", "value": TemplateType.DEFAULT},
189+
{"name": "Async ACP + OpenAI Agents SDK", "value": TemplateType.DEFAULT_OPENAI_AGENTS},
187190
{"name": "Async ACP + LangGraph", "value": TemplateType.DEFAULT_LANGGRAPH},
188191
{"name": "Async ACP + Pydantic AI", "value": TemplateType.DEFAULT_PYDANTIC_AI},
189192
],
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
23+
# Environments
24+
.env**
25+
.venv
26+
env/
27+
venv/
28+
ENV/
29+
env.bak/
30+
venv.bak/
31+
32+
# IDE
33+
.idea/
34+
.vscode/
35+
*.swp
36+
*.swo
37+
38+
# Git
39+
.git
40+
.gitignore
41+
42+
# Misc
43+
.DS_Store
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# {{ agent_name }} - Environment Variables
2+
# Copy this file to .env and fill in the values
3+
4+
# API key for your LLM provider
5+
LITELLM_API_KEY=
6+
7+
# LLM base URL (optional - override to use a different provider)
8+
# OPENAI_BASE_URL=
9+
10+
# SGP Configuration (optional - for tracing)
11+
# SGP_API_KEY=
12+
# SGP_ACCOUNT_ID=
13+
# SGP_CLIENT_BASE_URL=
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# syntax=docker/dockerfile:1.3
2+
FROM python:3.12-slim
3+
COPY --from=ghcr.io/astral-sh/uv:0.6.4 /uv /uvx /bin/
4+
5+
# Install system dependencies
6+
RUN apt-get update && apt-get install -y \
7+
htop \
8+
vim \
9+
curl \
10+
tar \
11+
python3-dev \
12+
postgresql-client \
13+
build-essential \
14+
libpq-dev \
15+
gcc \
16+
cmake \
17+
netcat-openbsd \
18+
nodejs \
19+
npm \
20+
&& apt-get clean \
21+
&& rm -rf /var/lib/apt/lists/**
22+
23+
ENV UV_COMPILE_BYTECODE=1
24+
ENV UV_LINK_MODE=copy
25+
ENV UV_HTTP_TIMEOUT=1000
26+
27+
WORKDIR /app/{{ project_path_from_build_root }}
28+
29+
# Copy dependency files for layer caching
30+
COPY {{ project_path_from_build_root }}/pyproject.toml {{ project_path_from_build_root }}/uv.lock ./
31+
32+
# Install dependencies (without project itself, for layer caching)
33+
RUN --mount=type=cache,target=/root/.cache/uv \
34+
uv sync --locked --no-install-project --no-dev
35+
36+
# Copy the project code
37+
COPY {{ project_path_from_build_root }}/project ./project
38+
39+
# Install the project
40+
RUN --mount=type=cache,target=/root/.cache/uv \
41+
uv sync --locked --no-dev
42+
43+
ENV PATH="/app/{{ project_path_from_build_root }}/.venv/bin:$PATH"
44+
ENV PYTHONPATH=/app
45+
46+
# Run the agent using uvicorn
47+
CMD ["uvicorn", "project.acp:acp", "--host", "0.0.0.0", "--port", "8000"]
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# syntax=docker/dockerfile:1.3
2+
FROM python:3.12-slim
3+
COPY --from=ghcr.io/astral-sh/uv:0.6.4 /uv /uvx /bin/
4+
5+
# Install system dependencies
6+
RUN apt-get update && apt-get install -y \
7+
htop \
8+
vim \
9+
curl \
10+
tar \
11+
python3-dev \
12+
postgresql-client \
13+
build-essential \
14+
libpq-dev \
15+
gcc \
16+
cmake \
17+
netcat-openbsd \
18+
nodejs \
19+
npm \
20+
&& apt-get clean \
21+
&& rm -rf /var/lib/apt/lists/*
22+
23+
RUN uv pip install --system --upgrade pip setuptools wheel
24+
25+
ENV UV_HTTP_TIMEOUT=1000
26+
27+
# Copy just the requirements file to optimize caching
28+
COPY {{ project_path_from_build_root }}/requirements.txt /app/{{ project_path_from_build_root }}/requirements.txt
29+
30+
WORKDIR /app/{{ project_path_from_build_root }}
31+
32+
# Install the required Python packages
33+
RUN uv pip install --system -r requirements.txt
34+
35+
# Copy the project code
36+
COPY {{ project_path_from_build_root }}/project /app/{{ project_path_from_build_root }}/project
37+
38+
39+
# Set environment variables
40+
ENV PYTHONPATH=/app
41+
42+
# Run the agent using uvicorn
43+
CMD ["uvicorn", "project.acp:acp", "--host", "0.0.0.0", "--port", "8000"]
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# {{ agent_name }} - AgentEx Async OpenAI Agents SDK Agent
2+
3+
This template builds an **asynchronous** (non-Temporal) agent built on the
4+
**OpenAI Agents SDK**, delivered through the unified harness surface on AgentEx:
5+
- Defines an OpenAI Agents SDK `Agent` (with an example weather tool) inline in
6+
`acp.py`
7+
- Wraps the SDK run in an `OpenAITurn`
8+
- Delivers canonical `StreamTaskMessage*` events via `UnifiedEmitter.auto_send_turn`
9+
(the async Redis push path), so the UI receives output in real time
10+
- Tracing integration to SGP / AgentEx
11+
12+
## Prerequisites
13+
14+
- An `OPENAI_API_KEY` in your environment (or a `LITELLM_API_KEY`, which is
15+
copied to `OPENAI_API_KEY` for LiteLLM-proxy compatibility)
16+
17+
## Running the Agent
18+
19+
```bash
20+
agentex agents run --manifest manifest.yaml
21+
```
22+
23+
## Project Structure
24+
25+
```
26+
{{ project_name }}/
27+
├── project/
28+
│ ├── __init__.py
29+
│ └── acp.py # ACP server, agent + tool definitions, event handlers
30+
├── Dockerfile
31+
├── manifest.yaml
32+
├── dev.ipynb
33+
{% if use_uv %}
34+
└── pyproject.toml
35+
{% else %}
36+
└── requirements.txt
37+
{% endif %}
38+
```
39+
40+
## Key Concepts
41+
42+
### Async ACP with the harness
43+
The async ACP model streams events over Redis instead of an HTTP response. The
44+
`@acp.on_task_event_send` handler runs the OpenAI Agents SDK and pushes the
45+
harness events to the task stream.
46+
47+
### The unified harness surface
48+
`OpenAITurn` + `UnifiedEmitter` are the unified harness surface. The turn
49+
normalizes the SDK's streamed run into canonical AgentEx events; the emitter
50+
traces and delivers them.
51+
52+
## Development
53+
54+
### 1. Add Your Own Tools
55+
Define new `@function_tool` functions in `project/acp.py` and add them to the
56+
agent's `tools=[...]` list in `create_agent()`.
57+
58+
### 2. Customize the Agent
59+
Edit `MODEL_NAME` and `INSTRUCTIONS` in `project/acp.py` to change the model or
60+
system prompt.
61+
62+
### 3. Configure Credentials
63+
Set your credentials via `manifest.yaml`, an exported environment variable, or a
64+
`.env` file in the project directory.
65+
66+
### 4. Run Locally
67+
```bash
68+
export ENVIRONMENT=development && agentex agents run --manifest manifest.yaml
69+
```

0 commit comments

Comments
 (0)