-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnodes.py
More file actions
27 lines (19 loc) · 796 Bytes
/
nodes.py
File metadata and controls
27 lines (19 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from dotenv import load_dotenv
from langgraph.prebuilt import ToolNode
from react import react_agent_runnable, tools
from state import AgentState
load_dotenv()
def run_agent_reasoning_engine(state: AgentState):
agent_outcome = react_agent_runnable.invoke(state)
print(f"reasoning_agent_outcome: {agent_outcome}")
return {"agent_outcome": agent_outcome}
tool_executor = ToolNode(tools)
def execute_tools(state: AgentState):
"""
Execute the tool chosen by the agent
Takes the agent's action from state and runs the appropriate tool
Returns the tool's output as part of the agent's intermediate steps
"""
agent_action = state["agent_outcome"]
output = tool_executor.invoke(agent_action)
return {"intermediate_steps": [(agent_action, str(output))]}