|
| 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). |
0 commit comments