agentleFS
haseeb-heavenhaseeb-heaven/gworkspace-agent/AGENTS.md

gworkspace-agent

AGENTS.md82 starsChanged 7 months agoMITView on GitHub

This file provides AI coding agents with the context, conventions, and constraints needed to work effectively in this repository. It complements the README by covering build steps, test commands, code style, and project-specific rules that are most useful to an automated contributor. Compatible with: OpenAI Codex, GitHub Copilot Agent, Google Jules, Devin, Cursor, Windsurf, Aider, Goose, Factory, Zed, Warp, and any agent that reads AGENTS.md. GWorkspace Agent is a LangGraph-powered AI assistant for Google Workspace. It accepts natural language commands…

  • Reads credentials
  • Installs packages
  • Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.

    Of the AGENTS.md files we read, the 35,337 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

  • In this repository3 other files it gives its agents.

The file

Show its rules and text

We split this AGENTS.md into the rules it gives an agent

37 rules. About 2 are common, 24 are distinctive, and 11 are very specific to this project.

  • ≈2

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈24

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 11

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Very specific:

    Do not hardcode CI=true inside tests.

    line 120
  2. Distinctive:

    Add or update tests for every code change, even if not requested

    line 122
  3. Distinctive:

    Follow PEP 8 with a 100-character line limit

    line 139
  4. Distinctive:

    All public functions and classes must have docstrings

    line 140
  5. Distinctive:

    Use type annotations on all function signatures

    line 141
  6. Distinctive:

    If you must bypass hooks (use with extreme caution):

    line 178
  7. Distinctive:

    Do not hardcode main or master as a merge target anywhere in the pipeline

    line 280
  8. Very specific:

    Always run ruff check . and the unit test suite before pushing

    line 309
  9. Distinctive:

    Do not open a new PR to fix a failing one — push to the existing branch.

    line 310
  10. Distinctive:

    Do not merge manually — CI handles all merges

    line 311
  11. Very specific:

    Add new GWS tools by updating service_catalog.py and adding a wrapper in gws_assistant/tools/

    line 329
  12. Very specific:

    Update models.py to add or extend Pydantic models

    line 330
  13. Distinctive:

    Add new test cases to existing test files

    line 332
  14. Very specific:

    Update requirements.txt for new dependencies

    line 333
  15. Distinctive:

    Update this file (AGENTS.md) when architecture or conventions change

    line 336
  16. Distinctive:

    Never modify or weaken test assertions to force passing results

    line 343
  17. Distinctive:

    Do not reduce code coverage thresholds under any circumstances

    line 344
  18. Distinctive:

    Avoid skipping, mocking, or bypassing critical test paths unless explicitly approved

    line 345
  19. Distinctive:

    Ensure all changes maintain or improve existing test reliability

    line 346
  20. Common:

    Never hardcode credentials, API keys, tokens, or secrets in source code

    line 349
  21. Very specific:

    Do not commit .env, secrets.json, or any sensitive configuration files

    line 350
  22. Distinctive:

    Never expose environment variables in logs, outputs, or error messages

    line 351
  23. Common:

    Use secure configuration management (e.g., environment variables, secret managers)

    line 352
  24. Very specific:

    Do not remove, weaken, or bypass rules in safety_guard.py

    line 355
  25. Distinctive:

    Never manually merge pull requests — CI pipeline owns all merges

    line 360
  26. Distinctive:

    Do not resolve review comments manually without fixing underlying code issues

    line 361
  27. Distinctive:

    Avoid introducing CI bypasses or conditional shortcuts that skip validation

    line 362
  28. Distinctive:

    Do not modify critical infrastructure variables:

    line 366
  29. Distinctive:

    Do not remove or alter CI mode conditions such as:

    line 370
  30. Very specific:

    Avoid hardcoding branch names like main or master.

    line 372
  31. Very specific:

    Never pass raw dict objects across layers

    line 375
  32. Distinctive:

    Always use typed schemas (Pydantic models) for:

    line 376
  33. Very specific:

    Do not delete or modify .env files within the repository

    line 383
  34. Very specific:

    Ensure .gitignore properly excludes sensitive files

    line 384
  35. Distinctive:

    Do not introduce hacks, shortcuts, or temporary fixes that bypass system design

    line 388
  36. Distinctive:

    Ensure logging, error handling, and observability remain intact

    line 391
  37. Distinctive:

    Never log full email bodies, file contents, or user PII

    line 395

≈ “Common” is an estimate: at least 1 in 5 of the 45,344 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

AGENTS.md

This file provides AI coding agents with the context, conventions, and constraints needed to work effectively in this repository. It complements the README by covering build steps, test commands, code style, and project-specific rules that are most useful to an automated contributor.

Compatible with: OpenAI Codex, GitHub Copilot Agent, Google Jules, Devin, Cursor, Windsurf, Aider, Goose, Factory, Zed, Warp, and any agent that reads AGENTS.md.


Project Overview

GWorkspace Agent is a LangGraph-powered AI assistant for Google Workspace. It accepts natural language commands and translates them into Google Workspace API calls (Gmail, Drive, Calendar, Docs, Sheets, Slides, Meet, Chat) using a multi-agent planning and execution pipeline.

  • Language: Python 3.11
  • Core Framework: LangGraph + LangChain
  • LLM Backend: OpenAI-compatible API (configurable via LLM_PROVIDER / LLM_MODEL)
  • Interfaces: CLI, Desktop GUI (Tkinter), Web UI (Gradio), Telegram Bot, Cloud Run (REST)
  • Deployment: Google Cloud Run via Docker
  • Package root: gws_assistant/

Dev Environment Setup

# 1. Create and activate virtual environment
python -m venv .venv && source .venv/bin/activate

# 2. Install all dependencies
pip install -r requirements.txt
pip install -e .
pip install ruff mypy pytest pytest-cov

# 3. Copy environment config
cp .env.example .env
# Fill in LLM_API_KEY, LLM_PROVIDER, LLM_MODEL, and GWS_BINARY_PATH

# 4. Run setup wizard (first time only)
python -m gws_assistant --setup

Required Environment Variables

VariableRequiredDescription
LLM_API_KEY✅API key for LLM provider
LLM_PROVIDER✅openai, anthropic, or openrouter
LLM_MODEL✅Primary model — must support tool-calling
LLM_FALLBACK_MODEL❌First fallback model
LLM_FALLBACK_MODEL2❌Second fallback model
GWS_BINARY_PATH✅*Path to GWS CLI binary (*skipped in CI)
DEFAULT_RECIPIENT_EMAIL❌Default email for send operations
APP_LOG_LEVEL❌Logging verbosity (default: INFO)
CIautoSet by pipeline — disables binary path validation

Build & Run Commands

# CLI interface
python gws_cli.py

# Desktop GUI
python gws_gui.py

# Web UI (Gradio)
python gws_gui_web.py

# Telegram Bot
python gws_telegram.py

# Docker (production)
docker build -t gworkspace-agent . && docker run --env-file .env gworkspace-agent

Testing Instructions

The CI plan lives in .github/workflows/pipeline.yml. All checks must pass before a PR is merged.

# Run unit tests (safe for CI — no GWS binary needed)
pytest tests/ \
  -m "not live_integration" \
  --ignore=tests/manual \
  --ignore=tests/test_live_integration.py \
  --cov=gws_assistant \
  --cov-fail-under=70 \
  -v

# Run integration tests (mocked GWS)
pytest tests/test_integration.py \
  -m "not live_integration" \
  --cov=gws_assistant.langgraph_workflow \
  --cov=gws_assistant.execution \
  --cov-fail-under=65 \
  -v

# Run live integration tests (requires real GWS binary + credentials)
pytest tests/test_live_integration.py -m live_integration -v

Test Structure

tests/
├── test_unit_*.py           # Unit tests — fully mocked, no GWS binary needed
├── test_integration.py      # Integration tests — mocked GWS, real LangGraph workflow
├── test_hardening_policy.py # Security/hardening policy tests
├── test_live_integration.py # Live tests — requires real credentials
└── manual/                  # Manual scripts — excluded from CI

Testing Conventions

  • Fix failing tests by correcting source code, never by modifying test assertions
  • Coverage thresholds are enforced: unit ≥ 70%, integration ≥ 65% — do not lower them
  • Tag live tests with @pytest.mark.live_integration
  • Do not hardcode CI=true inside tests; use monkeypatch.setenv / monkeypatch.delenv
  • Tests that exercise non-CI validation must explicitly unset CI: monkeypatch.delenv("CI", raising=False)
  • Add or update tests for every code change, even if not requested

Code Style Guidelines

# Lint (must pass with zero errors)
ruff check .

# Type check
mypy gws_assistant --ignore-missing-imports

# Auto-fix safe lint issues
ruff check . --fix
  • Follow PEP 8 with a 100-character line limit
  • All public functions and classes must have docstrings
  • Use type annotations on all function signatures
  • Inter-agent data must use Pydantic models from models.py — never pass raw dict between layers
  • Return type from any tool wrapper must be ToolResult (defined in models.py)

Pre-commit Hooks

This project uses pre-commit hooks to prevent accidental commits of secret files (.env, secrets*.json, etc.) and to enforce code quality.

Installation

# After installing dependencies from requirements.txt
pre-commit install

What It Blocks

The pre-commit configuration (.pre-commit-config.yaml) includes:

  • Secret file detection: Blocks commits containing .env, .env.local, .env.*.local, secrets*.json, credentials, api_keys, and other secret files
  • Basic formatting: YAML/JSON validation, trailing whitespace, end-of-file fixer
  • Private key detection: Detects private keys in code

Running Hooks Manually

# Run on all files
pre-commit run --all-files

# Run on staged files only
pre-commit run

Bypassing Hooks (Not Recommended)

If you must bypass hooks (use with extreme caution):

git commit --no-verify -m "your message"

Never bypass hooks to commit .env or secrets files.


Repository Structure

gworkspace-agent/
├── gws_assistant/               # Core package
│   ├── agent_system.py          # Multi-agent orchestrator (Planner → Executor → Verifier)
│   ├── planner.py               # Decomposes user intent into ordered PlanSteps
│   ├── intent_parser.py         # NLU — parses raw input into structured Intent objects
│   ├── langgraph_workflow.py    # LangGraph state machine — primary execution workflow
│   ├── langchain_agent.py       # LangChain ReAct agent — alternative backend
│   ├── service_catalog.py       # Registry of 60+ GWS tool definitions
│   ├── verification_engine.py   # Validates tool outputs against original intent
│   ├── safety_guard.py          # Blocks destructive/irreversible GWS operations
│   ├── execution/               # Runs GWS binary tool calls
│   ├── tools/                   # Per-service tool wrappers (Gmail, Drive, Calendar …)
│   ├── llm_client.py            # LLM abstraction — OpenAI / Anthropic / OpenRouter
│   ├── config.py                # AppConfig — loads and validates all env vars
│   ├── model_registry.py        # Tool-capable model registry + fallback chain
│   ├── memory.py                # Short-term conversation memory
│   ├── memory_backend.py        # Long-term persistent memory backend
│   ├── models.py                # Pydantic models: Intent, PlanStep, WorkflowState, ToolResult …
│   ├── output_formatter.py      # Formats responses per interface (CLI / GUI / API)
│   ├── relevance.py             # Relevance scoring — filters tool results by intent
│   ├── drive_query_builder.py   # Builds Drive API query strings
│   ├── gmail_query_builder.py   # Builds Gmail search query strings
│   ├── exceptions.py            # Custom exception hierarchy
│   ├── logging_utils.py         # Structured logging setup
│   ├── cli_app.py               # CLI interface
│   ├── gui_app.py               # Desktop GUI (Tkinter)
│   ├── gradio_app.py            # Web UI (Gradio)
│   ├── telegram_app.py          # Telegram Bot
│   ├── gws_runner.py            # Subprocess wrapper for GWS CLI binary
│   ├── setup_wizard.py          # First-run setup wizard
│   └── chat_utils.py            # Shared chat utilities
├── gws_cli.py / gws_gui.py / gws_gui_web.py / gws_telegram.py   # Entrypoints
├── tests/                       # All tests
├── framework/                   # Internal framework utilities
├── scripts/                     # Setup and utility scripts
├── .github/workflows/pipeline.yml  # CI/CD pipeline
├── Dockerfile / Dockerfile.sandbox
├── requirements.txt
└── pyproject.toml

Architecture: Core Components

Planner (planner.py)

Receives a parsed Intent and returns an ordered List[PlanStep]. Each step maps exactly to a tool registered in service_catalog.py. Do not reference tool names that are not in the catalog.

Executor — LangGraph Workflow (langgraph_workflow.py)

State machine with nodes: parse_intent → plan → execute_step → verify → respond. Uses llm_client.py with automatic fallback via model_registry.py.

Executor — LangChain ReAct (langchain_agent.py)

Alternative backend activated when USE_LANGCHAIN=true. Dynamically loads tools from gws_assistant/tools/ and integrates memory.py.

Verification Engine (verification_engine.py)

Post-execution validator. Input: Intent + List[ToolResult]. Output: VerificationResult (passed / failed / needs_retry). Triggers re-planning on failure.

Safety Guard (safety_guard.py)

Pre-execution safety layer. Must be consulted before any destructive GWS operation. Outputs SafetyDecision (allow / block / require_confirmation). The risk policy matrix must not be weakened without explicit project owner approval.

Service Catalog (service_catalog.py)

Registers all 60+ GWS tools with name, description, parameters (JSON Schema), and required fields. When adding a new GWS capability, register it here first. The Planner will not use an unregistered tool.

GWS Runner (gws_runner.py)

Subprocess wrapper for the GWS CLI binary. Binary path comes from GWS_BINARY_PATH. When CI=true, the is_file() check is skipped — this bypass is required for CI and must not be removed.


CI/CD Pipeline

File: .github/workflows/pipeline.yml

Job Execution Order

lint → unit-tests → integration-tests → security
                                              ↓
                                       review-guard
                                    (blocks on unresolved
                                      review threads)
                                              ↓ safe_to_merge == true
                                         auto-merge
                                              ↓ on any failure
                                        ci-auto-fix

Auto-Merge

  • Squash-merges into the PR’s actual base branch (github.event.pull_request.base.ref)
  • Branch is deleted after merge
  • Do not hardcode main or master as a merge target anywhere in the pipeline

Review Guard

  • Queries all review threads via GraphQL
  • Blocks merge if any thread is unresolved and non-outdated
  • Posts detailed unresolved comment context to the linked Issue

CI Failure Auto-Fix

  • Triggers on any job failure in a PR
  • Posts full error logs and instructions to the linked Issue (or PR if no Issue found)
  • Agent must push fixes to the same head branch — never open a new PR or merge manually

Security Scan

  • Runs bandit (Python code security), safety (dependency vulnerabilities), and pip-audit (CVE scan)
  • Snyk SCA (Software Composition Analysis) and SAST (Static Application Security Testing) if SNYK_TOKEN is configured
  • Security findings are uploaded as artifacts for review
  • IMPORTANT: Security scans now fail the pipeline on HIGH/CRITICAL findings
  • Exception: Snyk SCA is allowed to fail for third-party vulnerabilities with no available fixes (already reviewed and dismissed)

PR & Commit Instructions

  • Commit format: <type>(<scope>): <short description> — e.g. fix(planner): handle empty intent, feat(tools): add Sheets append tool
  • PR title: mirror the primary commit message
  • Branch naming:
    • feature/<short-description> for new features
    • fix/<short-description> for bug fixes
    • hotfix/<short-description> for urgent production fixes
  • Always run ruff check . and the unit test suite before pushing
  • Do not open a new PR to fix a failing one — push to the existing branch; CI will auto-merge once green
  • Do not merge manually — CI handles all merges

Custom Skills

The following custom agent skills are installed in the skills/ directory and can be used to automate PR/MR workflows:

  • check-pr: Audits a Pull Request (GitHub), Merge Request (GitLab), or Changelist (Perforce) for unresolved comments, failing status checks, and incomplete descriptions.
  • greploop: An iterative review and fix loop that triggers Greptile reviews and addresses feedback until a 5/5 confidence score is achieved.

To use these skills, read the instructions in skills/<skill-name>/SKILL.md.


What an Agent Can Do

  • Fix failing tests by correcting source code in gws_assistant/
  • Add new GWS tools by updating service_catalog.py and adding a wrapper in gws_assistant/tools/
  • Update models.py to add or extend Pydantic models
  • Fix lint (ruff) and type (mypy) errors
  • Add new test cases to existing test files
  • Update requirements.txt for new dependencies
  • Refactor modules within gws_assistant/ following existing patterns
  • Improve docstrings and inline comments
  • Update this file (AGENTS.md) when architecture or conventions change

🚫 Agent Safety & Integrity Rules (Python Projects)

1. Testing & Quality Assurance

  • Never modify or weaken test assertions to force passing results
  • Do not reduce code coverage thresholds under any circumstances
  • Avoid skipping, mocking, or bypassing critical test paths unless explicitly approved
  • Ensure all changes maintain or improve existing test reliability

2. Security & Secrets Management

  • Never hardcode credentials, API keys, tokens, or secrets in source code
  • Do not commit .env, secrets.json, or any sensitive configuration files
  • Never expose environment variables in logs, outputs, or error messages
  • Use secure configuration management (e.g., environment variables, secret managers)

3. Core Safety Mechanisms

  • Do not remove, weaken, or bypass rules in safety_guard.py
  • Maintain all risk policies and validation checks intact
  • Any change affecting safety logic must be explicitly reviewed and justified

4. CI/CD Discipline

  • Never manually merge pull requests — CI pipeline owns all merges
  • Do not resolve review comments manually without fixing underlying code issues
  • Avoid introducing CI bypasses or conditional shortcuts that skip validation
  • Preserve all pipeline safeguards and verification steps

5. Configuration Integrity

  • Do not modify critical infrastructure variables:
    • GCP_PROJECT_ID
    • GCP_REGION
    • GCP_SERVICE
  • Do not remove or alter CI mode conditions such as:
    • if not ci_mode
  • Avoid hardcoding branch names like main or master; always use dynamic references (e.g., base.ref)

6. Architecture & Data Contracts

  • Never pass raw dict objects across layers
  • Always use typed schemas (Pydantic models) for:
    • Validation
    • Serialization
    • Inter-layer communication
  • Maintain strict typing and schema consistency across services

7. Repository Hygiene

  • Do not delete or modify .env files within the repository
  • Ensure .gitignore properly excludes sensitive files
  • Prevent accidental commits of generated or local configuration artifacts

8. Code Integrity Principles

  • Do not introduce hacks, shortcuts, or temporary fixes that bypass system design
  • Preserve modular architecture and separation of concerns
  • Maintain backward compatibility unless explicitly breaking changes are approved
  • Ensure logging, error handling, and observability remain intact

Security Considerations

  • Never log full email bodies, file contents, or user PII
  • bandit, safety, and pip-audit run on every PR — fix all HIGH severity findings before pushing
  • Security scans now fail the pipeline on HIGH/CRITICAL findings (non-blocking mode removed)
  • Snyk SAST (code security) runs on every PR and blocks merge on HIGH severity findings
  • Snyk SCA (dependency scan) runs on every PR but is allowed to fail for third-party vulnerabilities with no available fixes (e.g. gradio, litellm)
  • Secrets live in GitHub Actions Secrets only — never in committed .env files
  • .env.example documents required keys but contains no real values
  • The safety_guard.py policy matrix is the authoritative source for what operations are allowed without user confirmation
  • Pre-commit hooks block commits of .env and secret files

Branch Strategy

main        ← production branch (Cloud Run deploy triggers on push)
develop     ← integration branch (most PRs target this)
feature/**  ← feature development
hotfix/**   ← urgent production fixes

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.