Skip to content

Commit 0bf42bd

Browse files
Kushal PatilKushal Patil
authored andcommitted
updated observe to handle my variables as well
1 parent ad95605 commit 0bf42bd

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

stagehand/handlers/observe_handler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ async def observe(
8282
logger=self.logger,
8383
log_inference_to_file=False, # TODO: Implement logging to file if needed
8484
from_act=from_act,
85+
variables= options.variables
8586
)
8687

8788
# Extract metrics from response

stagehand/llm/inference.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def observe(
2929
logger: Optional[Callable] = None,
3030
log_inference_to_file: bool = False,
3131
from_act: bool = False,
32+
variables = {}
3233
) -> dict[str, Any]:
3334
"""
3435
Call LLM to find elements in the DOM/accessibility tree based on an instruction.
@@ -54,6 +55,7 @@ def observe(
5455
user_prompt = build_observe_user_message(
5556
instruction=instruction,
5657
tree_elements=tree_elements,
58+
variables = variables
5759
)
5860

5961
messages = [

stagehand/llm/prompts.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,18 @@ def build_observe_system_prompt(
177177
def build_observe_user_message(
178178
instruction: str,
179179
tree_elements: str,
180+
variables,
180181
) -> ChatMessage:
181182
tree_or_dom = "Accessibility Tree"
183+
print("###############", variables)
182184
return ChatMessage(
183185
role="user",
184186
content=f"""instruction: {instruction}
185-
{tree_or_dom}: {tree_elements}""",
187+
Below are the variables that are accessible in jinja style in the instruction.
188+
For the 'fill' and 'type' instructions, don't replace the variables in the response. For the rest of the actions please do. In the response in the arguments try and use the same jinja style variables that are in the instruction, if it is suitable.
189+
variables: {variables}
190+
{tree_or_dom}: {tree_elements}
191+
""",
186192
)
187193

188194

stagehand/schemas.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ class ObserveOptions(StagehandBaseModel):
199199
dom_settle_timeout_ms: Optional[int] = None
200200
model_client_options: Optional[dict[str, Any]] = None
201201
iframes: Optional[bool] = None
202+
variables: Optional[dict[str, str]] = None
203+
202204

203205

204206
class ObserveResult(StagehandBaseModel):

0 commit comments

Comments
 (0)