LangGraph & GraphRAG: Exploring Graph-Based AI Agents and RAG
Overview
This project covers two explorations: agent development with LangGraph (prj_langgraph) and knowledge graph–based retrieval with GraphRAG (prj_graphrag). Work took place from November to December 2024, across 12 commits total.
Part 1: LangGraph Agents (prj_langgraph)
Background
LangGraph is an agent orchestration framework developed by the LangChain team. Unlike the linear chain structure of traditional LangChain, it expresses agent reasoning flows as a state-based graph.
Implementation
Development progressed incrementally from the first commit on November 27, 2024 through December 10, spanning 9 commits.
1. Basic Graph Structure (11/27–11/29)
from langgraph.graph import StateGraph, MessagesState
# 상태 기반 에이전트 그래프 정의
graph = StateGraph(MessagesState)
graph.add_node("agent", agent_node)
graph.add_node("tools", tool_node)
graph.add_edge("agent", "tools")
graph.add_conditional_edges("tools", should_continue)
2. Tool Integration (12/03–12/06)
Integrated various tools (search, calculation, code execution) into the LangGraph agent and learned the conditional routing pattern.
def should_continue(state: MessagesState):
"""에이전트가 도구를 호출해야 하는지 판단"""
last_message = state["messages"][-1]
if last_message.tool_calls:
return "tools"
return END
3. Advanced Patterns (12/10)
The final commit experimented with multi-agent collaboration patterns and subgraph structures.
Part 2: GraphRAG (prj_graphrag)
Concept
Where conventional RAG performs straightforward retrieval based on vector similarity, GraphRAG builds a knowledge graph capturing relationships between documents, providing richer context.
Implementation
A prototype was built quickly across 3 commits between December 10–13, 2024.
# 엔티티 추출 및 관계 매핑
entities = extract_entities(documents)
relationships = build_knowledge_graph(entities)
# 그래프 기반 검색
relevant_context = graph_search(
query=user_query,
graph=knowledge_graph,
depth=2 # 2-hop 관계까지 탐색
)
Comparison with Conventional RAG
| Vector RAG | GraphRAG | |
|---|---|---|
| Retrieval method | Cosine similarity | Graph traversal |
| Context | Independent chunks | Includes relationships |
| Multi-hop reasoning | Difficult | Natural |
| Build cost | Low | High |
What Came Next
The experience from these two projects directly influenced the workflow graph architecture and RAG pipeline design of the XGen platform. In particular, LangGraph's state-based graph pattern was incorporated into XGen's workflow execution engine, and GraphRAG's relationship extraction concept was applied to metadata linking in the Qdrant-based RAG pipeline.
Retrospective
It was a brief exploration — just 12 commits — but an important one that validated the potential of graph-based AI systems. LangGraph made it possible to visually design complex agent workflows, while GraphRAG pointed toward a new direction: pursuing depth of understanding rather than simply accuracy of retrieval.