Skip to content

Commit 9ce4efd

Browse files
committed
Accept both %-wrapped and non-wrapped variable arguments in act
1 parent a0f947a commit 9ce4efd

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "stagehand"
7-
version = "0.5.10"
7+
version = "0.5.11"
88
description = "Python SDK for Stagehand"
99
readme = "README.md"
1010
classifiers = [ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent",]

stagehand/handlers/act_handler.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,16 @@ async def act(self, options: Union[ActOptions, ObserveResult]) -> ActResult:
9595
# Substitute variables in arguments
9696
if options.get("variables"):
9797
variables = options.get("variables", {})
98-
element_to_act_on.arguments = [
99-
str(arg).replace(f"{key}", str(value))
100-
for arg in element_to_act_on.arguments or []
101-
for key, value in variables.items()
102-
]
98+
replaced_args = []
99+
for arg in element_to_act_on.arguments or []:
100+
replaced = str(arg)
101+
for key, value in variables.items():
102+
if f"%{key}%" in replaced:
103+
replaced = replaced.replace(f"%{key}%", str(value))
104+
else:
105+
replaced = replaced.replace(key, str(value))
106+
replaced_args.append(replaced)
107+
element_to_act_on.arguments = replaced_args
103108

104109
# domSettleTimeoutMs might come from options if specified for act
105110
dom_settle_timeout_ms = options.get("dom_settle_timeout_ms")

stagehand/llm/prompts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def build_act_observe_prompt(
205205
If the action implies choosing an option from a dropdown, and the corresponding element is NOT a 'select' element, choose the click method."""
206206

207207
if variables and len(variables) > 0:
208-
variables_prompt = f"The following variables are available to use in the action: {', '.join(variables.keys())}. Fill the argument variables with the variable name."
208+
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."
209209
instruction += f" {variables_prompt}"
210210

211211
return instruction

0 commit comments

Comments
 (0)