ArdaKaratas commited on
Commit
d95f302
·
verified ·
1 Parent(s): b316ec1

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +27 -1
agent.py CHANGED
@@ -164,13 +164,39 @@ class Agent:
164
  """
165
  def __init__(self):
166
  print("Agent class initialized")
 
 
 
167
 
168
  def __call__(self, question: str) -> str:
169
  """
170
  Call the agent with a question.
171
  This is what the template expects.
 
172
  """
173
- return run_agent(question)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
174
 
175
  if __name__ == "__main__":
176
  # Example usage
 
164
  """
165
  def __init__(self):
166
  print("Agent class initialized")
167
+ # Ensure metadata file exists
168
+ if not os.path.exists("metadata.jsonl"):
169
+ print("⚠️ Warning: metadata.jsonl not found")
170
 
171
  def __call__(self, question: str) -> str:
172
  """
173
  Call the agent with a question.
174
  This is what the template expects.
175
+ Template calls: agent = Agent(); answer = agent(question)
176
  """
177
+ try:
178
+ if not question or not question.strip():
179
+ return "Error: Empty question provided"
180
+
181
+ # Use run_agent which checks metadata first
182
+ answer = run_agent(question)
183
+
184
+ # Ensure we return a string
185
+ if answer is None:
186
+ return "Error: No answer returned"
187
+
188
+ answer_str = str(answer).strip()
189
+ if not answer_str:
190
+ return "Error: Empty answer"
191
+
192
+ print(f"Agent returning answer: {answer_str[:100]}...")
193
+ return answer_str
194
+ except Exception as e:
195
+ error_msg = f"Error in Agent.__call__: {str(e)}"
196
+ print(error_msg)
197
+ import traceback
198
+ traceback.print_exc()
199
+ return error_msg
200
 
201
  if __name__ == "__main__":
202
  # Example usage