Skip to main content

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

PyPI version Python versions License Tests Coverage Code Style


๐Ÿ“š Complete Documentation | ๅฎŒๆ•ดๆ–‡ๆกฃ๏ผˆไธญๆ–‡๏ผ‰

Quick Links: Quick Start | Alpha Testing | FAQ | API Reference


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 ไธญๆ–‡ๆ–‡ๆกฃ

๐ŸŽฏ Use Cases

GridCode Runtime is ideal for:

  • Multi-Agent Systems - Build complex agent workflows with specialized sub-agents (explore, plan, review)
  • Advanced Prompt Engineering - Leverage 100+ reusable templates with dynamic variable resolution
  • Framework-Agnostic Development - Switch between LangGraph and Pydantic-AI without code changes
  • Production AI Applications - State persistence, monitoring, and human-in-the-loop workflows
  • Plugin Development - Extend functionality with custom plugins and MCP server integration
  • Code Analysis & Generation - Specialized agents for codebase exploration, planning, and review

โœจ 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

# Basic installation (core features only)
pip install gridcode-runtime

# With LangGraph support (recommended for production)
pip install 'gridcode-runtime[langgraph]'

# With Pydantic-AI support
pip install 'gridcode-runtime[pydantic-ai]'

# With all optional dependencies (LangGraph + Pydantic-AI + dev tools)
pip install 'gridcode-runtime[all]'

Optional Dependencies

GridCode Runtime supports multiple agent frameworks through optional dependencies:

Extra Includes Use Case
langgraph LangGraph >= 0.2.0, langchain-core, langchain-anthropic Production multi-agent workflows
pydantic-ai Pydantic-AI >= 0.0.13 Type-safe agent development
all All frameworks + dev tools Development and testing

Note: The core package works without optional dependencies, but framework-specific features require the corresponding extras.

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

๐Ÿ“– Getting Started

๐Ÿ—๏ธ Architecture & Design

๐Ÿ“– User Guides

๐Ÿ› ๏ธ Developer Guides

๐ŸŒ ไธญๆ–‡ๆ–‡ๆกฃ

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gridcode_runtime-0.1.2.tar.gz (156.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gridcode_runtime-0.1.2-py3-none-any.whl (202.4 kB view details)

Uploaded Python 3

File details

Details for the file gridcode_runtime-0.1.2.tar.gz.

File metadata

  • Download URL: gridcode_runtime-0.1.2.tar.gz
  • Upload date:
  • Size: 156.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gridcode_runtime-0.1.2.tar.gz
Algorithm Hash digest
SHA256 ff313450b26d34f836fc7380a9e8cd73744ff4857109bb540ba552d7b1e11576
MD5 c6ccf52ab3e96a5b6451bc18d9410aab
BLAKE2b-256 97f3ed83e77727e6ae25d75089abe3d43dc9783a27809022db562dfda5421f81

See more details on using hashes here.

File details

Details for the file gridcode_runtime-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for gridcode_runtime-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ff41d124923e20b71df36c7bbae77a62febd7725b96afa9b0f32e7ab0dae0f16
MD5 2944ea41b0f9059826e6648a549aabaf
BLAKE2b-256 4c68e43c07003d0c5e11167f6c6756817a7a37d7ec050ed791180d6f4200f3b4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page