Skip to main content
Glama
README.md
# Chief of Staff Agent

AI agent for meeting briefings, context management, and to-do tracking. Integrates with Google Workspace (Calendar, Gmail, Drive), Discord, and uses Claude or Ollama for summarization.

## Quick Start

```bash
# 1. Install
pip install -e .

# 2. Create directories
mkdir -p credentials data

# 3. Set up credentials (see sections below)

# 4. Run
python -m src.mcp_server.server
```

---

## Getting API Keys

### Anthropic (Required)

1. Go to https://console.anthropic.com/
2. Create an API key
3. Add to `.env`: `COS_ANTHROPIC_API_KEY=sk-ant-...`

### Google Workspace (Required)

1. Go to [Google Cloud Console](https://console.cloud.google.com/)
2. Create a new project (or select existing)
3. Enable APIs:
   - Google Calendar API
   - Gmail API
   - Google Drive API
4. Go to **APIs & Services > Credentials**
5. Click **Create Credentials > OAuth 2.0 Client ID**
6. Select **Desktop application**
7. Download JSON and save as `credentials/google_credentials.json`

### Discord (Optional)

1. Go to https://discord.com/developers/applications
2. Create a new application
3. Go to **Bot** tab, create bot
4. Copy token to `.env`: `COS_DISCORD_BOT_TOKEN=...`
5. Add channel IDs: `COS_DISCORD_CHANNEL_IDS=["123456789","987654321"]`

### Ollama (Optional, for local LLM)

```bash
# Install from https://ollama.ai
ollama pull llama3.1:8b
```

---

## Storing Secrets

Create a `.env` file in the project root:

```bash
# Required
COS_USER_ID=your.email@gmail.com
COS_ANTHROPIC_API_KEY=sk-ant-api03-...

# LLM Provider ("anthropic" or "ollama")
COS_LLM_PROVIDER=anthropic

# Optional: Discord
COS_DISCORD_BOT_TOKEN=MTI...
COS_DISCORD_CHANNEL_IDS=["123456789"]

# Optional: Ollama (if using local LLM)
COS_OLLAMA_HOST=http://localhost:11434
COS_OLLAMA_MODEL=llama3.1:8b

# Optional: Database encryption
COS_DATABASE_ENCRYPTION_KEY=your-secret-key

# Optional: Scheduling (default: 8:00 AM)
COS_DAILY_BRIEFING_HOUR=8
COS_DAILY_BRIEFING_MINUTE=0
```

**File structure** (credentials/ and data/ are git-ignored):

```
gws-mcp/
├── credentials/
│   ├── google_credentials.json   # OAuth client from Google Console
│   └── google_token.json         # Auto-generated after first auth
├── data/
│   └── cos.db                    # SQLite database (auto-created)
└── .env                          # Your secrets
```

Google OAuth tokens are stored securely in your OS keyring (macOS Keychain, Windows Credential Manager, or Linux Secret Service).

---

## Running the Agent

### As MCP Server (for Claude Desktop/Code)

```bash
python -m src.mcp_server.server
```

Add to Claude's MCP config (`~/.claude/claude_desktop_config.json` or similar):

```json
{
  "mcpServers": {
    "chief-of-staff": {
      "command": "python",
      "args": ["-m", "src.mcp_server.server"],
      "cwd": "/path/to/gws-mcp"
    }
  }
}
```

### First Run

On first run, a browser window opens for Google OAuth consent. Grant read access to Calendar, Gmail, and Drive.

---

## Force Run Now (Bypass Scheduler)

Create a script `run_briefing.py`:

```python
#!/usr/bin/env python3
"""Run a meeting briefing immediately, bypassing the scheduler."""

import asyncio
from src.core.config import get_settings
from src.agents.briefing import BriefingAgent
from src.google_client.auth import GoogleAuth
from src.google_client.calendar import GoogleCalendarClient
from src.google_client.gmail import GoogleGmailClient
from src.google_client.drive import GoogleDriveClient
from src.discord_client.client import DiscordBotClient
from src.storage.database import Database
from src.storage.repository import SQLiteRepository
from src.storage.migrations import run_migrations
from src.llm.factory import create_llm_client
from src.document_processor.processor import DocumentProcessor


async def main():
    settings = get_settings()

    # Initialize storage
    db = Database(settings.database_path)
    run_migrations(db)
    storage = SQLiteRepository(db)

    # Initialize Google clients
    auth = GoogleAuth(settings.user_id)
    creds = await auth.get_credentials()
    calendar = GoogleCalendarClient(credentials=creds)
    gmail = GoogleGmailClient(credentials=creds)
    drive = GoogleDriveClient(credentials=creds)

    # Initialize Discord (optional)
    discord = None
    if settings.discord_bot_token:
        discord = DiscordBotClient(settings.discord_bot_token)

    # Initialize LLM and processor
    llm = create_llm_client(settings)
    processor = DocumentProcessor(llm=llm, settings=settings)

    # Create briefing agent
    agent = BriefingAgent(
        llm=llm,
        calendar=calendar,
        gmail=gmail,
        drive=drive,
        discord=discord,
        storage=storage,
        processor=processor,
        settings=settings,
    )

    # Generate briefing
    print("Generating briefing for next meeting...")
    briefing = await agent.generate_briefing_for_next_meeting()

    if briefing:
        print(f"\n{'='*60}")
        print(f"BRIEFING: {briefing.event_title}")
        print(f"{'='*60}\n")
        print(briefing.content)
    else:
        print("No upcoming meetings with attendees found.")


if __name__ == "__main__":
    asyncio.run(main())
```

Run it:

```bash
python run_briefing.py
```

---

## Available MCP Tools

| Tool | Description |
|------|-------------|
| `todo_list` | List todos (optionally filter by status) |
| `todo_add` | Add a new todo item |
| `todo_update` | Update todo status |
| `calendar_list_events` | List upcoming calendar events |
| `gmail_search` | Search Gmail messages |
| `drive_get_document` | Get a Google Drive document |
| `discord_read_channel` | Read Discord channel messages |
| `generate_briefing` | Generate a meeting briefing |

---

## Configuration Reference

| Variable | Default | Description |
|----------|---------|-------------|
| `COS_USER_ID` | *required* | User identifier (email) |
| `COS_ANTHROPIC_API_KEY` | - | Anthropic API key |
| `COS_LLM_PROVIDER` | `anthropic` | `anthropic` or `ollama` |
| `COS_ANTHROPIC_MODEL` | `claude-3-5-haiku-20241022` | Claude model |
| `COS_OLLAMA_HOST` | `http://localhost:11434` | Ollama server URL |
| `COS_OLLAMA_MODEL` | `llama3.1:8b` | Ollama model |
| `COS_GOOGLE_CREDENTIALS_PATH` | `credentials/google_credentials.json` | OAuth client file |
| `COS_DATABASE_PATH` | `data/cos.db` | SQLite database path |
| `COS_DATABASE_ENCRYPTION_KEY` | - | Optional SQLCipher key |
| `COS_DISCORD_BOT_TOKEN` | - | Discord bot token |
| `COS_DISCORD_CHANNEL_IDS` | `[]` | JSON array of channel IDs |
| `COS_CALENDAR_LOOKAHEAD_DAYS` | `7` | Days ahead to fetch events |
| `COS_GMAIL_SEARCH_DAYS` | `7` | Days back to search emails |
| `COS_DAILY_BRIEFING_HOUR` | `8` | Hour for daily briefing (24h) |
| `COS_DAILY_BRIEFING_MINUTE` | `0` | Minute for daily briefing |
| `COS_CONSENT_TIMEOUT` | `60.0` | Seconds to wait for write consent |

---

## Development

```bash
# Install with dev tools
pip install -e ".[dev]"

# Run static analysis (required before commits)
python tools/analyzers/static_rigor.py src/
python tools/analyzers/contracts.py src/ --strict
python tools/analyzers/scaling.py src/
python tools/analyzers/callgraph.py src/ --format=summary
```

See `docs/DESIGN.md` for architecture details.