LangGraph
LangGraph exposes agent workflows as graphs, making execution paths explicit—and therefore inspectable. Wrap the LLM client used by each node to gain visibility into the full execution path, including state propagation and tool calls.
Configuration
Section titled “Configuration”import osfrom langchain_openai import ChatOpenAI
# Create LangChain ChatOpenAI with Glitchllm = ChatOpenAI( model="gpt-4", api_key=os.environ["GLITCH_API_KEY"], base_url="https://api.golabrat.ai/v1",)Basic Example
Section titled “Basic Example”import osfrom typing import TypedDict, Annotatedfrom langchain_openai import ChatOpenAIfrom langgraph.graph import StateGraph, ENDfrom langgraph.prebuilt import ToolNode
# Configure LangChain with Glitchllm = ChatOpenAI( model="gpt-4", api_key=os.environ["GLITCH_API_KEY"], base_url="https://api.golabrat.ai/v1",)
# Bind tools to the LLMtools = [/* your tools */]llm_with_tools = llm.bind_tools(tools)
# Define graph stateclass State(TypedDict): messages: Annotated[list, "messages"]
# Build the graphworkflow = StateGraph(State)workflow.add_node("agent", llm_with_tools)workflow.add_node("tools", ToolNode(tools))workflow.add_edge("agent", "tools")workflow.add_edge("tools", END)
app = workflow.compile()
# Run the graph - all LLM calls are securedresult = await app.invoke({ "messages": [{"role": "user", "content": "What's the weather in Paris?"}]})Error Handling
Section titled “Error Handling”Handle security blocks in your graph nodes:
from langchain_core.exceptions import LangChainException
try: result = await app.invoke({"messages": [{"role": "user", "content": user_input}]}) return resultexcept LangChainException as e: # Check if it's a 403 security block if "403" in str(e) or "security" in str(e).lower(): # Handle security block return {"messages": [{"role": "assistant", "content": "I can't process that request."}]} raiseNext Steps
Section titled “Next Steps”- Frameworks Overview — Other framework integrations
- Quick Start — Get running in 5 minutes
- API Reference — Full endpoint documentation