Final submission: update main.py
This commit is contained in:
@@ -15,14 +15,18 @@ def echo(text: str) -> str:
|
|||||||
|
|
||||||
# Define graph state
|
# Define graph state
|
||||||
class State(dict):
|
class State(dict):
|
||||||
pass
|
pass # no-op
|
||||||
|
|
||||||
|
# Dummy tool node to satisfy interrupt_before
|
||||||
|
async def tools_node(state: State, config=None):
|
||||||
|
return state
|
||||||
|
|
||||||
# Agent node
|
# Agent node
|
||||||
async def agent_node(state: State, config=None):
|
async def agent_node(state: State, config=None):
|
||||||
# Use LangChain LLM with tool calling
|
# Use LangChain LLM with tool calling
|
||||||
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
|
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
|
||||||
from langchain.agents import create_openai_functions_agent
|
from langgraph.agent import create_agent
|
||||||
agent = create_openai_functions_agent(llm, [echo])
|
agent = create_agent(llm, [echo])
|
||||||
messages = state.get("messages", [])
|
messages = state.get("messages", [])
|
||||||
# Run agent
|
# Run agent
|
||||||
result = await agent.ainvoke({"messages": messages})
|
result = await agent.ainvoke({"messages": messages})
|
||||||
@@ -32,6 +36,7 @@ async def agent_node(state: State, config=None):
|
|||||||
builder = StateGraph(State)
|
builder = StateGraph(State)
|
||||||
builder.add_node("agent", agent_node)
|
builder.add_node("agent", agent_node)
|
||||||
builder.set_entry_point("agent")
|
builder.set_entry_point("agent")
|
||||||
|
builder.add_node("tools", tools_node)
|
||||||
|
|
||||||
graph = builder.compile(checkpointer=MemorySaver(), interrupt_before=["tools"]) # memory and pause before tools
|
graph = builder.compile(checkpointer=MemorySaver(), interrupt_before=["tools"]) # memory and pause before tools
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user