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

Fix: llm completion exception breaks CodeActAgent #3678

Merged
merged 6 commits into from
Sep 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions agenthub/codeact_agent/codeact_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from openhands.controller.agent import Agent
from openhands.controller.state.state import State
from openhands.core.config import AgentConfig
from openhands.core.logger import openhands_logger as logger
from openhands.core.message import ImageContent, Message, TextContent
from openhands.events.action import (
Action,
Expand Down Expand Up @@ -198,8 +199,13 @@ def step(self, state: State) -> Action:
params['extra_headers'] = {
'anthropic-beta': 'prompt-caching-2024-07-31',
}

response = self.llm.completion(**params)
try:
response = self.llm.completion(**params)
except Exception as e:
logger.error(f'LLM completion failed: {e}')
return AgentFinishAction(
thought='Agent encountered an error. Please try again.'
)

return self.action_parser.parse(response)

Expand Down