Spaces:
Running
Running
Daniel Amendoeira
commited on
Update agent.py
Browse files
agent.py
CHANGED
@@ -36,6 +36,7 @@ custom_tools = [datetime_tools, transcribe_audio_tool]
|
|
36 |
tools = community_tools + custom_tools
|
37 |
llm_with_tools = llm.bind_tools(tools)
|
38 |
|
|
|
39 |
tools_by_name = {tool.name: tool for tool in tools}
|
40 |
|
41 |
class MessagesState(TypedDict): # creates the state (is like the agent's memory at any moment)
|
@@ -83,11 +84,19 @@ builder.add_edge(START, "llm_call")
|
|
83 |
builder.add_conditional_edges(
|
84 |
"llm_call",
|
85 |
should_continue,
|
86 |
-
{
|
87 |
-
# Name returned by should_continue : Name of the next node
|
88 |
-
"Action": "environment",
|
89 |
-
END: END
|
90 |
-
})
|
91 |
builder.add_edge("environment", "llm_call")
|
92 |
|
93 |
-
gaia_agent = builder.compile()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
tools = community_tools + custom_tools
|
37 |
llm_with_tools = llm.bind_tools(tools)
|
38 |
|
39 |
+
# Prepare tools by name
|
40 |
tools_by_name = {tool.name: tool for tool in tools}
|
41 |
|
42 |
class MessagesState(TypedDict): # creates the state (is like the agent's memory at any moment)
|
|
|
84 |
builder.add_conditional_edges(
|
85 |
"llm_call",
|
86 |
should_continue,
|
87 |
+
{"Action": "environment", END: END}) # Name returned by should_continue : Name of the next node
|
|
|
|
|
|
|
|
|
88 |
builder.add_edge("environment", "llm_call")
|
89 |
|
90 |
+
gaia_agent = builder.compile()
|
91 |
+
|
92 |
+
# Call the Agent
|
93 |
+
def run_gaia(question: str):
|
94 |
+
input_state = {"messages": [HumanMessage(content=question)]} # prepare the initial user message
|
95 |
+
result = gaia_agent.invoke(input_state, {"recursion_limit": 30}) # invoke with recursion limit to avoid infinite loops
|
96 |
+
final_response = result["messages"][-1].content
|
97 |
+
|
98 |
+
try:
|
99 |
+
return final_response.split("FINAL ANSWER:")[-1].strip() # parse out only what's after "FINAL ANSWER:"
|
100 |
+
except Exception:
|
101 |
+
print("Could not split on 'FINAL ANSWER:'")
|
102 |
+
return final_response
|