Spaces:
Sleeping
Sleeping
File size: 1,934 Bytes
f78a0f0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | """LangGraph multi-agent research workflow — parsable example.
This file is intentionally NOT runnable (it imports langgraph, which you
may not have installed). It exists so users can try::
import semanticembed as se
edges = se.extract.from_langgraph("examples/langgraph_research_agent.py")
The parser is pure AST — it never imports langgraph or executes any of
this code.
Topology (what `from_langgraph` will extract):
START -> planner
planner -> researcher
researcher -> writer (conditional: ready=True)
researcher -> researcher (conditional: ready=False, dropped as self-loop)
writer -> critic
critic -> writer (conditional: needs_revision=True)
critic -> END (conditional: needs_revision=False)
"""
from langgraph.graph import StateGraph, START, END
def planner(state):
"""Decompose the question into research tasks."""
return state
def researcher(state):
"""Hit web search + scratch tools."""
return state
def writer(state):
"""Draft the answer from the research."""
return state
def critic(state):
"""Score the draft. Either request a revision or finish."""
return state
def research_router(state):
return "writer" if state.get("ready") else "researcher"
def critic_router(state):
return "writer" if state.get("needs_revision") else "END"
workflow = StateGraph(dict)
workflow.add_node("planner", planner)
workflow.add_node("researcher", researcher)
workflow.add_node("writer", writer)
workflow.add_node("critic", critic)
workflow.set_entry_point("planner")
workflow.add_edge("planner", "researcher")
workflow.add_conditional_edges(
"researcher",
research_router,
{"writer": "writer", "researcher": "researcher"},
)
workflow.add_edge("writer", "critic")
workflow.add_conditional_edges(
"critic",
critic_router,
{"writer": "writer", "END": END},
)
app = workflow.compile()
|