Build production AI agents with modular architecture, advanced prompt engineering, and framework-agnostic design (LangGraph/Pydantic-AI)
Project description
GridCode Runtime (GCR)
Modular Agentic Architecture (MAA) - An Open-Source Agent Runtime System
Overview
GridCode Runtime is an open-source, modular, production-ready agent runtime system inspired by Claude Code's prompt engineering patterns. It provides a unified framework for building intelligent agents with support for multiple AI frameworks (LangGraph, Pydantic-AI).
Key Design Goals:
- Framework-agnostic architecture supporting LangGraph and Pydantic-AI
- Production-ready features: state persistence, monitoring, human-in-the-loop
- Claude Code-inspired patterns: 5-phase planning, context-aware reminders, progressive prompt composition
๐ ไธญๆๆๆกฃ: GridCode Runtime ไธญๆๆๆกฃ
โจ Key Features
๐ฏ Core Capabilities
- Advanced Prompt System: 100+ reusable prompt templates with 4-type variable injection (
${VAR},${context.prop},${COND ? "A" : "B"},${FUNC()}) - Framework Agnostic: Nexus Agent Engine with Strategy+Adapter patterns supporting LangGraph and Pydantic-AI
- Multi-Agent Architecture: 10 specialized agents (Main, Explore, Plan, Review, TestRunner, Architect, CodeReviewer, Debugger, DocsArchitect, APIDocumenter, TutorialEngineer)
- 5-Phase Planning Workflow: Understanding โ Exploration โ Planning โ Review โ Ready
- Context-Aware System Reminders: 18+ dynamic system hints with 5 Learning Mode reminders
- Learning Mode: Continuous improvement with FeedbackRecord, pattern analysis, and knowledge accumulation
- Plugin System: 5 plugin types with 10+ hook events and auto-discovery
๐ Production Features
- State Persistence: SQLite-based checkpoints with ExecutionContext management
- Human-in-the-Loop: ConsoleInteractionHandler with approval workflows
- Tool Result Enhancement: Automatic guidance injection via ToolResultEnhancer
- Layered Permissions: Agent-specific tool whitelists/blacklists (main/explore/plan/review)
- MCP Integration: Multi-server support with stdio/HTTP transports and connection pooling
- Configuration System: YAML/environment/CLI with validation and templates
Architecture
GridCode Runtime adopts a three-layer architecture with clear separation of concerns:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Layer 3: Orchestration โ
โ - GridCodeRuntime: Main runtime coordinator โ
โ - PlanModeManager: 5-phase planning workflow โ
โ - LearningModeManager: Learning mode & feedback system โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Layer 2: Execution โ
โ โโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Nexus Agent Engine โ โ Prompt Composer โ โ
โ โ (LangGraph/PAI) โ โ (Template + Variable System) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Agent Pool โ โ Tool Registry โ โ
โ โ (10 Specialized) โ โ (Read/Write/Edit/Glob/Grep) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Layer 1: Foundation โ
โ - ExecutionContext: State management (session/agent/tool) โ
โ - SQLiteStorage: Context persistence โ
โ - PluginManager: Plugin system & hook registry โ
โ - MCPClient: MCP server integration โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Quick Start
Installation
# Install core package
pip install gridcode-runtime
# Install with LangGraph support
pip install gridcode-runtime[langgraph]
# Install with Pydantic-AI support
pip install gridcode-runtime[pydantic-ai]
# Install all dependencies (including dev tools)
pip install gridcode-runtime[all]
Basic Usage
import asyncio
from gridcode.core import GridCodeRuntime, ExecutionContext
async def main():
# Create runtime with LangGraph adapter
runtime = GridCodeRuntime(
api_key="your-anthropic-api-key",
framework="langgraph" # or "pydantic-ai"
)
# Setup execution context
context = ExecutionContext(
session_id="demo-session",
working_dir="/path/to/project"
)
# Run agent with simple prompt
result = await runtime.run(
prompt="Analyze this project's code structure",
context=context
)
print(result.content)
asyncio.run(main())
CLI Usage
# Run agent with CLI
gridcode run "Analyze code structure" --framework langgraph
# Configure settings
gridcode config set anthropic.api_key "your-api-key"
gridcode config set runtime.framework "langgraph"
# List available plugins
gridcode plugins list
# Get plugin information
gridcode plugins info example-plugin
๐ Advanced Usage
Using Sub-Agents
from gridcode.agents import AgentPool
# Initialize agent pool
pool = AgentPool(
framework="langgraph",
api_key="your-api-key"
)
# Spawn explore agent for read-only codebase exploration
result = await pool.spawn_agent(
agent_type="explore",
task="Find all API endpoint definitions",
context=context
)
# Spawn plan agent for planning without execution
plan = await pool.spawn_agent(
agent_type="plan",
task="Design a new authentication system",
context=context
)
Enabling Learning Mode
from gridcode.workflows import LearningModeManager
# Enable learning mode for continuous improvement
learning_mgr = LearningModeManager(context)
learning_mgr.enable()
# Provide feedback after task completion
learning_mgr.record_feedback(
task_id="task-123",
rating=5,
feedback="Great performance on API analysis"
)
# Get learned patterns
patterns = learning_mgr.get_patterns()
Plugin Development
from gridcode.plugins import Plugin, Hook
class MyPlugin(Plugin):
name = "my-plugin"
version = "1.0.0"
@Hook.on("PreToolUse")
async def before_tool_use(self, tool_name: str, args: dict):
# Custom logic before tool execution
print(f"About to use tool: {tool_name}")
return True # Allow execution
@Hook.on("PostToolUse")
async def after_tool_use(self, tool_name: str, result: any):
# Custom logic after tool execution
print(f"Tool {tool_name} completed")
โ๏ธ Configuration
GridCode can be configured via YAML file, environment variables, or CLI arguments.
Configuration File
Create gridcode.yaml in your project directory:
runtime:
api_provider: anthropic
api_key: ${ANTHROPIC_API_KEY}
model: claude-sonnet-4-5
framework: langgraph
agent_pool:
cache_enabled: true
max_agents: 5
mcp:
enabled: true
servers:
- name: context7
type: stdio
command: npx
args: ["-y", "@context7/mcp-server"]
env:
CONTEXT7_API_KEY: ${CONTEXT7_API_KEY}
plugins:
enabled: true
dirs:
- ~/.gridcode/plugins
- ./plugins
For full configuration options, see gridcode.yaml.template or the Configuration Guide.
Environment Variables
# API Keys
export ANTHROPIC_API_KEY="sk-ant-xxx"
export OPENAI_API_KEY="sk-proj-xxx"
# Optional: Model selection
export OPENAI_MODEL_NAME="gpt-4"
# Optional: MCP servers
export CONTEXT7_API_KEY="c7-xxx"
CLI Options
# Use custom config file
gridcode run --config custom.yaml "Your query"
# Override config with CLI args
gridcode run --model gpt-4 --api-key sk-xxx "Your query"
# Configuration priority: CLI args > Environment variables > Config file > Defaults
๐งช Testing
GridCode has comprehensive test coverage with unit tests, integration tests, and performance benchmarks.
Run Tests
# All tests
pytest
# Unit tests only (fast)
pytest tests/unit/ -v
# Integration tests (with mocked APIs)
pytest tests/integration/ --run-integration
# With coverage
pytest --cov=src --cov-report=term-missing
# Generate HTML coverage report
pytest --cov=src --cov-report=html
open htmlcov/index.html
Test Status
- Total Tests: 822 tests
- Passing: 822 (100%)
- Coverage: 81%
- Test Categories:
- Unit tests: ~697 tests (core logic)
- Integration tests: ~125 tests (E2E scenarios)
For more details, see the Testing Guide.
๐ Documentation
๐๏ธ Architecture & Design
- Architecture Overview - Three-layer system architecture and design patterns
- Nexus Agent Engine - Framework adapter design (Strategy + Adapter patterns)
- Prompt System Design - Template composition and variable resolution
- Plugin System - Extensible plugin architecture with hooks
๐ User Guides
- Quick Start Guide - Get up and running in 5 minutes
- Configuration Guide - Complete configuration reference
- Agent Usage Guide - Working with multi-agent workflows
- CLI Reference - Complete CLI command reference
๐ ๏ธ Developer Guides
- Contributing Guide - How to contribute to the project
- Plugin Development - Creating custom plugins and hooks
- API Reference - Complete API documentation
- Testing Guide - Testing strategies and best practices
๐ Tutorials & Examples
- Basic Usage Tutorial - Step-by-step basic usage
- Advanced Workflows - Complex multi-agent scenarios
- Plugin Examples - Real-world plugin implementations
- Best Practices - Production deployment patterns
Core Design Patterns (from Claude Code)
| Pattern | Description |
|---|---|
| Progressive Prompt Composition | Layer prompts based on task complexity |
| 5-Phase Planning Workflow | Explore โ Design โ Review โ Finalize โ Approve |
| Context-Aware Reminders | Dynamic system hints based on state |
| Layered Tool Permissions | Different capabilities per agent type |
| Tool Result Enhancement | Inject guidance in tool responses |
๐ ๏ธ Tech Stack
| Category | Technologies |
|---|---|
| Runtime | Python 3.11+, asyncio |
| AI Frameworks | LangGraph 0.2+, Pydantic-AI 0.0.13+ |
| LLM Client | Anthropic Claude API (Sonnet 4.5, Opus 4.5) |
| Storage | SQLite (checkpoints), Redis (optional) |
| CLI | Typer, Rich |
| Logging | loguru |
| Testing | pytest, pytest-asyncio, pytest-cov |
| Code Quality | Black, isort, Ruff, mypy |
๐บ๏ธ Roadmap
Phase 1-3: Foundation โ (Complete)
- Prompt Composer with variable resolution
- Nexus Agent Engine (LangGraph + Pydantic-AI adapters)
- Agent Pool (Explore, Plan, Review agents)
- 5-Phase Planning Workflow
- System Reminders (18+ reminder types)
- Context Persistence (SQLite)
Phase 4: Ecosystem โ (Complete)
- Learning Mode with feedback system
- Plugin System with hook registry
- MCP Integration
- Plugin Discovery & Auto-loading
Phase 5: Production โ (Complete)
- CLI Interface (typer-based)
- Performance Optimization (lazy loading, caching)
- Memory Profiling & Leak Detection
- Configuration System (gridcode.yaml)
- Integration Tests (131 E2E tests, 99.3% pass rate)
- Documentation (Configuration Guide, Testing Guide)
Phase 6: Future ๐ฎ (Planned)
- Web UI for agent monitoring
- More framework adapters (AutoGen, CrewAI)
- Distributed agent orchestration
- Cloud deployment support
๐ค Contributing
We welcome contributions! Please see CONTRIBUTING.md for:
- Development environment setup
- Code style guidelines
- Testing requirements
- Pull request process
๐ License
This project is licensed under the MIT License - see LICENSE for details.
๐ Acknowledgments
This project is inspired by Claude Code's prompt engineering patterns. Special thanks to the Anthropic team for their innovative work in agentic AI systems.
๐ง Contact & Support
- Documentation: GridCode Runtime Docs
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- API Reference: Complete API Documentation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gridcode_runtime-0.1.0.tar.gz.
File metadata
- Download URL: gridcode_runtime-0.1.0.tar.gz
- Upload date:
- Size: 156.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32b28da835ea73a6e43f5a29412230e1f31bf0bebdb148154bab7d2acad70341
|
|
| MD5 |
59b18d0d0842f8ea91b3c2724ac1151a
|
|
| BLAKE2b-256 |
30ab050adee34ac87b1b7bdf032c2ac1d013d4650e6a0475925bdd5b86218151
|
File details
Details for the file gridcode_runtime-0.1.0-py3-none-any.whl.
File metadata
- Download URL: gridcode_runtime-0.1.0-py3-none-any.whl
- Upload date:
- Size: 201.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b3cf7ee349c75412faf6ec4aeb414e711daeb6d84384d768fc68af829c3afe1
|
|
| MD5 |
f707982041f5bee21d3b6c6173d4995c
|
|
| BLAKE2b-256 |
2ffa6fe26d45ae20442c6590490c3d7e494a3c14f80afaa35d3251ad392a2240
|