jcleee commited on
Commit
c21837e
·
verified ·
1 Parent(s): 939e99c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -5
app.py CHANGED
@@ -133,16 +133,30 @@ import gradio as gr
133
  # NEW VERSION
134
  def run_agent(question):
135
  try:
136
- steps = list(agent.run(question))
137
- for step in reversed(steps):
138
- if hasattr(step, "tool_calls"):
 
 
 
139
  for call in step.tool_calls:
140
  if call.name == "final_answer":
141
- return [str(call.arguments.get("answer", "null"))]
142
- return ["null"] # fallback
 
 
 
 
 
 
 
 
 
 
143
  except Exception as e:
144
  return [f"Error: {e}"]
145
 
146
 
 
147
  demo = gr.Interface(fn=run_agent, inputs="text", outputs="text")
148
  demo.launch()
 
133
  # NEW VERSION
134
  def run_agent(question):
135
  try:
136
+ # Get all steps from the agent run
137
+ steps = list(agent.run(question, stream=False))
138
+
139
+ # Look through all tool calls to find final_answer
140
+ for step in steps:
141
+ if hasattr(step, "tool_calls") and step.tool_calls:
142
  for call in step.tool_calls:
143
  if call.name == "final_answer":
144
+ answer = call.arguments.get("answer", None)
145
+ if answer:
146
+ return [str(answer)]
147
+
148
+ # Fallback: try tool_output or .final_answer if FinalAnswerStep
149
+ for step in reversed(steps):
150
+ if hasattr(step, "tool_output") and step.tool_output:
151
+ return [str(step.tool_output)]
152
+ if hasattr(step, "final_answer") and step.final_answer:
153
+ return [str(step.final_answer)]
154
+
155
+ return ["null"]
156
  except Exception as e:
157
  return [f"Error: {e}"]
158
 
159
 
160
+
161
  demo = gr.Interface(fn=run_agent, inputs="text", outputs="text")
162
  demo.launch()