Skip to content

Commit

Permalink
fix: Handle api key error (All-Hands-AI#488)
Browse files Browse the repository at this point in the history
* Propagate exception up to task coroutine instead of breaking the for loop manually, await coroutine so exception is returned to caller

* Remove redundant traceback as is already called in step function lower on the stack

* Change message as error could occur in middle of task also

* Fix linter errors

* Raise exception only on api key error

* Add TODO
  • Loading branch information
joorjeh committed Apr 2, 2024
1 parent fa40d37 commit a9f469f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 4 additions & 2 deletions opendevin/controller/agent_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ async def start_loop(self, task: str):
finished = await self.step(i)
except Exception as e:
print("Error in loop", e, flush=True)
traceback.print_exc()
break
raise e
if finished:
break
if not finished:
Expand Down Expand Up @@ -94,6 +93,9 @@ async def step(self, i: int):
observation = AgentErrorObservation(str(e))
print_with_indent("\nAGENT ERROR:\n%s" % observation)
traceback.print_exc()
# TODO Change to more robust error handling
if "The api_key client option must be set" in observation.content:
raise
self.update_state_after_step()

await self._run_callbacks(action)
Expand Down
5 changes: 4 additions & 1 deletion opendevin/server/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ async def start_task(self, start_event):
if self.controller is None:
await self.send_error("No agent started. Please wait a second...")
return
self.agent_task = asyncio.create_task(self.controller.start_loop(task), name="agent loop")
try:
self.agent_task = await asyncio.create_task(self.controller.start_loop(task), name="agent loop")
except Exception:
await self.send_error("Error during task loop.")

def on_agent_event(self, event: Observation | Action):
"""Callback function for agent events.
Expand Down

0 comments on commit a9f469f

Please sign in to comment.