Skip to main content

A context-graph framework for building production-ready AI applications.

Project description

KayGraph

An opinionated framework for building context-aware AI applications with production-ready graphs.

PyPI version License: MIT Python

What is KayGraph?

KayGraph provides powerful abstractions for orchestrating complex AI workflows through Context Graphs - a pattern that seamlessly integrates operations, LLM calls, and state management into production-ready applications.

Core Philosophy

  • Context-Aware Graphs: Build sophisticated AI systems where every node has access to shared context
  • Opinionated Patterns: Production-tested patterns for common AI workflows
  • Zero Dependencies: Pure Python implementation with no external dependencies
  • Bring Your Own Tools: Integrate any LLM, database, or service you prefer

Installation

Using uv (Recommended)

uv is a fast Python package manager that provides better dependency resolution and faster installations:

# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh

# Install KayGraph
uv pip install kaygraph

# Or install from source with development dependencies
git clone https://github.com/KayOS-AI/KayGraph.git
cd KayGraph/kaygraph-library
uv pip install -e ".[dev]"

Using pip

pip install kaygraph

Or install from source:

git clone https://github.com/KayOS-AI/KayGraph.git
cd KayGraph/kaygraph-library
pip install -e .

Quick Start

🚀 Scaffold a New Project

Use our zero-dependency scaffolding tool to generate production-ready boilerplate:

# Generate a basic node pattern
python scripts/kaygraph_scaffold.py node DataProcessor

# Generate an interactive chat application
python scripts/kaygraph_scaffold.py chat CustomerSupport

# Generate a supervisor-worker pattern
python scripts/kaygraph_scaffold.py supervisor TaskManager

# See all available templates
python scripts/kaygraph_scaffold.py --help

📝 Write Your First Graph

from kaygraph import Node, Graph

# Define a simple node
class AnalyzeNode(Node):
    def prep(self, shared):
        # Read from shared context
        return shared.get("input_text")

    def exec(self, text):
        # Process data (e.g., LLM call)
        return analyze_sentiment(text)

    def post(self, shared, prep_res, exec_res):
        # Write to shared context
        shared["sentiment"] = exec_res
        return "complete"  # Next action

# Create and run a graph
analyze = AnalyzeNode("analyzer")
graph = Graph(analyze)

shared = {"input_text": "KayGraph makes AI development intuitive!"}
graph.run(shared)
print(shared["sentiment"])  # Output: "positive"

Key Features

🏗️ Core Abstractions

  • Node: Atomic unit of work with 3-phase lifecycle (prep → exec → post)
  • Graph: Orchestrates node execution through labeled actions
  • Shared Store: Context-aware state management across nodes

🎯 Production Patterns

  • Agent: Autonomous decision-making systems
  • RAG: Retrieval-augmented generation pipelines
  • Workflows: Multi-step task orchestration
  • Batch Processing: Efficient data processing at scale
  • Async Operations: Non-blocking I/O operations

🚀 Enterprise Features

  • ValidatedNode: Input/output validation
  • MetricsNode: Performance monitoring
  • Comprehensive Logging: Built-in debugging support
  • Error Handling: Graceful failure recovery
  • Resource Management: Context managers for cleanup

Examples & Workbooks

Explore 71 production-ready examples in the workbooks/ directory:

  • Quick Start: kaygraph-hello-world, kaygraph-workflow, kaygraph-chat
  • AI Agents: kaygraph-agent, kaygraph-multi-agent, kaygraph-agent-tools
  • RAG Systems: kaygraph-rag, kaygraph-text2sql, kaygraph-tool-embeddings
  • Production: kaygraph-production-ready-api, kaygraph-realtime-monitoring

See workbooks/QUICK_FINDER.md for task-based navigation or workbooks/guides/WORKBOOK_INDEX.md for the complete catalog.

Documentation

Core Concepts

Common Patterns

Advanced Topics

Development with AI Assistants

KayGraph is designed for Agentic Coding - where humans design and AI agents implement.

Generate Cursor Rules

# Generate AI coding assistant rules from documentation
python utils/update_kaygraph_mdc.py

This creates .cursor/rules/ with context-aware guidance for AI assistants.

Project Structure

kaygraph-library/
├── kaygraph/          # Core framework
│   └── __init__.py    # All abstractions in one file
├── docs/              # Comprehensive documentation
├── tests/             # Unit tests
├── utils/             # Helper scripts
└── .cursor/rules/     # AI assistant guidance

Contributing

We welcome contributions! Please see our Contributing Guide for details.

License

MIT License - see LICENSE for details.


Built with ❤️ by the KayOS Team

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

kaygraph-0.3.0.tar.gz (1.8 MB view details)

Uploaded Source

Built Distribution

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

kaygraph-0.3.0-py3-none-any.whl (65.3 kB view details)

Uploaded Python 3

File details

Details for the file kaygraph-0.3.0.tar.gz.

File metadata

  • Download URL: kaygraph-0.3.0.tar.gz
  • Upload date:
  • Size: 1.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.10

File hashes

Hashes for kaygraph-0.3.0.tar.gz
Algorithm Hash digest
SHA256 54b225c4a33839220ff18e639b3b8261e05f4d2886db0e7524a8d7834465a673
MD5 2f35531320a0b6c7a22d9a58ebd50112
BLAKE2b-256 bea311439fdc6ff127036625dffbc6d0e49ca65cc31089ea72b4eb9585b3cdf2

See more details on using hashes here.

File details

Details for the file kaygraph-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: kaygraph-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 65.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.10

File hashes

Hashes for kaygraph-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b1505d48a7ebe549b5278ca27bc4bd308c2c8025fa993ddd153b0f0ef41ee07a
MD5 11e6520ca79685309769fa4445632fbb
BLAKE2b-256 5173b1ab5337e7bccd626825398e56458f889c94a6cd8648e93119fba78948ed

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