adding step_exception to provide more signal of why the step failed (#730)

This commit is contained in:
Kerem Yilmaz
2024-08-28 11:06:04 +03:00
committed by GitHub
parent 6f4ff4339f
commit a6a545224a
4 changed files with 14 additions and 3 deletions

View File

@@ -583,6 +583,7 @@ class ForgeAgent:
actions=actions, actions=actions,
action_results=[], action_results=[],
actions_and_results=[], actions_and_results=[],
step_exception=None,
) )
return step, detailed_agent_step_output return step, detailed_agent_step_output
@@ -776,13 +777,14 @@ class ForgeAgent:
step_order=step.order, step_order=step.order,
step_retry=step.retry_index, step_retry=step.retry_index,
) )
detailed_agent_step_output.step_exception = "CancelledError"
failed_step = await self.update_step( failed_step = await self.update_step(
step=step, step=step,
status=StepStatus.failed, status=StepStatus.failed,
output=detailed_agent_step_output.to_agent_step_output(), output=detailed_agent_step_output.to_agent_step_output(),
) )
return failed_step, detailed_agent_step_output.get_clean_detailed_output() return failed_step, detailed_agent_step_output.get_clean_detailed_output()
except Exception: except Exception as e:
LOG.exception( LOG.exception(
"Unexpected exception in agent_step, marking step as failed", "Unexpected exception in agent_step, marking step as failed",
task_id=task.task_id, task_id=task.task_id,
@@ -790,6 +792,7 @@ class ForgeAgent:
step_order=step.order, step_order=step.order,
step_retry=step.retry_index, step_retry=step.retry_index,
) )
detailed_agent_step_output.step_exception = e.__class__.__name__
failed_step = await self.update_step( failed_step = await self.update_step(
step=step, step=step,
status=StepStatus.failed, status=StepStatus.failed,
@@ -882,6 +885,7 @@ class ForgeAgent:
actions=None, actions=None,
action_results=None, action_results=None,
actions_and_results=None, actions_and_results=None,
step_exception=None,
) )
return step, browser_state, detailed_output return step, browser_state, detailed_output

View File

@@ -14,6 +14,7 @@ from skyvern.forge.sdk.api.llm.exceptions import (
DuplicateCustomLLMProviderError, DuplicateCustomLLMProviderError,
InvalidLLMConfigError, InvalidLLMConfigError,
LLMProviderError, LLMProviderError,
LLMProviderErrorRetryableTask,
) )
from skyvern.forge.sdk.api.llm.models import LLMAPIHandler, LLMConfig, LLMRouterConfig from skyvern.forge.sdk.api.llm.models import LLMAPIHandler, LLMConfig, LLMRouterConfig
from skyvern.forge.sdk.api.llm.utils import llm_messages_builder, parse_api_response from skyvern.forge.sdk.api.llm.utils import llm_messages_builder, parse_api_response
@@ -211,8 +212,8 @@ class LLMAPIHandlerFactory:
**active_parameters, **active_parameters,
) )
LOG.info("LLM API call successful", llm_key=llm_key, model=llm_config.model_name) LOG.info("LLM API call successful", llm_key=llm_key, model=llm_config.model_name)
except openai.OpenAIError as e: except litellm.exceptions.APIError as e:
raise LLMProviderError(llm_key) from e raise LLMProviderErrorRetryableTask(llm_key) from e
except CancelledError: except CancelledError:
t_llm_cancelled = time.perf_counter() t_llm_cancelled = time.perf_counter()
LOG.error( LOG.error(

View File

@@ -40,6 +40,11 @@ class LLMProviderError(BaseLLMError):
super().__init__(f"Error while using LLMProvider {llm_key}") super().__init__(f"Error while using LLMProvider {llm_key}")
class LLMProviderErrorRetryableTask(LLMProviderError):
def __init__(self, llm_key: str) -> None:
super().__init__(f"Retryable error while using LLMProvider {llm_key}")
class NoProviderEnabledError(BaseLLMError): class NoProviderEnabledError(BaseLLMError):
def __init__(self) -> None: def __init__(self) -> None:
super().__init__( super().__init__(

View File

@@ -39,6 +39,7 @@ class DetailedAgentStepOutput(BaseModel):
actions: list[Action] | None actions: list[Action] | None
action_results: list[ActionResult] | None action_results: list[ActionResult] | None
actions_and_results: list[tuple[Action, list[ActionResult]]] | None actions_and_results: list[tuple[Action, list[ActionResult]]] | None
step_exception: str | None = None
class Config: class Config:
exclude = ["scraped_page", "extract_action_prompt"] exclude = ["scraped_page", "extract_action_prompt"]