Skip to content

Commit 0c147dc

Browse files
committed
Fix agent status checking to match working pattern
1 parent 7830c4a commit 0c147dc

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

main.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -273,30 +273,30 @@ async def chat_with_agent(self, message: str) -> ChatResponse:
273273

274274
# Check run status (detailed debugging like sample script)
275275
logger.info(f"Run completed with status: {run.status}")
276-
if str(run.status) == "RunStatus.FAILED":
276+
if run.status == "failed":
277277
logger.error(f"Run failed: {getattr(run, 'last_error', 'Unknown error')}")
278278
assistant_response = f"Run failed: {getattr(run, 'last_error', 'Unknown error')}"
279279

280280
# Display run steps and tool calls (like sample script)
281281
try:
282282
run_steps = fresh_client.run_steps.list(thread_id=thread.id, run_id=run.id)
283283
for step in run_steps:
284-
logger.info(f"Step {step.id} status: {step.status}")
284+
logger.info(f"Step {step['id']} status: {step['status']}")
285285

286286
# Check if there are tool calls in the step details
287-
step_details = getattr(step, 'step_details', {})
288-
tool_calls = getattr(step_details, 'tool_calls', []) if step_details else []
287+
step_details = step.get('step_details', {})
288+
tool_calls = step_details.get('tool_calls', [])
289289

290290
if tool_calls:
291291
logger.info(" MCP Tool calls:")
292292
for call in tool_calls:
293-
logger.info(f" Tool Call ID: {getattr(call, 'id', 'N/A')}")
294-
logger.info(f" Type: {getattr(call, 'type', 'N/A')}")
295-
logger.info(f" Name: {getattr(call, 'name', 'N/A')}")
293+
logger.info(f" Tool Call ID: {call.get('id', 'N/A')}")
294+
logger.info(f" Type: {call.get('type', 'N/A')}")
295+
logger.info(f" Name: {call.get('name', 'N/A')}")
296296
except Exception as e:
297297
logger.error(f"Error retrieving run steps: {e}")
298298

299-
if str(run.status) == "RunStatus.COMPLETED":
299+
if run.status == "completed":
300300
# Get the response
301301
messages_paged = fresh_client.messages.list(thread_id=thread.id)
302302
messages = list(messages_paged) # Convert ItemPaged to list

0 commit comments

Comments
 (0)