Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "stagehand"
version = "0.5.10"
version = "0.5.11"
description = "Python SDK for Stagehand"
readme = "README.md"
classifiers = [ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent",]
Expand Down
15 changes: 10 additions & 5 deletions stagehand/handlers/act_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,16 @@ async def act(self, options: Union[ActOptions, ObserveResult]) -> ActResult:
# Substitute variables in arguments
if options.get("variables"):
variables = options.get("variables", {})
element_to_act_on.arguments = [
str(arg).replace(f"{key}", str(value))
for arg in element_to_act_on.arguments or []
for key, value in variables.items()
]
replaced_args = []
for arg in element_to_act_on.arguments or []:
replaced = str(arg)
for key, value in variables.items():
if f"%{key}%" in replaced:
replaced = replaced.replace(f"%{key}%", str(value))
else:
replaced = replaced.replace(key, str(value))
replaced_args.append(replaced)
element_to_act_on.arguments = replaced_args

# domSettleTimeoutMs might come from options if specified for act
dom_settle_timeout_ms = options.get("dom_settle_timeout_ms")
Expand Down
2 changes: 1 addition & 1 deletion stagehand/llm/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def build_act_observe_prompt(
If the action implies choosing an option from a dropdown, and the corresponding element is NOT a 'select' element, choose the click method."""

if variables and len(variables) > 0:
variables_prompt = f"The following variables are available to use in the action: {', '.join(variables.keys())}. Fill the argument variables with the variable name."
variables_prompt = f"The following variables are available to use in the action: {', '.join(variables.keys())}. Fill the argument variables with the variable name. Wrap the argument in % symbols."
instruction += f" {variables_prompt}"

return instruction
Expand Down