Update agents/agents_nodes.py
Browse files- agents/agents_nodes.py +29 -8
agents/agents_nodes.py
CHANGED
|
@@ -38,21 +38,42 @@ llm = HuggingFacePipeline(pipeline=text_generator)
|
|
| 38 |
# )
|
| 39 |
# )
|
| 40 |
|
| 41 |
-
llm_instantiated = llm | RunnableLambda(
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
)
|
| 47 |
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
def agent_node(state: AgentState):
|
| 50 |
response = llm_instantiated.invoke(state["messages"])
|
| 51 |
-
if not
|
| 52 |
-
|
| 53 |
-
|
| 54 |
return {"messages": [response]}
|
| 55 |
|
|
|
|
|
|
|
| 56 |
# Tool node executes the tool
|
| 57 |
tool_node = ToolNode([time_value_tool])
|
| 58 |
|
|
|
|
| 38 |
# )
|
| 39 |
# )
|
| 40 |
|
| 41 |
+
# llm_instantiated = llm | RunnableLambda(
|
| 42 |
+
# lambda x: x.bind(
|
| 43 |
+
# [time_value_tool],
|
| 44 |
+
# tool_choice={"type": "function", "function": {"name": "time_value_tool"}}
|
| 45 |
+
# )
|
| 46 |
+
# )
|
| 47 |
+
|
| 48 |
+
# Replace this
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
# With this
|
| 52 |
+
llm_instantiated = llm.bind(
|
| 53 |
+
tools=[time_value_tool],
|
| 54 |
+
tool_choice="time_value_tool"
|
| 55 |
)
|
| 56 |
|
| 57 |
|
| 58 |
+
|
| 59 |
+
# def agent_node(state: AgentState):
|
| 60 |
+
# response = llm_instantiated.invoke(state["messages"])
|
| 61 |
+
# if not (hasattr(response, 'tool_calls') and response.tool_calls):
|
| 62 |
+
# error_message = AIMessage(content="Error: Model failed to generate tool call.")
|
| 63 |
+
# return {"messages": [error_message]}
|
| 64 |
+
# return {"messages": [response]}
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
# Update tool invocation in agent_node
|
| 68 |
def agent_node(state: AgentState):
|
| 69 |
response = llm_instantiated.invoke(state["messages"])
|
| 70 |
+
if not hasattr(response, 'tool_calls') or not response.tool_calls:
|
| 71 |
+
return {"messages": [AIMessage(content="Error: No tool call generated")]}
|
| 72 |
+
tool_call = response.tool_calls
|
| 73 |
return {"messages": [response]}
|
| 74 |
|
| 75 |
+
|
| 76 |
+
|
| 77 |
# Tool node executes the tool
|
| 78 |
tool_node = ToolNode([time_value_tool])
|
| 79 |
|