25
Graph & JoinsGraph Edges
Create typed, directional edges between agents to model relationships.
Prerequisite: Lesson 4 complete
What you'll learn
- ✓POST /v1/graph/edges — from_agent, to_agent, edge_type, meta
- ✓GET /v1/graph/edges?from=users — outbound edges
- ✓GET /v1/graph/edges?to=orders — inbound edges
- ✓DELETE /v1/graph/edges/:from/:to/:type — remove edge
- ✓Graph layer vs strand records — two separate stores
Challenge
Model: company → departments → employees → time_entries. Create the three edges. List to confirm.
Interactive Walkthrough
What you'll learn
Create typed, directional edges between agents, and query connected agents.
What graph edges are for
Agents are nodes. Edges express relationships:
- users → orders (a user has orders)
- orders → payments (an order has payments)
- users → sessions (a user has sessions)
These are structural links stored in the graph layer — separate from the strand records.
Create an edge
curl -s -X POST http://localhost:7475/v1/graph/edges \
-H "Content-Type: application/json" \
-H "Authorization: Bearer spx_root_YOUR_ROOT_KEY" \
-d '{
"from_agent": "users",
"to_agent": "orders",
"edge_type": "has_orders",
"meta": {"established": "2026-07-09"}
}' | python3 -m json.toolList edges from an agent
curl -s "http://localhost:7475/v1/graph/edges?from=users" \
-H "Authorization: Bearer spx_root_YOUR_ROOT_KEY" \
| python3 -m json.toolList edges to an agent
curl -s "http://localhost:7475/v1/graph/edges?to=orders" \
-H "Authorization: Bearer spx_root_YOUR_ROOT_KEY" \
| python3 -m json.toolDelete an edge
curl -s -X DELETE "http://localhost:7475/v1/graph/edges/users/orders/has_orders" \
-H "Authorization: Bearer spx_root_YOUR_ROOT_KEY"Challenge
Model this graph: company → departments → employees → time_entries. Create the three edges. List them to confirm the structure.
---