Skip to content

Commit

Permalink
fix(agents-api): Retry failed integration executions (#874)
Browse files Browse the repository at this point in the history
<!-- ELLIPSIS_HIDDEN -->



> [!IMPORTANT]
> Introduces `IntegrationExecutionException` for integration execution
errors and updates retry logic to handle it.
> 
>   - **Behavior**:
> - Introduces `IntegrationExecutionException` in `tools.py` for errors
during integration execution.
> - Updates `execute_integration()` in `execute_integration.py` to raise
`IntegrationExecutionException` on integration service errors.
>   - **Error Handling**:
> - Adds `IntegrationExecutionException` to `RETRYABLE_ERROR_TYPES` in
`tasks.py` to allow retries for integration execution errors.
> 
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=julep-ai%2Fjulep&utm_source=github&utm_medium=referral)<sup>
for 11edfc0. It will automatically
update as commits are pushed.</sup>

<!-- ELLIPSIS_HIDDEN -->

---------

Co-authored-by: HamadaSalhab <[email protected]>
  • Loading branch information
HamadaSalhab and HamadaSalhab authored Nov 23, 2024
1 parent 5b63886 commit f27c4a1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
13 changes: 11 additions & 2 deletions agents-api/agents_api/activities/execute_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from ..autogen.openapi_model import BaseIntegrationDef
from ..clients import integrations
from ..common.exceptions.tools import IntegrationExecutionException
from ..common.protocol.tasks import StepContext
from ..common.storage_handler import auto_blob_store
from ..env import testing
Expand Down Expand Up @@ -53,13 +54,21 @@ async def execute_integration(
"error" in integration_service_response
and integration_service_response["error"]
):
raise Exception(integration_service_response["error"])
raise IntegrationExecutionException(
integration=integration,
error=integration_service_response["error"],
)

return integration_service_response

except BaseException as e:
if activity.in_activity():
activity.logger.error(f"Error in execute_integration: {e}")
integration_str = integration.provider + (
"." + integration.method if integration.method else ""
)
activity.logger.error(
f"Error in execute_integration {integration_str}: {e}"
)

raise

Expand Down
5 changes: 5 additions & 0 deletions agents-api/agents_api/common/exceptions/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import temporalio.exceptions
from tenacity import RetryError

from .tools import IntegrationExecutionException

# 🚫 The "No Second Chances" Club - errors that we won't retry
# Because sometimes, no means no!
NON_RETRYABLE_ERROR_TYPES = (
Expand Down Expand Up @@ -134,6 +136,9 @@
#
# Tenacity exceptions (retry when retrying goes wrong lol)
RetryError,
#
# Tools-related exceptions (when tools have a bad day)
IntegrationExecutionException,
)

# HTTP status codes that say "maybe try again later?"
Expand Down
25 changes: 25 additions & 0 deletions agents-api/agents_api/common/exceptions/tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
Defines tools-related exceptions for the agents API.
"""

from ...autogen.openapi_model import BaseIntegrationDef
from . import BaseCommonException


class BaseToolsException(BaseCommonException):
"""Base exception for tools-related errors."""

pass


class IntegrationExecutionException(BaseToolsException):
"""Exception raised when an error occurs during an integration execution."""

def __init__(self, integration: BaseIntegrationDef, error: str):
integration_str = integration.provider + (
"." + integration.method if integration.method else ""
)
super().__init__(
f"Error in executing {integration_str}: {error}",
http_code=500,
)

0 comments on commit f27c4a1

Please sign in to comment.