Skip to content

Commit

Permalink
fix(integrations-service): Return errors for failed integration execu…
Browse files Browse the repository at this point in the history
…tions (#836)

<!-- ELLIPSIS_HIDDEN -->


> [!IMPORTANT]
> Enhances error handling in integration executions by introducing
`ExecutionError` and updating functions to return it on exceptions.
> 
>   - **Behavior**:
> - `execute_integration` in `execute_integration.py` raises an
exception if `integration_service_response` contains an error.
> - Integration functions in `brave.py`, `browserbase.py`, `email.py`,
`llama_parse.py`, `remote_browser.py`, `spider.py`, `weather.py`, and
`wikipedia.py` return `ExecutionError` on exceptions.
>   - **Models**:
> - Adds `ExecutionError` model to `execution.py` to encapsulate error
messages.
>   - **Functions**:
> - Updates return types of integration functions to include
`ExecutionError` in `brave.py`, `browserbase.py`, `email.py`,
`llama_parse.py`, `remote_browser.py`, `spider.py`, `weather.py`, and
`wikipedia.py`.
> 
> <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 968fe53. 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 16, 2024
1 parent 0555e91 commit 16a5a51
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 9 deletions.
7 changes: 6 additions & 1 deletion agents-api/agents_api/activities/execute_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,18 @@ async def execute_integration(
if integration.provider == "dummy":
return arguments

return await integrations.run_integration_service(
integration_service_response = await integrations.run_integration_service(
provider=integration.provider,
setup=setup,
method=integration.method,
arguments=arguments,
)

if "error" in integration_service_response:
raise Exception(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}")
Expand Down
9 changes: 9 additions & 0 deletions integrations-service/integrations/models/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
from .weather import WeatherGetOutput
from .wikipedia import WikipediaSearchOutput


class ExecutionError(BaseModel):
error: str
"""
The error message of the integration execution
"""


ExecutionSetup = Union[
EmailSetup,
SpiderSetup,
Expand Down Expand Up @@ -90,6 +98,7 @@
BrowserbaseListSessionsOutput,
RemoteBrowserOutput,
LlamaParseFetchOutput,
ExecutionError,
]


Expand Down
19 changes: 13 additions & 6 deletions integrations-service/integrations/utils/execute_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@

from .. import providers as available_providers
from ..models.base_models import BaseProvider, IdentifierName
from ..models.execution import ExecutionArguments, ExecutionResponse, ExecutionSetup
from ..models.execution import (
ExecutionArguments,
ExecutionError,
ExecutionResponse,
ExecutionSetup,
)


@beartype
Expand Down Expand Up @@ -54,8 +59,10 @@ async def execute_integration(
parsed_arguments = arguments_class(**arguments.model_dump())
else:
parsed_arguments = arguments

if setup_obj:
return await execution_function(setup=setup_obj, arguments=parsed_arguments)
else:
return await execution_function(arguments=parsed_arguments)
try:
if setup_obj:
return await execution_function(setup=setup_obj, arguments=parsed_arguments)
else:
return await execution_function(arguments=parsed_arguments)
except BaseException as e:
return ExecutionError(error=str(e))
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ async def get_live_urls(
setup: BrowserbaseSetup, arguments: BrowserbaseGetSessionLiveUrlsArguments
) -> BrowserbaseGetSessionLiveUrlsOutput:
"""Get the live URLs for a session."""

client = get_browserbase_client(setup)
urls: DebugConnectionURLs = client.get_debug_connection_urls(arguments.id)
return BrowserbaseGetSessionLiveUrlsOutput(urls=urls)
Expand Down Expand Up @@ -159,6 +158,7 @@ async def install_extension_from_github(
setup: BrowserbaseSetup, arguments: BrowserbaseExtensionArguments
) -> BrowserbaseExtensionOutput:
"""Download and install an extension from GitHub to the user's Browserbase account."""

github_url = f"https://github.com/{arguments.repository_name}/archive/refs/tags/{
arguments.ref}.zip"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ async def parse(
"""
Parse and extract content from files using LlamaParse.
"""

assert isinstance(setup, LlamaParseSetup), "Invalid setup"
assert isinstance(arguments, LlamaParseFetchArguments), "Invalid arguments"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
reraise=True,
stop=stop_after_attempt(4),
)
async def search(arguments: WikipediaSearchArguments) -> WikipediaSearchOutput:
async def search(
arguments: WikipediaSearchArguments,
) -> WikipediaSearchOutput:
"""
Searches Wikipedia for a given query and returns formatted results.
"""
Expand Down

0 comments on commit 16a5a51

Please sign in to comment.