← All lessons/Graph & Joins
25
Graph & Joins

Graph 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: - usersorders (a user has orders) - orderspayments (an order has payments) - userssessions (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.tool

List 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.tool

List 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.tool

Delete 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: companydepartmentsemployeestime_entries. Create the three edges. List them to confirm the structure.

---

← Previous
Lesson 24: Chain Verification
Next →
Lesson 26: Graph Traversal