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

remove unnecessary info in action result history #248

Merged
merged 1 commit into from
May 8, 2024
Merged
Changes from all commits
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
47 changes: 34 additions & 13 deletions skyvern/forge/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,20 +616,9 @@ async def _build_and_record_step_prompt(
num_elements=len(scraped_page.elements),
url=task.url,
)
# 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)
window_steps = steps[-1 * SettingsManager.get_settings().PROMPT_ACTION_HISTORY_WINDOW :]
actions_and_results: list[tuple[ActionTypeUnion, list[ActionResult]]] = []
for window_step in window_steps:
if window_step.output and window_step.output.actions_and_results:
actions_and_results.extend(window_step.output.actions_and_results)

actions_and_results_str = json.dumps(
[
{"action": action.model_dump(), "results": [result.model_dump() for result in results]}
for action, results in actions_and_results
]
)
actions_and_results_str = await self._get_action_results(task)

# Generate the extract action prompt
navigation_goal = task.navigation_goal
starting_url = task.url
Expand Down Expand Up @@ -673,6 +662,38 @@ async def _build_and_record_step_prompt(

return scraped_page, extract_action_prompt

async def _get_action_results(self, task: Task) -> str:
# 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)
window_steps = steps[-1 * SettingsManager.get_settings().PROMPT_ACTION_HISTORY_WINDOW :]
actions_and_results: list[tuple[ActionTypeUnion, list[ActionResult]]] = []
for window_step in window_steps:
if window_step.output and window_step.output.actions_and_results:
actions_and_results.extend(window_step.output.actions_and_results)

# shall we exclude successful actions?
return json.dumps(
[
{
"action": action.model_dump(exclude_none=True),
"results": [
result.model_dump(
exclude_none=True,
exclude={
"javascript_triggered",
"interacted_with_sibling",
"interacted_with_parent",
"step_retry_number",
"step_order",
},
)
for result in results
],
}
for action, results in actions_and_results
]
)

async def get_extracted_information_for_task(self, task: Task) -> dict[str, Any] | list | str | None:
"""
Find the last successful ScrapeAction for the task and return the extracted information.
Expand Down
Loading