Programming Fundamentals · Trees & Graphs: AI's Home Turf

Graphs: From Knowledge Graphs to Multi-Agent Collaboration

Last lesson’s trees were well-behaved: one parent each, never a cycle. Real-world relations are messier—friends are friends with each other; companies, schools, and people tangle. Tear up “one parent only,” and a tree upgrades to a graph: nodes + relations, wire them however you like. This lesson covers graph’s two home turfs in AI.

Home turf 1 · knowledge graph: click once, watch knowledge spread

Below is a mini knowledge graph: dots are entities (people, companies, schools, products); lines are relations. Click any node and watch relations ripple out—watch the “hop count”: one hop is direct, two hops is a “friend of a friend.”

Person Company School Product 👆 Try clicking a node
No node clicked yet. Try “Lei Jun”—see what knowledge spreads within two hops.
AI answers hard questions with these “multi-hops.” “Who else are famous alumni of Lei Jun’s alma mater?”—no single doc says it outright, but two hops on the graph (Lei Jun → Wuhan University → Chen Dongsheng) stitch it together. Knowledge graphs lace scattered facts into a net; after RAG lands on a node you can follow the vines—that’s graph-augmented retrieval (GraphRAG), better at twisty questions than text search alone.
Home turf 2 · multi-Agent workflow: why it must be a DAG

Now a crew of Agents co-writes a research report. Each box is a task; arrows mean “can’t start until upstream finishes.” Hit “Run” and watch two things: tasks with no mutual deps light up together (parallel); each waits until every arrow source turns green. Then hit “Create a cycle” and run again—see what happens.

7 Agents on standby. Yellow = working, green = done.
A “directed acyclic graph” (DAG) isn’t jargon—it’s common sense: dependency arrows have direction (order), and mustn’t loop—once there’s a cycle, it’s “you wait for me, I wait for them, they wait for you,” and nobody starts. Every multi-Agent orchestrator cycle-checks your workflow on submit and refuses to run if it finds one—exactly to dodge the deadlock you just saw.
Tie the two lessons together
🌳

A tree is a graph’s “well-behaved kid”

A tree is a graph with two house rules: one parent each, and no cycles. So last lesson’s file trees and ASTs can use graph algorithms too—graph is the bigger umbrella.

🕸

Graph = nodes + relations

Just that formula. Social nets (people + follows), maps (intersections + roads), knowledge graphs (entities + facts), Agent workflows (tasks + deps)—if you can say “who relates to whom,” you can draw a graph.

What this lesson wants to share