Remove successful action history. Only show the failure of the previous step in action history. (#602)

This commit is contained in:
Kerem Yilmaz
2024-07-12 08:57:50 -07:00
committed by GitHub
parent b52be1a597
commit cdd731b862
2 changed files with 5 additions and 3 deletions

View File

@@ -23,7 +23,7 @@ class Settings(BaseSettings):
MAX_RETRIES_PER_STEP: int = 5 MAX_RETRIES_PER_STEP: int = 5
DEBUG_MODE: bool = False DEBUG_MODE: bool = False
DATABASE_STRING: str = "postgresql+psycopg://skyvern@localhost/skyvern" DATABASE_STRING: str = "postgresql+psycopg://skyvern@localhost/skyvern"
PROMPT_ACTION_HISTORY_WINDOW: int = 5 PROMPT_ACTION_HISTORY_WINDOW: int = 1
TASK_RESPONSE_ACTION_SCREENSHOT_COUNT: int = 3 TASK_RESPONSE_ACTION_SCREENSHOT_COUNT: int = 3
ENV: str = "local" ENV: str = "local"

View File

@@ -1017,13 +1017,14 @@ class ForgeAgent:
async def _get_action_results(self, task: Task) -> str: async def _get_action_results(self, task: Task) -> str:
# Get action results from the last app.SETTINGS.PROMPT_ACTION_HISTORY_WINDOW steps # Get action results from the last app.SETTINGS.PROMPT_ACTION_HISTORY_WINDOW steps
steps = await app.DATABASE.get_task_steps(task_id=task.task_id, organization_id=task.organization_id) steps = await app.DATABASE.get_task_steps(task_id=task.task_id, organization_id=task.organization_id)
window_steps = steps[-1 * SettingsManager.get_settings().PROMPT_ACTION_HISTORY_WINDOW :] # the last step is always the newly created one and it should be excluded from the history window
window_steps = steps[-1 - SettingsManager.get_settings().PROMPT_ACTION_HISTORY_WINDOW : -1]
actions_and_results: list[tuple[Action, list[ActionResult]]] = [] actions_and_results: list[tuple[Action, list[ActionResult]]] = []
for window_step in window_steps: for window_step in window_steps:
if window_step.output and window_step.output.actions_and_results: if window_step.output and window_step.output.actions_and_results:
actions_and_results.extend(window_step.output.actions_and_results) actions_and_results.extend(window_step.output.actions_and_results)
# shall we exclude successful actions? # exclude successful action from history
return json.dumps( return json.dumps(
[ [
{ {
@@ -1044,6 +1045,7 @@ class ForgeAgent:
], ],
} }
for action, results in actions_and_results for action, results in actions_and_results
if len(results) > 0 and not results[-1].success
] ]
) )