Add multiple LangGraph examples including basic agents, chatbots, conditional edges, checkpointers, tool calls, and human-in-the-loop approval processes. Update .gitignore to include local environment files.

This commit is contained in:
Eric Wang
2026-07-25 17:31:26 +08:00
parent e5d701a045
commit f0b0eb13fe
8 changed files with 709 additions and 0 deletions

51
07_command.py Normal file
View File

@@ -0,0 +1,51 @@
from typing import Literal, TypedDict
from langgraph.graph import END, START, StateGraph
from langgraph.types import Command
class State(TypedDict):
number: int
result: str
def check_number(
state: State,
) -> Command[Literal["positive", "negative"]]:
if state["number"] >= 0:
return Command(
update={"result": "这是非负数"},
goto="positive",
)
return Command(
update={"result": "这是负数"},
goto="negative",
)
def positive(state: State):
print(state["result"])
return {}
def negative(state: State):
print(state["result"])
return {}
builder = StateGraph(State)
builder.add_node("check", check_number)
builder.add_node("positive", positive)
builder.add_node("negative", negative)
builder.add_edge(START, "check")
builder.add_edge("positive", END)
builder.add_edge("negative", END)
graph = builder.compile()
graph.invoke({
"number": -5,
"result": "",
})