Add tiered model delegation for gmail operations

Implements cost-efficient gmail operations by delegating to appropriate
model tiers via Claude CLI subprocess. Simple fetches use no LLM,
summarization and triage delegate to Sonnet, complex reasoning stays
with Opus (PA). Uses subscription instead of API key.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
OpenCode Test
2025-12-31 21:35:32 -08:00
parent 690c57caeb
commit d9332ae118
5 changed files with 446 additions and 1 deletions

View File

@@ -9,6 +9,34 @@ allowed-tools:
Access Gmail via direct Python API calls. Uses OAuth credentials at `~/.gmail-mcp/`.
## Delegated Operations (Recommended)
Use the tiered delegation helper for cost-efficient operations. Uses Claude CLI with your subscription (no API key needed):
```bash
GMAIL_PY=~/.claude/mcp/gmail/venv/bin/python
HELPER=~/.claude/mcp/delegation/gmail_delegate.py
# Haiku tier - list unread (no LLM call, just fetches)
$GMAIL_PY $HELPER check-unread --days 7
# Sonnet tier - summarize emails (spawns claude --model sonnet)
$GMAIL_PY $HELPER summarize --query "from:github.com"
# Sonnet tier - triage urgent (spawns claude --model sonnet)
$GMAIL_PY $HELPER urgent
```
### When to Use Each Tier
| Request Type | Command | Model |
|--------------|---------|-------|
| "Check my email" | `check-unread` | Haiku |
| "How many unread?" | `check-unread` | Haiku |
| "Summarize X" | `summarize --query "X"` | Sonnet |
| "What's urgent?" | `urgent` | Sonnet |
| "What should I prioritize?" | (PA direct) | Opus |
## Usage
For any Gmail request, use Bash to run the Python helper:
@@ -83,8 +111,37 @@ for msg in results.get('messages', []):
EOF
```
## Model Selection
Gmail operations use tiered delegation per `model-policy.json`:
| Model | Use For | Examples |
|-------|---------|----------|
| **Haiku** | Fetch, count, list, simple search | "How many unread?", "List from X" |
| **Sonnet** | Summarize, categorize, extract | "Summarize this email", "Group by topic" |
| **Opus** | Prioritize, analyze, cross-reference | "What should I handle first?" |
### Delegation Pattern
When invoking gmail operations, the PA should:
1. **Classify the request** — Is it fetch-only, summarization, or analysis?
2. **Delegate appropriately**:
- Haiku: API calls + simple formatting
- Sonnet: API calls + content understanding
- Opus: Only for strategic reasoning
3. **Escalate if needed** — If lower tier can't handle it, escalate
### Implementation Note
Until Task tool delegation is available, the PA executes gmail operations directly
but should mentally "account" for which tier the work belongs to. This policy
enables future cost optimization when subagent spawning is implemented.
## Policy
- Read-only operations only
- Summarize results (don't dump raw content)
- Report metadata, not full body unless asked
- Start with lowest capable model tier
- Escalate only when task complexity requires