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.
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
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
graph = Graph()
analyze = AnalyzeNode("analyzer")
graph.add_node(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
Documentation
Core Concepts
- Node Design - Understanding the 3-phase lifecycle
- Graph Orchestration - Connecting nodes with actions
- Shared Store - Managing shared context
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
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 kaygraph-0.0.1.tar.gz.
File metadata
- Download URL: kaygraph-0.0.1.tar.gz
- Upload date:
- Size: 534.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
25fc9b04ec358309362eaaed4f8d8ab9f33e55bb781992e615ec51256563d0bb
|
|
| MD5 |
d93f301e0587ee9f83525a2fe572c08c
|
|
| BLAKE2b-256 |
161120e675694538f27d490ec313c0ab5ea0af9228d120ba0786a977ae17a3a4
|
File details
Details for the file kaygraph-0.0.1-py3-none-any.whl.
File metadata
- Download URL: kaygraph-0.0.1-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e87417464252c5f7619c889f63006c8ae627798486064ff1fcf6fe8ec4f89932
|
|
| MD5 |
feac376991ad714d7a8338c47eefa05b
|
|
| BLAKE2b-256 |
ff9f05387773fea2d5f12a90f4097cce18cec9e744e1a40393649a367d490f0c
|