Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ dependencies = [
"yaspin>=3.1.0",
"claude-agent-sdk>=0.1.0",
"anthropic>=0.40.0",
"partial-json-parser>=0.2.1", # For voice agent streaming JSON parsing
"google-auth>=2.0.0", # For Vertex AI authentication in voice agents
]

requires-python = ">= 3.12,<4"
Expand Down
85 changes: 53 additions & 32 deletions src/agentex/lib/cli/commands/init.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from __future__ import annotations

from enum import Enum
from typing import Any, Dict
from typing import Any, Dict, Optional
from pathlib import Path

import typer
import questionary
from jinja2 import Environment, FileSystemLoader
from rich.rule import Rule
Expand All @@ -27,6 +28,7 @@ class TemplateType(str, Enum):
DEFAULT = "default"
SYNC = "sync"
SYNC_OPENAI_AGENTS = "sync-openai-agents"
VOICE = "voice"


def render_template(
Expand Down Expand Up @@ -60,6 +62,7 @@ def create_project_structure(
TemplateType.DEFAULT: ["acp.py"],
TemplateType.SYNC: ["acp.py"],
TemplateType.SYNC_OPENAI_AGENTS: ["acp.py"],
TemplateType.VOICE: ["acp.py"],
}[template_type]

# Create project/code files
Expand Down Expand Up @@ -102,9 +105,15 @@ def get_project_context(answers: Dict[str, Any], project_path: Path, manifest_ro
# Now, this is actually the exact same as the project_name because we changed the build root to be ../
project_path_from_build_root = project_name

# Create PascalCase class name from agent name
agent_class_name = "".join(
word.capitalize() for word in answers["agent_name"].split("-")
)

return {
**answers,
"project_name": project_name,
"agent_class_name": agent_class_name,
"workflow_class": "".join(
word.capitalize() for word in answers["agent_name"].split("-")
)
Expand All @@ -115,7 +124,14 @@ def get_project_context(answers: Dict[str, Any], project_path: Path, manifest_ro
}


def init():
def init(
voice: bool = typer.Option(
False,
"--voice",
hidden=True,
help="Create a voice agent template (LiveKit + Gemini)",
),
):
"""Initialize a new agent project"""
console.print(
Panel.fit(
Expand All @@ -124,43 +140,48 @@ def init():
)
)

# Use a Rich table for template descriptions
table = Table(show_header=True, header_style="bold blue")
table.add_column("Template", style="cyan", no_wrap=True)
table.add_column("Description", style="white")
table.add_row(
"[bold cyan]Async - ACP Only[/bold cyan]",
"Asynchronous, non-blocking agent that can process multiple concurrent requests. Best for straightforward asynchronous agents that don't need durable execution. Good for asynchronous workflows, stateful applications, and multi-step analysis.",
)
table.add_row(
"[bold cyan]Async - Temporal[/bold cyan]",
"Asynchronous, non-blocking agent with durable execution for all steps. Best for production-grade agents that require complex multi-step tool calls, human-in-the-loop approvals, and long-running processes that require transactional reliability.",
)
table.add_row(
"[bold cyan]Sync ACP[/bold cyan]",
"Synchronous agent that processes one request per task with a simple request-response pattern. Best for low-latency use cases, FAQ bots, translation services, and data lookups.",
)
console.print()
console.print(table)
console.print()
# If --voice flag is passed, skip the menu and use voice template
if voice:
console.print("[bold cyan]Creating Voice Agent template...[/bold cyan]\n")
template_type = TemplateType.VOICE
else:
# Use a Rich table for template descriptions
table = Table(show_header=True, header_style="bold blue")
table.add_column("Template", style="cyan", no_wrap=True)
table.add_column("Description", style="white")
table.add_row(
"[bold cyan]Async - ACP Only[/bold cyan]",
"Asynchronous, non-blocking agent that can process multiple concurrent requests. Best for straightforward asynchronous agents that don't need durable execution. Good for asynchronous workflows, stateful applications, and multi-step analysis.",
)
table.add_row(
"[bold cyan]Async - Temporal[/bold cyan]",
"Asynchronous, non-blocking agent with durable execution for all steps. Best for production-grade agents that require complex multi-step tool calls, human-in-the-loop approvals, and long-running processes that require transactional reliability.",
)
table.add_row(
"[bold cyan]Sync ACP[/bold cyan]",
"Synchronous agent that processes one request per task with a simple request-response pattern. Best for low-latency use cases, FAQ bots, translation services, and data lookups.",
)
console.print()
console.print(table)
console.print()

# Gather project information
template_type = questionary.select(
"What type of template would you like to create?",
choices=[
{"name": "Async - ACP Only", "value": TemplateType.DEFAULT},
{"name": "Async - Temporal", "value": "temporal_submenu"},
{"name": "Sync ACP", "value": "sync_submenu"},
],
).ask()

def validate_agent_name(text: str) -> bool | str:
"""Validate agent name follows required format"""
is_valid = len(text) >= 1 and text.replace("-", "").isalnum() and text.islower()
if not is_valid:
return "Invalid name. Use only lowercase letters, numbers, and hyphens. Examples: 'my-agent', 'newsbot'"
return True

# Gather project information
template_type = questionary.select(
"What type of template would you like to create?",
choices=[
{"name": "Async - ACP Only", "value": TemplateType.DEFAULT},
{"name": "Async - Temporal", "value": "temporal_submenu"},
{"name": "Sync ACP", "value": "sync_submenu"},
],
).ask()
if not template_type:
if template_type is None:
return

# If Temporal was selected, show sub-menu for Temporal variants
Expand Down
43 changes: 43 additions & 0 deletions src/agentex/lib/cli/templates/voice/.dockerignore.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# Environments
.env**
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# IDE
.idea/
.vscode/
*.swp
*.swo

# Git
.git
.gitignore

# Misc
.DS_Store
42 changes: 42 additions & 0 deletions src/agentex/lib/cli/templates/voice/Dockerfile-uv.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# syntax=docker/dockerfile:1.3
FROM python:3.12-slim
COPY --from=ghcr.io/astral-sh/uv:0.6.4 /uv /uvx /bin/

# Install system dependencies
RUN apt-get update && apt-get install -y \
htop \
vim \
curl \
tar \
python3-dev \
postgresql-client \
build-essential \
libpq-dev \
gcc \
cmake \
netcat-openbsd \
nodejs \
npm \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/**

RUN uv pip install --system --upgrade pip setuptools wheel

ENV UV_HTTP_TIMEOUT=1000

# Copy just the pyproject.toml file to optimize caching
COPY {{ project_path_from_build_root }}/pyproject.toml /app/{{ project_path_from_build_root }}/pyproject.toml

WORKDIR /app/{{ project_path_from_build_root }}

# Install the required Python packages using uv
RUN uv pip install --system .

# Copy the project code
COPY {{ project_path_from_build_root }}/project /app/{{ project_path_from_build_root }}/project

# Set environment variables
ENV PYTHONPATH=/app

# Run the agent using uvicorn
CMD ["uvicorn", "project.acp:acp", "--host", "0.0.0.0", "--port", "8000"]
43 changes: 43 additions & 0 deletions src/agentex/lib/cli/templates/voice/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# syntax=docker/dockerfile:1.3
FROM python:3.12-slim
COPY --from=ghcr.io/astral-sh/uv:0.6.4 /uv /uvx /bin/

# Install system dependencies
RUN apt-get update && apt-get install -y \
htop \
vim \
curl \
tar \
python3-dev \
postgresql-client \
build-essential \
libpq-dev \
gcc \
cmake \
netcat-openbsd \
node \
npm \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN uv pip install --system --upgrade pip setuptools wheel

ENV UV_HTTP_TIMEOUT=1000

# Copy just the requirements file to optimize caching
COPY {{ project_path_from_build_root }}/requirements.txt /app/{{ project_path_from_build_root }}/requirements.txt

WORKDIR /app/{{ project_path_from_build_root }}

# Install the required Python packages
RUN uv pip install --system -r requirements.txt

# Copy the project code
COPY {{ project_path_from_build_root }}/project /app/{{ project_path_from_build_root }}/project


# Set environment variables
ENV PYTHONPATH=/app

# Run the agent using uvicorn
CMD ["uvicorn", "project.acp:acp", "--host", "0.0.0.0", "--port", "8000"]
Loading
Loading