Skip to content
Open
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
1 change: 1 addition & 0 deletions stagehand/handlers/observe_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ async def observe(
logger=self.logger,
log_inference_to_file=False, # TODO: Implement logging to file if needed
from_act=from_act,
variables= options.variables
)

# Extract metrics from response
Expand Down
2 changes: 2 additions & 0 deletions stagehand/llm/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def observe(
logger: Optional[Callable] = None,
log_inference_to_file: bool = False,
from_act: bool = False,
variables = {}
) -> dict[str, Any]:
"""
Call LLM to find elements in the DOM/accessibility tree based on an instruction.
Expand All @@ -54,6 +55,7 @@ def observe(
user_prompt = build_observe_user_message(
instruction=instruction,
tree_elements=tree_elements,
variables = variables
)

messages = [
Expand Down
7 changes: 6 additions & 1 deletion stagehand/llm/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,17 @@ def build_observe_system_prompt(
def build_observe_user_message(
instruction: str,
tree_elements: str,
variables,
) -> ChatMessage:
tree_or_dom = "Accessibility Tree"
return ChatMessage(
role="user",
content=f"""instruction: {instruction}
{tree_or_dom}: {tree_elements}""",
Below are the variables that are accessible in jinja style in the instruction.
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.
variables: {variables}
{tree_or_dom}: {tree_elements}
""",
)


Expand Down
2 changes: 2 additions & 0 deletions stagehand/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ class ObserveOptions(StagehandBaseModel):
dom_settle_timeout_ms: Optional[int] = None
model_client_options: Optional[dict[str, Any]] = None
iframes: Optional[bool] = None
variables: Optional[dict[str, str]] = None



class ObserveResult(StagehandBaseModel):
Expand Down