A 3-layer architecture system that separates LLM orchestration from deterministic execution, maximizing reliability and maintainability.
This project implements a three-layer architecture:
- Standard Operating Procedures written in Markdown
- Located in
directives/ - Define goals, inputs, tools/scripts to use, outputs, and edge cases
- Natural language instructions that guide the AI orchestrator
- AI agent that reads directives and makes intelligent routing decisions
- Calls execution tools in the right order
- Handles errors and asks for clarification when needed
- Updates directives with learnings over time
- Deterministic Python scripts in
execution/ - Handles API calls, data processing, file operations, and database interactions
- Reliable, testable, and fast
- No LLM uncertainty in this layer
.
├── directives/ # Markdown SOPs (instruction set)
├── execution/ # Python scripts (deterministic tools)
├── .tmp/ # Intermediate files (never commit)
├── .env # Environment variables and API keys
├── .env.example # Template for environment variables
├── credentials.json # Google OAuth credentials (gitignored)
├── token.json # Google OAuth token (gitignored)
├── AGENTS.md # Architecture documentation
└── README.md # This file
- Python 3.8 or higher
- Git
- Access to required APIs (Google, OpenAI, etc.)
# Clone or initialize the repository
git init
# Install Python dependencies
pip install -r requirements.txt
# Copy the environment template
copy .env.example .env # Windows
# cp .env.example .env # Linux/MacEdit .env and add your API keys and credentials:
- Google API credentials (for Sheets, Slides, etc.)
- OpenAI or Anthropic API keys (if using)
- Any other required API credentials
- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable required APIs (Sheets, Slides, Drive, etc.)
- Create OAuth 2.0 credentials
- Download credentials and save as
credentials.jsonin the project root
See GOOGLE_SHEETS_SETUP.md for detailed setup instructions.
Analyze the complete structure of any Google Sheet:
py execution\analyze_sheet_structure.py "https://docs.google.com/spreadsheets/d/YOUR_SHEET_ID/edit"What it extracts:
- All sheets/tabs in the spreadsheet
- Column headers and row headers
- Data types for each column (number, text, date, URL, email, boolean)
- Row and column counts
- Sample data from each sheet
- Grid properties and metadata
Output: JSON file saved to .tmp/sheet_analysis_{spreadsheet_id}.json
First time setup: See GOOGLE_SHEETS_SETUP.md for Google API authentication.
- Create a new Markdown file in
directives/ - Follow this template:
# [Task Name]
## Goal
What this task accomplishes
## Inputs
- Input 1: Description
- Input 2: Description
## Tools/Scripts
- `execution/script_name.py`: What it does
## Outputs
- Output 1: Description
- Output 2: Description
## Edge Cases
- Edge case 1: How to handle it
- Edge case 2: How to handle it
## Notes
Additional context or considerations- Create a new Python file in
execution/ - Make it deterministic and testable
- Use environment variables from
.env - Return clear success/failure status
- Handle errors gracefully
Example structure:
import os
from dotenv import load_dotenv
load_dotenv()
def main():
# Your deterministic logic here
pass
if __name__ == "__main__":
main()The AI orchestrator will:
- Read the relevant directive
- Determine which execution scripts to run
- Execute them in the correct order
- Handle errors and update directives as needed
- Deliverables: Cloud-based outputs (Google Sheets, Slides, etc.)
- Intermediates: Temporary files in
.tmp/(can be deleted and regenerated)
When errors occur:
- Read the error message and stack trace
- Fix the script and test again
- Update the directive with learnings
- System becomes stronger over time
Directives are living documents. When you discover:
- API constraints or rate limits
- Better approaches
- Common errors
- Timing expectations
Update the directive so future runs benefit from this knowledge.
- Check for tools first: Before creating a new script, check if one already exists
- Keep execution deterministic: No LLM calls in execution scripts
- Use intermediate files wisely: Everything in
.tmp/should be regenerable - Document learnings: Update directives when you discover edge cases
- Test scripts independently: Each script in
execution/should be testable on its own
When adding new functionality:
- Create or update the directive first
- Write or modify the execution script
- Test thoroughly
- Update documentation
[Add your license here]