MAgPIE AI Documentation System
Comprehensive, AI-optimized documentation for the MAgPIE land-use model. Works with any AI assistant.
project/CURRENT_STATE.json
Working on documentation project? Read these in order:
- This file (you're reading it!) - Setup & orientation
project/CURRENT_STATE.json- Single source of truth (status, plans, history)- Ask user: "What should I work on?"
🚨 CRITICAL: When working on the project, update ONLY project/CURRENT_STATE.json 🚨
- DO NOT update README.md, AGENT.md, or any other file with project status
- ALL project information goes in the JSON (status, plans, handoffs, next steps)
Using MAgPIE with an AI assistant? Configure your AI to read AGENT.md which contains all instructions for answering MAgPIE questions.
cd /path/to/your/magpie/
git clone git@github.com:mscrawford/magpie-agent.git magpie-agentYour AI assistant needs AGENT.md in the working directory (the MAgPIE root) to read it.
cd /path/to/your/magpie/
cp magpie-agent/AGENT.md AGENT.mdPoint your AI tool to read AGENT.md at session start. Tool-specific instructions:
Claude Code: Add AGENT.md to your project context or workspace settings.
GitHub Copilot: Point to AGENT.md in your workspace configuration.
Cursor: Add AGENT.md to your AI context settings.
Other tools: Consult your tool's documentation for providing context files.
# You should now have:
ls -la AGENT.md # ← In MAgPIE root
ls -la magpie-agent/ # ← Full documentation repoNow your AI assistant will use the comprehensive documentation when working with MAgPIE! 🎉
👉 For current progress numbers, check project/CURRENT_STATE.json 👈
Phase 0 - Foundation (~70,000 words) ✅
- Model architecture, execution flow, folder structure
- 173 dependencies mapped, 26 circular cycles identified
- 172 input files cataloged with sources
Phase 1 - Modules (~20,000+ lines) ✅
- All 46 modules documented with verified equations
- Complete parameter descriptions
- Interface variables and dependencies mapped
Phase 2 - Cross-Module Analysis (~5,400 lines) ✅
- 5 conservation laws (land, water, carbon, nitrogen, food)
- Safety protocols for high-risk modifications
- Circular dependency resolution mechanisms
Total: ~95,000 words / ~25,000+ lines of verified documentation
See project/CURRENT_STATE.json → current_initiative for active projects
magpie-agent/
├── README.md ← You are here (project overview)
├── AGENT.md ← AI agent instructions (SOURCE - edit here)
│
├── agent/ ← AGENT COMMANDS
│ └── commands/ ← Command definitions (guide, update, feedback, etc.)
│
├── project/ ← PROJECT MANAGEMENT (maintainers only)
│ ├── README.md ← What's in this folder
│ └── CURRENT_STATE.json ← EVERYTHING (status, plans, history)
│
├── modules/ ← Phase 1: Module Docs (46 files) ✅
│ ├── module_09.md Drivers
│ ├── module_10.md Land (critical hub)
│ └── ... (all 46 modules documented)
│
├── cross_module/ ← Phase 2: System Analysis (6 files) ✅
│ ├── land_balance_conservation.md
│ ├── water_balance_conservation.md
│ ├── carbon_balance_conservation.md
│ ├── nitrogen_food_balance.md
│ ├── modification_safety_guide.md
│ └── circular_dependency_resolution.md
│
├── core_docs/ ← Phase 0: Foundation (4 files) ✅
│ ├── Core_Architecture.md
│ ├── Module_Dependencies.md
│ ├── Data_Flow.md
│ └── Tool_Usage_Patterns.md
│
├── reference/ ← GAMS Programming (6 files)
│ ├── GAMS_Phase1_Fundamentals.md
│ ├── GAMS_Phase2_Control_Structures.md
│ ├── GAMS_Phase3_Advanced_Features.md
│ ├── GAMS_Phase4_Functions_Operations.md
│ ├── GAMS_Phase5_MAgPIE_Patterns.md
│ └── GAMS_Phase6_Best_Practices.md
│
├── feedback/ ← User Feedback System
│ ├── README.md System overview
│ ├── global/agent_lessons.md
│ └── integrated/ Archived feedback
│
└── archive/ ← Historical session logs
When analyzing MAgPIE, describe ONLY what is actually implemented in the code.
- ✅ DO: Describe actual equations, parameters, and module implementations
- ❌ DON'T: Add ecological or economic reality, suggest improvements, or describe ideal features
- 📖 Read:
reference/Code_Truth_Principles.mdbefore any analysis
This ensures any AI assistant can pick up the project instantly and maintain quality standards.
Step 1: Orient (2 minutes)
- Read this README (you're doing it!)
- Check
project/CURRENT_STATE.jsonfor:- Current progress (what's completed)
- Known issues (problems to avoid)
- Priorities (what to work on next)
- Current initiative (active multi-session project)
- Ask user: "What should I work on?"
Step 2: Choose Your Path
Path A: Documentation Project Work
- Update
project/CURRENT_STATE.json(the ONLY file you modify - contains status, plans, history) - Check
current_initiativeandphase_3sections in the JSON for active work
Path B: MAgPIE Question Support
- Follow instructions in
AGENT.md(AI agent workflow) - Check AI docs FIRST before reading GAMS code
- Use feedback system to improve documentation
Path C: Module Documentation
- Read
reference/Verification_Protocol.md - Follow verification checklist
- Update ONLY
project/CURRENT_STATE.jsonfor status
The Golden Rule: CODE TRUTH
Describe ONLY what IS implemented in the code.
Always ask yourself: "Where is this in the code? What file and line?"
Mandatory Citation Format
Every factual claim MUST cite source:
- ✅
equations.gms:45orequations.gms:45-52 - ✅
presolve.gms:123 - ✅
input.gms:67
Use Exact Variable Names
- ✅
vm_land(j,land)- correct - ❌ "the land variable" - wrong
- ✅
pm_carbon_density(t,j,land,c_pools)- correct - ❌ "carbon density parameter" - wrong
State Limitations Explicitly
- ✅ "Does NOT model fire dynamics"
- ✅ "Climate impacts are parameterized, not dynamically modeled"
- ✅ "Uses uniform BII factors globally"
Distinguish Examples from Data
When providing numerical examples:
✅ CORRECT - Clearly labeled as illustrative:
To illustrate, consider a **hypothetical cell**:
- Available water: 100 km³ (made-up number for illustration)
- Environmental flows: 40 km³ (example value)
*Note: These are made-up numbers for pedagogical purposes.
Actual values require reading input file lpj_airrig.cs2*❌ WRONG - Implies actual data:
In Punjab region:
- Available water: 100 km³
- Environmental flows: 40 km³Verify Arithmetic
If you provide calculations, double-check the math:
- ✅ 100 km³ × 50% = 50 km³ (correct)
- ❌ 100 km³ × 50% = 30 km³ (wrong - rejected)
Step 1: Update State (5 minutes) - CRITICAL
🚨 ONLY UPDATE project/CURRENT_STATE.json - DO NOT UPDATE ANY OTHER FILES WITH STATUS 🚨
Update project/CURRENT_STATE.json with:
- Work completed (what you finished)
- New issues found (problems discovered)
- Recommended priorities for next session
- Last session accomplishments
- Update progress counters if applicable
DO NOT UPDATE:
- README.md (this file - static reference)
- AGENT.md (agent instructions - only update for new workflows)
- modules/README.md (static reference)
Step 2: Archive Session Files (1 minute)
Move dated log files to archive:
mv *_2025-10-*.md archive/Keep root clean!
Step 3: Create Lightweight Handover (50 lines MAX)
DO NOT duplicate information from project/CURRENT_STATE.json
DO include:
- What was accomplished (bullet points)
- What failed (if anything)
- Recommended next steps (3-5 items)
- Any new lessons learned
Before finishing ANY module, verify:
- Cited file:line for every factual claim
- Used exact variable names (vm_land, not "land variable")
- Verified feature exists (grep'd for it or read the file)
- Described CODE behavior only (not ecological/economic theory)
- Labeled examples (made-up numbers vs. actual input data)
- Checked arithmetic (if providing calculations)
- Listed dependencies (if suggesting modifications)
- Stated limitations (what code does NOT do)
- No vague language ("the model handles..." → specific equation)
- Updated CURRENT_STATE.json
If you can't check all boxes, your response needs more verification.
- Read this README (2 min)
- Check
project/CURRENT_STATE.json(1 min) - If active initiative exists, read that plan document (5 min)
- Ask user what to work on
- Model Overview:
core_docs/Core_Architecture.md - Specific Module:
modules/module_XX.md - Module Interactions:
core_docs/Module_Dependencies.md - Data Sources:
core_docs/Data_Flow.md
- Read target module documentation in
modules/ - Always check dependencies in
core_docs/Module_Dependencies.md - Verify interface variables in source code
- Follow "Common Modifications" section in module doc
- Test affected downstream modules
- Query routing:
AGENT.md(Advanced Query Patterns section) - Response patterns: Module-specific sections in each
module_XX.md - Quality standards: This README (Quality Checklist section)
- Verification:
reference/Verification_Protocol.md
# Count documented modules
ls -1 modules/module_*.md | wc -l
# Check project status
cat CURRENT_STATE.json
# Verify equation count for module XX
grep "^[ ]*qXX_" ../modules/XX_*/*/declarations.gms | wc -l
# List all modules
ls ../modules/
# Archive dated session files
mv *_2025-10-*.md archive/Available in core_docs/phase2_dependency_analysis/:
core_dependencies.dot- Top 20 modulesdegradation_system.dot- Degradation subsystemforestry_system.dot- Forestry/timber systemfull_dependencies.dot- All 46 modules
Generate PNG:
cd core_docs/phase2_dependency_analysis
dot -Tpng core_dependencies.dot -o core_dependencies.pngdependency_report.txt- Complete 46×46 dependency matrixdependency_analysis.json- Machine-readable dependenciesdetailed_module_analysis.txt- Deep dive into hub modules
🚨 project/CURRENT_STATE.json IS THE ONLY FILE YOU MODIFY FOR PROJECT WORK 🚨
This file contains EVERYTHING:
- ✅ Current status and progress
- ✅ All session accomplishments (no separate handoff docs!)
- ✅ Future plans and priorities (no separate plan docs!)
- ✅ Phase 3 task details
- ✅ Next steps
NEVER UPDATE THESE FILES WITH PROJECT STATUS:
- ❌ This README (static reference - DO NOT TOUCH)
- ❌ AGENT.md (AI instructions - DO NOT TOUCH)
- ❌ project/README.md (static reference - DO NOT TOUCH)
- ❌ modules/README.md (static overview - DO NOT TOUCH)
- ❌ NO HANDOFF DOCUMENTS - everything goes in CURRENT_STATE.json
- ❌ NO PLAN DOCUMENTS - everything goes in CURRENT_STATE.json
After EVERY session:
- Update
project/CURRENT_STATE.jsonwith ALL progress/plans/status - Archive dated log files if any (usually none needed - use the JSON!)
- DO NOT update status in README, AGENT.md, or create handoff docs
MAgPIE developers can improve agent performance through feedback!
- Say "run command: feedback" for complete system overview
- Submit feedback about agent behavior, documentation errors, or suggestions
- Review and compress integrated feedback with
command: compress-documentation
See feedback/README.md for details.
Problem: Can't find equation
- Solution: Check
declarations.gmswith grep:grep "^[ ]*qXX_" modules/XX_*/*/declarations.gms
Problem: Wrong equation count
- Solution: Recount with grep (see command above)
Problem: Unknown interface variable
- Solution: Check
core_docs/Module_Dependencies.mdfor provider module
Problem: Not sure what to work on
- Solution: Check
project/CURRENT_STATE.json→prioritiessection
Problem: Equation formula doesn't match source
- Solution: Mark module as needing verification, document the discrepancy
Problem: Need to understand agent workflow
- Solution: Read
AGENT.mdfor complete AI instructions
Problem: File paths or tool usage issues
- Solution: Check
core_docs/Tool_Usage_Patterns.md
- 100% Code Truth: Describe only what IS implemented
- Complete Coverage: All 46 modules documented
- Full Verification: Every equation, formula, parameter checked
- AI-Optimized: Easy for any AI assistant to understand and use
- Maintainable: Clear structure, version control, protocols
Cost: 2 hours wasted when fresh attempt had 10+ critical errors
Lesson: Read source files FIRST, verify EVERY equation, THEN write
Method:
- Count equations:
grep "^[ ]*qXX_" declarations.gms | wc -l - Verify 2-3 equation names
- Check 1-2 interface variables
- Confirm limitations stated
Lesson: 5 min/module for high-confidence check
Pattern:
- 40+ citations = likely good
- 60+ citations = very good
- <20 citations = suspicious, needs review
Lesson: Citation count is a quick quality proxy
Lesson: Don't waste time trying to fix fundamentally flawed documentation
You are a key part of trying to improve the MAgPIE model and address the crises of climate change and unsustainable land-use. Thank you!
Goal: Make it effortless for the next AI session (or yourself tomorrow) to pick up instantly.
How:
- Keep
project/CURRENT_STATE.jsoncurrent - Archive dated files immediately
- Use the quality checklist
- Follow Code Truth principles
If future AI is confused: This protocol needs improvement → submit feedback!
Purpose: Enable any AI to effectively work with MAgPIE without prior knowledge
Principle: Code Truth - Describe only what IS implemented in the code
This is a STATIC reference document. For current project status, see project/CURRENT_STATE.json