Skip to content

Commit ca90a1a

Browse files
Add SGP Help Agent with multi-repo git cloning and MCP support
1 parent a277f10 commit ca90a1a

File tree

13 files changed

+1226
-2
lines changed

13 files changed

+1226
-2
lines changed
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: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 (including git for repo cloning)
6+
RUN apt-get update && apt-get install -y \
7+
htop \
8+
vim \
9+
curl \
10+
tar \
11+
git \
12+
python3-dev \
13+
postgresql-client \
14+
build-essential \
15+
libpq-dev \
16+
gcc \
17+
cmake \
18+
netcat-openbsd \
19+
nodejs \
20+
npm \
21+
&& apt-get clean \
22+
&& rm -rf /var/lib/apt/lists/*
23+
24+
# Install tctl (Temporal CLI)
25+
RUN curl -L https://github.com/temporalio/tctl/releases/download/v1.18.1/tctl_1.18.1_linux_arm64.tar.gz -o /tmp/tctl.tar.gz && \
26+
tar -xzf /tmp/tctl.tar.gz -C /usr/local/bin && \
27+
chmod +x /usr/local/bin/tctl && \
28+
rm /tmp/tctl.tar.gz
29+
30+
RUN uv pip install --system --upgrade pip setuptools wheel
31+
32+
ENV UV_HTTP_TIMEOUT=1000
33+
34+
# Copy pyproject.toml and README.md to install dependencies
35+
COPY 10_async/10_temporal/100_sgp_help/pyproject.toml /app/100_sgp_help/pyproject.toml
36+
COPY 10_async/10_temporal/100_sgp_help/README.md /app/100_sgp_help/README.md
37+
38+
WORKDIR /app/100_sgp_help
39+
40+
# Copy the project code
41+
COPY 10_async/10_temporal/100_sgp_help/project /app/100_sgp_help/project
42+
43+
# Copy the test files
44+
COPY 10_async/10_temporal/100_sgp_help/tests /app/100_sgp_help/tests
45+
46+
# Copy shared test utilities
47+
COPY test_utils /app/test_utils
48+
49+
# Install the required Python packages with dev dependencies
50+
RUN uv pip install --system .[dev]
51+
52+
WORKDIR /app/100_sgp_help
53+
54+
# Set environment variables
55+
ENV PYTHONPATH=/app
56+
57+
# Set test environment variables
58+
ENV AGENT_NAME=at100-sgp-help
59+
# Run the ACP server using uvicorn
60+
CMD ["uvicorn", "project.acp:acp", "--host", "0.0.0.0", "--port", "8000"]
61+
62+
# When we deploy the worker, we will replace the CMD with the following
63+
# CMD ["python", "-m", "run_worker"]
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
# SGP Help Agent
2+
3+
An AI agent that answers questions about the Scale Generative Platform (SGP) codebase by searching multiple GitHub repositories and providing answers with citations.
4+
5+
## Overview
6+
7+
The SGP Help Agent clones and searches three SGP repositories:
8+
- **scaleapi** - Scale API repository (focus: `packages/egp-api-backend/`, `packages/egp-annotation/`)
9+
- **sgp** - SGP core platform
10+
- **sgp-solutions** - Example implementations and solutions
11+
12+
The agent operates in read-only mode, using tools like Read, Grep, Glob, and Bash (git commands) to explore the codebase and answer questions with GitHub URL citations.
13+
14+
## Features
15+
16+
- **Multi-repo workspace**: Clones 3 SGP repos on task initialization with smart caching
17+
- **Read-only operation**: No code editing, focused on answering questions
18+
- **Citation-focused**: Provides GitHub URLs for all code references
19+
- **MCP integration**: Uses SGP docs MCP server for documentation queries
20+
- **Session continuity**: Maintains conversation context across multiple turns
21+
- **Smart caching**: Uses shared cache to minimize network traffic
22+
23+
## Architecture
24+
25+
Built on:
26+
- **Claude Agents SDK**: Powers the AI agent with tool use
27+
- **Temporal workflows**: Provides durable execution and retry logic
28+
- **AgentEx SDK**: Provides ACP integration and streaming
29+
30+
Key components:
31+
- `workflow.py` - SGPHelpWorkflow for orchestration
32+
- `activities.py` - Git operations (setup_sgp_repos activity)
33+
- `run_worker.py` - Temporal worker registration
34+
- `acp.py` - ACP server setup
35+
36+
## Example Questions
37+
38+
Try asking:
39+
- "Where is the SGP API client implemented?"
40+
- "Show me examples from sgp-solutions"
41+
- "How does authentication work in the backend?"
42+
- "What annotation features are available?"
43+
- "Where is the error handling in the API backend?"
44+
45+
## Local Development
46+
47+
### Prerequisites
48+
49+
- Python 3.12+
50+
- Rye or UV for dependency management
51+
- Temporal server running (via docker compose)
52+
- Redis running
53+
- Anthropic API key
54+
55+
### Setup
56+
57+
1. Set environment variables:
58+
```bash
59+
export ANTHROPIC_API_KEY=your-key-here
60+
export REDIS_URL=redis://localhost:6379
61+
```
62+
63+
2. Run the agent:
64+
```bash
65+
agentex agents run --manifest manifest.yaml --debug-worker
66+
```
67+
68+
3. Create a task via API and send questions
69+
70+
### Debug Mode
71+
72+
To debug the worker:
73+
```bash
74+
agentex agents run --manifest manifest.yaml --debug-worker --debug-port 5679
75+
```
76+
77+
Then attach VS Code debugger to port 5679.
78+
79+
## Directory Structure
80+
81+
```
82+
100_sgp_help/
83+
├── manifest.yaml # Agent configuration
84+
├── pyproject.toml # Dependencies
85+
├── Dockerfile # Container image
86+
├── .dockerignore # Docker ignore rules
87+
├── project/
88+
│ ├── acp.py # ACP server
89+
│ ├── workflow.py # SGPHelpWorkflow
90+
│ ├── activities.py # Git operations activity
91+
│ └── run_worker.py # Worker registration
92+
├── tests/
93+
│ └── test_sgp_agent.py # Test suite
94+
└── README.md # This file
95+
```
96+
97+
## Workspace Structure
98+
99+
When a task is created, the agent sets up:
100+
101+
```
102+
.claude-workspace/
103+
├── .repos-cache/ # Shared cache (reused across tasks)
104+
│ ├── scaleapi/
105+
│ ├── sgp/
106+
│ └── sgp-solutions/
107+
└── {task-id}/
108+
└── repos/ # Task-specific clones (working directory)
109+
├── scaleapi/
110+
├── sgp/
111+
└── sgp-solutions/
112+
```
113+
114+
The agent's `cwd` is set to `repos/` so it can access all three repositories.
115+
116+
## System Prompt
117+
118+
The agent uses a specialized system prompt that:
119+
- Identifies itself as an SGP expert
120+
- Explains the workspace structure and repo focus areas
121+
- Requires GitHub URL citations for all code references
122+
- Enforces read-only mode
123+
- Guides multi-repo search strategy
124+
125+
## Caching Strategy
126+
127+
To minimize network traffic and improve performance:
128+
1. **Cache directory**: Shared across all tasks at `.repos-cache/`
129+
2. **Initial clone**: `git clone --depth=1` to cache (only latest commit)
130+
3. **Cache update**: `git fetch origin` + `git reset --hard origin/HEAD`
131+
4. **Task clone**: `git clone --depth=1 file://{cache_path}` (local, fast)
132+
133+
## MCP Integration
134+
135+
The agent is configured to use the SGP docs MCP server:
136+
- URL: https://docs.gp.scale.com/mcp
137+
- Transport: SSE (Server-Sent Events)
138+
139+
Note: MCP integration depends on Claude Agent SDK support for HTTP/SSE transports.
140+
141+
## Testing
142+
143+
Run the test suite:
144+
```bash
145+
cd examples/tutorials/10_async/10_temporal/100_sgp_help
146+
uv run pytest tests/test_sgp_agent.py -v
147+
```
148+
149+
## Performance
150+
151+
Typical timings:
152+
- Repo setup (first time): 2-3 minutes
153+
- Repo setup (cached): 30-60 seconds
154+
- First response: 20-30 seconds
155+
- Follow-up responses: 5-10 seconds
156+
157+
## Limitations
158+
159+
1. **MCP Transport**: HTTP/SSE MCP configuration format requires Claude Agent SDK support
160+
2. **Cache freshness**: Repos cached indefinitely (no automatic updates)
161+
3. **Shallow clones**: Only latest commit available (no full git history)
162+
4. **Citation accuracy**: Relies on system prompt compliance
163+
164+
## Future Enhancements
165+
166+
- Subagents for specialized tasks (code-expert, docs-expert, solutions-expert)
167+
- Auto-citation post-processing hooks
168+
- Smart cache with TTL and auto-refresh
169+
- Multi-branch/tag support
170+
- Git blame integration for authorship tracking
171+
- Cache locking for concurrent worker safety
172+
173+
## Deployment
174+
175+
Build and push the Docker image:
176+
```bash
177+
agentex agents build --manifest manifest.yaml
178+
agentex agents deploy --manifest manifest.yaml
179+
```
180+
181+
Ensure secrets are configured:
182+
- `anthropic-api-key` (key: `api-key`)
183+
- `redis-url-secret` (key: `url`)
184+
185+
## License
186+
187+
Same as parent project (agentex-sdk).
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
kind: Agent
2+
3+
# Build Configuration
4+
build:
5+
context:
6+
# Root directory for the build context
7+
root: ../../../ # Up to tutorials level to include test_utils
8+
9+
# Paths to include in the Docker build context
10+
include_paths:
11+
- 10_async/10_temporal/100_sgp_help
12+
- test_utils
13+
14+
# Path to Dockerfile (relative to root)
15+
dockerfile: 10_async/10_temporal/100_sgp_help/Dockerfile
16+
17+
# Path to .dockerignore (relative to root)
18+
dockerignore: 10_async/10_temporal/100_sgp_help/.dockerignore
19+
20+
# Local Development Configuration
21+
local_development:
22+
agent:
23+
port: 8000
24+
host_address: host.docker.internal
25+
paths:
26+
acp: project/acp.py
27+
worker: project/run_worker.py
28+
29+
# Agent Configuration
30+
agent:
31+
acp_type: async
32+
name: sgp-help-agent
33+
description: SGP Help Agent - answers questions about Scale Generative Platform codebase
34+
35+
temporal:
36+
enabled: true
37+
workflows:
38+
- name: SGPHelpWorkflow
39+
queue_name: sgp-help-queue
40+
41+
credentials:
42+
- env_var_name: ANTHROPIC_API_KEY
43+
secret_name: anthropic-api-key
44+
secret_key: api-key
45+
- env_var_name: REDIS_URL
46+
secret_name: redis-url-secret
47+
secret_key: url
48+
49+
# Deployment Configuration
50+
deployment:
51+
image:
52+
repository: ""
53+
tag: "latest"
54+
imagePullSecrets:
55+
- name: my-registry-secret
56+
global:
57+
agent:
58+
name: "sgp-help-agent"
59+
description: "SGP Help Agent"
60+
replicaCount: 1
61+
resources:
62+
requests:
63+
cpu: "500m"
64+
memory: "1Gi"
65+
limits:
66+
cpu: "1000m"
67+
memory: "2Gi"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""SGP Help Agent - Project package."""

0 commit comments

Comments
 (0)