← All lessons/Graph & Joins
26
Graph & Joins

Graph Traversal

Walk the graph from one agent to connected agents, and reference specific records across agents.

Prerequisite: Lesson 25 complete

What you'll learn

  • GET /v1/graph/traverse?from=users&depth=2 — agents reachable within N hops
  • Record-level edges: from_record and to_record hash fields
  • Use case: link a specific user record to a specific order record
  • Traversal response includes edge types and path
  • Combining graph traversal with strand reads
Challenge

Create 3 user records and 3 order records. Link each via graph edges. Traverse to find all orders for a specific user.

Interactive Walkthrough

What you'll learn

Walk the graph from one agent to connected agents, and reference records across agents.

Traverse from a node

curl -s "http://localhost:7475/v1/graph/traverse?from=users&depth=2" \
  -H "Authorization: Bearer spx_root_YOUR_ROOT_KEY" \
  | python3 -m json.tool

Response shows agents reachable from users within 2 hops, with edge types.

Record references in graph

You can attach a specific record hash to an edge — linking a user record to an order record:

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":     "placed",
    "from_record":   "usr_hash_b3a7c2...",
    "to_record":     "order_hash_9d2e4f...",
    "meta": {"amount": 299.99}
  }' | python3 -m json.tool

This creates a record-level link — a specific user to a specific order.

Challenge

Create 3 user records and 3 order records. Link each user record to its order record via graph edges. Then traverse to find all orders for a specific user.

---

← Previous
Lesson 25: Graph Edges
Next →
Lesson 27: Multi-Agent Joins