Langgraph Workflows

LangGraph

ComeOnOliver Updated 61 repo stars

File contents

LangGraph

Basic Agent Graph

from langgraph.graph import StateGraph, END
from typing import TypedDict

class AgentState(TypedDict):
    messages: list
    next_step: str

def call_model(state: AgentState) -> AgentState:
    response = llm.invoke(state["messages"])
    return {"messages": state["messages"] + [response]}

def should_continue(state: AgentState) -> str:
    if state["messages"][-1].tool_calls:
        return "tools"
    return END

graph = StateGraph(AgentState)
graph.add_node("agent", call_model)
graph.add_node("tools", tool_executor)
graph.add_conditional_edges("agent", should_continue, {"tools": "tools", END: END})
graph.add_edge("tools", "agent")
graph.set_entry_point("agent")

app = graph.compile()
result = app.invoke({"messages": [HumanMessage("What's the weather?")]})

Checkpointing for persistence, human-in-the-loop, branching, subgraphs

ComeOnOliver/skillshub/tree/main/skills/skillshub-team/catalog-batch5/langgraph-workflows commit bde446dcdb

Frequently asked questions

npx skillmds@latest add comeonoliver/langgraph-workflows