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.2.0.tar.gz (1.5 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.2.0-py3-none-any.whl (23.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kaygraph-0.2.0.tar.gz
  • Upload date:
  • Size: 1.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for kaygraph-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8a8fc04873280d902f8b40773c0d10a095df6847b9d025372e6c5ed97f418a05
MD5 6030cd0281ec0243ab253adc0a2d84cd
BLAKE2b-256 1ca2ffd736d9ea30fce7032d887768eaf1b5403afd252c9d5b2da45596387449

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kaygraph-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 23.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for kaygraph-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 729e87e1e37bfb91755bac2889bf41ce20f08e1b1b9286bec01fc52f1d3d2497
MD5 2df3f3e440be07f712bb7e9461469c83
BLAKE2b-256 defa0ff793beee838b50348449d6ffd3b78fc73a0e2aaf2cba2004780cbbde02

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