Daniel Amendoeira commited on
Commit
87c5184
·
verified ·
1 Parent(s): 232ee64

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +27 -11
agent.py CHANGED
@@ -108,14 +108,30 @@ builder.add_edge("environment", "llm_call") # after running the tools go back t
108
 
109
  gaia_agent = builder.compile() # converts my builder into a runnable agent by using gaia_agent.invoke()
110
 
111
- # Call the Agent
112
- def agent_run(question: str):
113
- input_state = {"messages": [HumanMessage(content=question)]} # prepare the initial user message
114
- result = gaia_agent.invoke(input_state, {"recursion_limit": 30}) # prevents infinite looping when the LLM keeps calling tools over and over
115
- final_response = result["messages"][-1].content
116
-
117
- try:
118
- return final_response.split("FINAL ANSWER:")[-1].strip() # parse out only what's after "FINAL ANSWER:"
119
- except Exception:
120
- print("Could not split on 'FINAL ANSWER:'")
121
- return final_response
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
 
109
  gaia_agent = builder.compile() # converts my builder into a runnable agent by using gaia_agent.invoke()
110
 
111
+ # Call the Agent
112
+ #def agent_run(question: str):
113
+ input_state = {"messages": [HumanMessage(content=question)]} # prepare the initial user message
114
+ result = gaia_agent.invoke(input_state, {"recursion_limit": 30}) # prevents infinite looping when the LLM keeps calling tools over and over
115
+ final_response = result["messages"][-1].content
116
+
117
+ try:
118
+ return final_response.split("FINAL ANSWER:")[-1].strip() # parse out only what's after "FINAL ANSWER:"
119
+ except Exception:
120
+ print("Could not split on 'FINAL ANSWER:'")
121
+ return final_response
122
+
123
+ class LangGraphAgent:
124
+ def __init__(self):
125
+ print("LangGraphAgent initialized.")
126
+
127
+ def __call__(self, question: str) -> str:
128
+ input_state = {"messages": [HumanMessage(content=question)]} # prepare the initial user message
129
+ print(f"Running LangGraphAgent with input: {question[:50]}...")
130
+ result = gaia_agent.invoke(input_state, {"recursion_limit": 30}) # prevents infinite looping when the LLM keeps calling tools over and over
131
+ final_response = result["messages"][-1].content
132
+
133
+ try:
134
+ return final_response.split("FINAL ANSWER:")[-1].strip() # parse out only what's after "FINAL ANSWER:"
135
+ except Exception:
136
+ print("Could not split on 'FINAL ANSWER:'")
137
+ return final_response