Examples Overview
Welcome to the Syntha examples! These working code samples demonstrate every feature and concept in Syntha. Each example is ready to copy, paste, and run.
Getting Started
All examples are located in the /examples
directory and are organized by concept. Each example includes:
- Clear documentation explaining what it demonstrates
- Working code that you can run immediately
- Real-world scenarios showing practical applications
- Best practices and common patterns
Example Categories
🧩 Context Mesh
Learn the core context sharing system:
-
Basic Usage - Creating and using a Context Mesh
-
Topic Routing - Topic-based context distribution
-
User Isolation - Multi-user context separation
🔧 Tools & Tool Handler
Master agent-context interaction:
-
Tool Basics - Using ToolHandler for context operations
-
Access Control - Role-based permissions and restrictions
-
Multi-Agent Setup - Coordinating multiple agents
🔌 Framework Adapters
Integrate with your LLM framework:
-
OpenAI Integration - Using Syntha with OpenAI's API
-
Anthropic Integration - Using Syntha with Claude
-
LangChain Integration - Building LangChain agents with Syntha
-
Agno Integration - Flexible multi-agent coordination
📝 Prompts
Build context-aware prompts:
-
System Prompts - Automatic context-aware prompts
-
Context Injection - Custom prompt templates
💾 Persistence
Configure database storage:
-
SQLite Setup - Local development with SQLite
-
PostgreSQL Setup - Production setup with PostgreSQL
🚀 Complete Examples
End-to-end real-world scenarios:
-
Complete Workflows - Full product launch workflow
-
Real-World Use Cases - Industry-specific applications
Quick Start Examples
5-Minute Setup
from syntha import ContextMesh, ToolHandler
# Create context mesh
context = ContextMesh(user_id="demo")
# Add some context
context.push("project", "AI Assistant")
context.push("status", "active")
# Create agent handler
handler = ToolHandler(context, "DemoAgent")
# Agent retrieves context
result = handler.handle_tool_call("get_context")
print(f"Context: {result['context']}")
Multi-Agent Communication
from syntha import ContextMesh, ToolHandler
context = ContextMesh(user_id="team")
# Create multiple agents
sales = ToolHandler(context, "SalesAgent")
support = ToolHandler(context, "SupportAgent")
# Sales agent shares information
sales.handle_tool_call(
"push_context",
key="customer_info",
value={"name": "Acme Corp", "tier": "Enterprise"},
subscribers=["SupportAgent"]
)
# Support agent gets the information
result = support.handle_tool_call("get_context")
print(f"Support sees: {list(result['context'].keys())}")
Framework Integration
from syntha import ContextMesh, ToolHandler, build_system_prompt
context = ContextMesh(user_id="user123")
handler = ToolHandler(context, "AssistantAgent")
# Add business context
context.push("company", "TechCorp")
context.push("role", "Customer Success Manager")
# Get LLM-ready components
system_prompt = build_system_prompt("AssistantAgent", context)
tools = handler.get_schemas() # OpenAI format
langchain_tools = handler.get_langchain_tools() # LangChain format
print("Ready for your LLM framework!")
Running Examples
Prerequisites
# Install Syntha
pip install syntha
# For framework examples, install additional packages:
pip install openai anthropic langchain langchain-openai agno
# Set API keys (for framework examples)
export OPENAI_API_KEY="your-openai-key"
export ANTHROPIC_API_KEY="your-anthropic-key"
Running Individual Examples
# Navigate to the examples directory
cd examples
# Run any example
python context-mesh/basic_usage.py
python tools/tool_basics.py
python adapters/openai.py
Running All Examples
Example Structure
Each example follows a consistent structure:
"""
Category - Example Name
Brief description of what this example demonstrates.
Prerequisites:
- Any required packages or setup
Copy and run this code to see [feature] in action!
"""
from syntha import ContextMesh, ToolHandler
def main():
print("🚀 Example Name")
print("=" * 40)
# 1. Setup
# Clear setup code
# 2. Demonstration
# Working example code
# 3. Results
# Show what happened
print("\n✅ Example complete!")
if __name__ == "__main__":
main()
Best Practices Shown
The examples demonstrate these best practices:
Context Organization
- Use descriptive context keys
- Structure data consistently
- Apply appropriate access control
- Leverage topic-based routing
Agent Coordination
- Set up clear topic subscriptions
- Use role-based access control
- Handle errors gracefully
- Monitor context flow
Framework Integration
- Get native tool formats
- Build context-aware prompts
- Handle tool call responses
- Integrate with existing workflows
Production Readiness
- Use persistent storage
- Implement user isolation
- Configure appropriate backends
- Monitor performance
Troubleshooting Examples
If an example doesn't work:
- Check Prerequisites: Ensure all required packages are installed
- Verify API Keys: Make sure environment variables are set correctly
- Check Python Version: Syntha requires Python 3.9+
- Database Issues: For persistence examples, verify database connectivity
Contributing Examples
Want to add an example? See our Contributing Guide for:
- Example structure guidelines
- Code style requirements
- Documentation standards
- Testing procedures
Next Steps
- User Guide - Learn the concepts
- API Reference - Complete API documentation
- Setup Guide - Production deployment