Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional statement expanded for errored API response (close #560) #628

Conversation

xAIdrian
Copy link
Contributor

@xAIdrian xAIdrian commented Jul 4, 2023

Solved endless loop and hanging UI by extending our error catching by expanding conditional check to properties.

Description

Solved endless loop and hanging UI by extending our error catching. We were getting an uncaught exception because response['content'} was throwing a KeyError when response does not contain a 'content' property.

Traceback (most recent call last):
superagi-celery-1           |   File "/usr/local/lib/python3.9/site-packages/celery/app/trace.py", line 451, in trace_task
superagi-celery-1           |     R = retval = fun(*args, **kwargs)
superagi-celery-1           |   File "/usr/local/lib/python3.9/site-packages/celery/app/trace.py", line 734, in __protected_call__
superagi-celery-1           |     return self.run(*args, **kwargs)
superagi-celery-1           |   File "/usr/local/lib/python3.9/site-packages/celery/app/autoretry.py", line 54, in run
superagi-celery-1           |     ret = task.retry(exc=exc, **retry_kwargs)
superagi-celery-1           |   File "/usr/local/lib/python3.9/site-packages/celery/app/task.py", line 717, in retry
superagi-celery-1           |     raise_with_context(exc)
superagi-celery-1           |   File "/usr/local/lib/python3.9/site-packages/celery/app/autoretry.py", line 34, in run
superagi-celery-1           |     return task._orig_run(*args, **kwargs)
superagi-celery-1           |   File "/app/superagi/worker.py", line 19, in execute_agent
superagi-celery-1           |     AgentExecutor().execute_next_action(agent_execution_id=agent_execution_id)
superagi-celery-1           |   File "/app/superagi/jobs/agent_executor.py", line 206, in execute_next_action
superagi-celery-1           |     response = spawned_agent.execute(agent_workflow_step)
superagi-celery-1           |   File "/app/superagi/agent/super_agi.py", line 168, in execute
superagi-celery-1           |     if response['content'] is None:
superagi-celery-1           | KeyError: 'content'

Related Issues

Resolves #560 #272

Solution and Design

If we capture the case of a missing property AND the response['content'] is None. Execution continues and we hit max retry threshold. Original user behavior stays intact because we are not changing the error handling mechanism. Since we are properly catching errors now we let the UI show the user that the maximum number of retries have been attempted.

Small fixes:

Account for the case when we have no content in our response

if 'content' not in response or response['content'] is None:
    raise RuntimeError(f"Failed to get response from llm")

Surround execution with try catch to follow existing design:

try:
    response = spawned_agent.execute(agent_workflow_step)
except RuntimeError as e:    
    # If our execution encounters an error we respond as an error and attempt to retry
     return

Test Plan

While there is no test class for super_agi.py you can see the manual testing below.
https://www.loom.com/share/028e80623061493a8c167f1aa0df5edb?sid=29e496ec-62ba-4bed-b809-25cf29cd88de

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Docs update

Checklist

  • My pull request is atomic and focuses on a single change.
  • I have read the contributing guide and my code conforms to the guidelines.
  • I have documented my changes clearly and comprehensively.
  • I have added the required tests.

Solved endless loop and hanging UI by extending our error catching by expanding conditional check to properties.
@xAIdrian xAIdrian changed the title Conditional statement expanded for errored API response Conditional statement expanded for errored API response (close #560) Jul 4, 2023
@xAIdrian xAIdrian marked this pull request as ready for review July 4, 2023 09:41
@TransformerOptimus TransformerOptimus changed the base branch from main to dev July 4, 2023 13:17
@TransformerOptimus TransformerOptimus merged commit 6bb345d into TransformerOptimus:dev Jul 4, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

if response['content'] is None: | KeyError: 'content'
2 participants