TOOL WIKI · AGENT SDKS
LangGraph
Represents an agent or workflow as explicit state and transitions in a graph.
Jump to a section 10 sections
EXAMPLE USE CASE
Own the transitions in an order lookup loop
A developer needs a small, observable agent or retrieval step before connecting real business services.
- Input
- MessagesState, a model node, ToolNode and a bounded recursion limit.
- Expected output
- A model → tool → model path ending in the observed order status.
- Success check: The messages end with an answer grounded in the tool result.
- Try a failure: A repeated request must stop at the configured recursion bound.
Example scope: Actual graph invocation; state is process-local without a checkpointer.
Official reference · LangGraph
Authenticate the request and define the goal before calling the framework.
Custom control flow, branching, interruptions, and persisted execution. A checkpoint does not make an external side effect safe to repeat.
invokeTo 03 · Model providertool callTo 04 · Tool servicemeasureTo 06 · EvaluationThe application supplies provider credentials, model selection, and budgets.
decisionBack to 02 · LangGraphValidate each operation and return authoritative observations.
resultBack to 02 · LangGraphChoose the checkpoint or session store and its retention policy deliberately.
Result or stopping pointCheck completion, cost, latency, and tool behavior against fixtures.
Result or stopping point
Custom control flow, branching, interruptions, and persisted execution. A checkpoint does not make an external side effect safe to repeat.
When to consider it
- Custom control flow, branching, interruptions, and persisted execution.
A design decision to make
- A checkpoint does not make an external side effect safe to repeat.
Prerequisites and setup
- Python 3.11+ in an empty directory. A compatible model and provider credentials are required.
- Running the model-backed example can incur API charges; this website displays it without calling a provider.
- Save the code at the displayed path, then use the corresponding run command.
python3 -m venv .venv
source .venv/bin/activate
python -m pip install langgraph langchain langchain-openai
export OPENAI_API_KEY="your-api-key"
export OPENAI_MODEL="your-enabled-model-id"Try a small integration
graph_agent.py
import os
from langchain.chat_models import init_chat_model
from langchain.tools import tool
from langgraph.graph import StateGraph, MessagesState, START
from langgraph.prebuilt import ToolNode, tools_condition
@tool
def lookup_order(order_id: str) -> str:
"""Read an order status from a local demonstration fixture."""
orders = {"A104": "Packed; awaiting courier pickup"}
return orders.get(order_id, "Order not found")
tools = [lookup_order]
model = init_chat_model(
os.environ["OPENAI_MODEL"], model_provider="openai"
).bind_tools(tools)
def think(state: MessagesState):
response = model.invoke(state["messages"])
return {"messages": [response]}
builder = StateGraph(MessagesState)
builder.add_node("think", think)
builder.add_node("tools", ToolNode(tools))
builder.add_edge(START, "think")
builder.add_conditional_edges("think", tools_condition)
builder.add_edge("tools", "think")
agent = builder.compile()
result = agent.invoke(
{"messages": [("user", "Use lookup_order for A104.")]},
{"recursion_limit": 8},
)
print(result["messages"][-1].content)Run and check the result
python graph_agent.py- The messages end with an answer grounded in the tool result.
- The graph moves from think to tools and back, then stops when no tool is requested.
Common failures
- A missing ToolMessage or mismatched call identifier breaks the tool-result contract.
- A recursion-limit failure is evidence of an unfinished loop; inspect repeated tool calls before raising the limit.
Production decisions
- Replace the local fixture with a service that enforces authenticated tenant and resource permissions.
- Add timeouts, bounded retries, tracing redaction, and a regression case for each observed failure.
- Model calls consume provider API usage when you run this example; this website only displays the code.
Keep exploring
Explore the same layer
Compare candidates on your own workload. This entry describes a product’s role; it is not a claim that products in the category are interchangeable.