Cortex Examples
This directory contains examples demonstrating how to use Cortex in various scenarios.
Examples
Quick Start
Before running these examples, ensure Cortex is installed:
# Resolve the current release and this platform
VERSION=$(curl -sI https://github.com/petal-labs/cortex/releases/latest | awk -F'/v' '/^[Ll]ocation:/ {print $2}' | tr -d '\r')
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
[ "$ARCH" = "x86_64" ] && ARCH=amd64
[ "$ARCH" = "aarch64" ] && ARCH=arm64
curl -LO "https://github.com/petal-labs/cortex/releases/latest/download/cortex_${VERSION}_${OS}_${ARCH}.tar.gz"
tar -xzf "cortex_${VERSION}_${OS}_${ARCH}.tar.gz"
sudo mv "cortex_${VERSION}_${OS}_${ARCH}/cortex" /usr/local/bin/
# Verify installation
cortex --version
Use Cases
Personal Knowledge Base
Store and search your notes, documents, and research:
cortex knowledge ingest --collection notes --title "Meeting Notes" --file notes.md
cortex knowledge search "action items from last meeting"
Agent Memory
Give AI agents persistent memory across sessions:
# Start MCP server for your agent
cortex serve --namespace my-agent
Development Context
Track project state and context across coding sessions:
cortex context set "current_task" "implementing user auth"
cortex context set "project_status" '{"phase": "development", "sprint": 3}'
AI Agent Workflows with PetalFlow
Build sophisticated multi-agent workflows using PetalFlow:
// Use the Agent/Task schema for declarative workflows
wf, _ := agent.LoadFromFile("research_workflow.json")
graphDef, _ := agent.Compile(wf)
graph, _ := hydrate.Hydrate(graphDef, opts)
// Or build graphs programmatically
builder := petalflow.NewGraphBuilder("qa-workflow")
builder.AddNode(searchNode)
builder.Edge(prepareNode)
builder.Edge(generateNode)
graph, _ := builder.Build()
See the petalflow-research-agent and petalflow-graph examples for complete implementations.