Skip to content

Commit

Permalink
save the elements tree in the prompt as an artifact (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
LawyZheng authored May 22, 2024
1 parent e6d4302 commit 43823b6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion skyvern/forge/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,13 +763,14 @@ async def _build_and_record_step_prompt(
format=element_tree_format,
)

element_tree_in_prompt: str = scraped_page.build_element_tree(element_tree_format)
extract_action_prompt = prompt_engine.load_prompt(
prompt_template,
navigation_goal=navigation_goal,
navigation_payload_str=json.dumps(task.navigation_payload),
starting_url=starting_url,
current_url=current_url,
elements=scraped_page.build_element_tree(element_tree_format),
elements=element_tree_in_prompt,
data_extraction_goal=task.data_extraction_goal,
action_history=actions_and_results_str,
error_code_mapping_str=(json.dumps(task.error_code_mapping) if task.error_code_mapping else None),
Expand All @@ -791,6 +792,11 @@ async def _build_and_record_step_prompt(
artifact_type=ArtifactType.VISIBLE_ELEMENTS_TREE_TRIMMED,
data=json.dumps(scraped_page.element_tree_trimmed, indent=2).encode(),
)
await app.ARTIFACT_MANAGER.create_artifact(
step=step,
artifact_type=ArtifactType.VISIBLE_ELEMENTS_TREE_IN_PROMPT,
data=element_tree_in_prompt.encode(),
)

return scraped_page, extract_action_prompt

Expand Down
1 change: 1 addition & 0 deletions skyvern/forge/sdk/artifact/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ArtifactType(StrEnum):
VISIBLE_ELEMENTS_ID_XPATH_MAP = "visible_elements_id_xpath_map"
VISIBLE_ELEMENTS_TREE = "visible_elements_tree"
VISIBLE_ELEMENTS_TREE_TRIMMED = "visible_elements_tree_trimmed"
VISIBLE_ELEMENTS_TREE_IN_PROMPT = "visible_elements_tree_in_prompt"

# DEPRECATED. pls use HTML_SCRAPE or HTML_ACTION
HTML = "html"
Expand Down
1 change: 1 addition & 0 deletions skyvern/forge/sdk/artifact/storage/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
ArtifactType.VISIBLE_ELEMENTS_ID_XPATH_MAP: "json",
ArtifactType.VISIBLE_ELEMENTS_TREE: "json",
ArtifactType.VISIBLE_ELEMENTS_TREE_TRIMMED: "json",
ArtifactType.VISIBLE_ELEMENTS_TREE_IN_PROMPT: "txt",
ArtifactType.HTML_SCRAPE: "html",
ArtifactType.HTML_ACTION: "html",
ArtifactType.TRACE: "zip",
Expand Down

0 comments on commit 43823b6

Please sign in to comment.