xiaohongshu
xiaohongshu
langgraph-fundamentals
Core concepts for building LangGraph applications. Use when creating StateGraph workflows, defining nodes and edges, managing state with TypedDict/Pydantic, or understanding basic graph structure. Covers state schemas, reducers, node functions, edge types (normal, conditional), and graph compilat...
Full skill instructions
LangGraph is a low-level orchestration framework for building stateful, multi-actor LLM applications with cyclic graphs.
The central abstraction. Initialize with a state schema, add nodes and edges, then compile.
from langgraph.graph import StateGraph, START, END
from typing import TypedDict, Annotated
import operator
class State(TypedDict):
messages: Annotated[list, operator.add] # Reducer: append
count: int # Override: replace
graph = StateGraph(State)
Define with TypedDict or Pydantic BaseModel. Two update modes:
| Mode | Syntax | Behavior |
|---|---|---|
| Override | field: Type | Replace value |
| Reduce | field: Annotated[Type, reducer] | Apply reducer function |
Common reducers:
operator.add - Append to listadd_messages - Append messages with deduplicationfrom langgraph.graph.message import add_messages
class ChatState(TypedDict):
messages: Annotated[list, add_messages]
Functions that receive state and return partial state updates.
def my_node(state: State) -> dict:
return {"count": state["count"] + 1}
graph.add_node("my_node", my_node)
# Or auto-name from function:
graph.add_node(my_node) # name = "my_node"
Async nodes:
async def async_node(state: State) -> dict:
result = await some_async_call()
return {"data": result}
Connect nodes to define execution flow.
Normal edges - Fixed transitions:
graph.add_edge(START, "node_a")
graph.add_edge("node_a", "node_b")
graph.add_edge("node_b", END)
Conditional edges - Dynamic routing:
def route(state: State) -> str:
if state["count"] > 5:
return "finish"
return "continue"
graph.add_conditional_edges(
"node_a",
route,
{"finish": END, "continue": "node_b"}
)
Fan-out/Fan-in - Parallel execution:
# Fan-out: single node to multiple
graph.add_edge("start", "task_a")
graph.add_edge("start", "task_b")
# Fan-in: multiple nodes to single (waits for all)
graph.add_edge(["task_a", "task_b"], "merge")
# Compile
app = graph.compile()
# Invoke (sync)
result = app.invoke({"messages": [], "count": 0})
# Stream (sync)
for event in app.stream({"messages": []}, stream_mode="updates"):
print(event)
# Async
result = await app.ainvoke({"messages": []})
async for event in app.astream({"messages": []}):
print(event)
from typing import Annotated, Literal
from typing_extensions import TypedDict
from langchain.chat_models import init_chat_model
from langchain.tools import tool
from langgraph.graph import StateGraph, START, END
from langgraph.graph.message import add_messages
from langgraph.prebuilt import ToolNode
class State(TypedDict):
messages: Annotated[list, add_messages]
@tool
def search(query: str) -> str:
"""Search the web."""
return f"Results for: {query}"
tools = [search]
model = init_chat_model("gpt-4o").bind_tools(tools)
def agent(state: State) -> dict:
response = model.invoke(state["messages"])
return {"messages": [response]}
def should_continue(state: State) -> Literal["tools", "__end__"]:
last = state["messages"][-1]
if last.tool_calls:
return "tools"
return "__end__"
graph = StateGraph(State)
graph.add_node("agent", agent)
graph.add_node("tools", ToolNode(tools))
graph.add_edge(START, "agent")
graph.add_conditional_edges("agent", should_continue)
graph.add_edge("tools", "agent")
app = graph.compile()
Annotated with reducers for accumulating valuesSTART and END are special constants for entry/exitxiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience