Examples
Complete working examples demonstrating Mesh features.
Available Examples
All examples are in the examples/ directory.
Basic Examples
simple_agent.py
Basic LLM usage with token-by-token streaming.
python examples/simple_agent.py
Agent Integration
vel_agent_streaming.py
Vel agent with streaming events.
pip install "mesh[vel]"
python examples/vel_agent_streaming.py
openai_agent_streaming.py
OpenAI Agents SDK with Vel translation.
pip install "mesh[agents]"
python examples/openai_agent_streaming.py
Event Translation
event_translation_comparison.py
Side-by-side comparison of Vel-translated vs native events.
python examples/event_translation_comparison.py
React Flow
react_flow_parse.py
Parse and execute Flowise-compatible React Flow JSON.
python examples/react_flow_parse.py
Server
fastapi_server.py
Complete FastAPI server with SSE streaming.
pip install "mesh[server]"
python examples/fastapi_server.py
# Visit http://localhost:8000/docs
Visualization Examples
Complete examples demonstrating graph visualization with Mermaid diagrams. All examples are in examples/visualization_examples/.
01_cyclic_graph.py
Loop patterns with termination points.
python examples/visualization_examples/01_cyclic_graph.py
02_sequential_workflow.py
Linear pipeline visualization.
python examples/visualization_examples/02_sequential_workflow.py
03_conditional_branching.py
Decision points with diamond-shaped condition nodes.
python examples/visualization_examples/03_conditional_branching.py
04_multi_agent_workflow.py
Multi-stage processing pipeline.
python examples/visualization_examples/04_multi_agent_workflow.py
05_mixed_node_types.py
Color palette showcase - demonstrates all node type colors in one graph.
python examples/visualization_examples/05_mixed_node_types.py
See the Visualization Guide for detailed documentation.
Running Examples
Setup
# 1. Install Mesh
pip install -e ".[all]"
# 2. Configure environment
cp .env.example .env
# Edit .env and add OPENAI_API_KEY
# 3. Run any example
python examples/simple_agent.py
Example Patterns
Pattern: Simple Streaming
async for event in executor.execute("Hello", context):
if event.type == "token":
print(event.content, end="", flush=True)
Pattern: Multi-Node Graph
graph.add_node("analyze", analyzer_agent, node_type="agent")
graph.add_node("process", processor_tool, node_type="tool")
graph.add_node("respond", responder_agent, node_type="agent")
graph.add_edge("START", "analyze")
graph.add_edge("analyze", "process")
graph.add_edge("process", "respond")
Pattern: Conditional Flow
from mesh.nodes import Condition
conditions = [
Condition("positive", check_positive, "positive_handler"),
Condition("negative", check_negative, "negative_handler"),
]
graph.add_node("router", conditions, node_type="condition")
See Also
- Quick Start Guide - Build your first graph
- Guides - Detailed usage guides
- API Reference - Complete API documentation