simodocs

Examples

Browser agent

Each step, take a screenshot and ask Simo three things at once: is the task done, what should happen next, and where is the thing to click. Simo answers with pixel coordinates of your screenshot, ready to pass to the browser. Below the confidence threshold, the agent stops and asks a person.

This example uses Playwright; any tool that can screenshot and click works.

from playwright.sync_api import sync_playwright
from simoai import Client, Choice, Extract, Fill, Locate, Noul, image

c = Client()
TASK = "Subscribe to the newsletter with the email ada@example.com"

QUESTIONS = {
    "done": Noul("The task is complete"),
    "next": Choice("What should the agent do next to complete the task?", {
        "click":  "click an element on the page",
        "type":   "type text into the focused field",
        "scroll": "scroll down to see more of the page",
        "stop":   "the task is complete or cannot be done",
    }, args={
        "click": {"target": Extract("the visible label of the element to click", max_tokens=16)},
        "type":  {"text": Fill("the exact text to type", max_tokens=32)},
    }),
    "where": Locate("the element the agent should click or type into next"),
}

with sync_playwright() as pw:
    page = pw.chromium.launch().new_page(viewport={"width": 1280, "height": 800})
    page.goto("https://example.com/newsletter")
    history = []

    for step in range(15):
        shot = page.screenshot()
        r = c.ask({"task": TASK, "history": "\n".join(history) or "(nothing yet)", "screen": "<image:1>"},
                  QUESTIONS, media=[image(shot)])

        if r["done"].noul > 0.9:
            print("done after", step, "steps")
            break
        nxt = r["next"]
        if nxt.probabilities[nxt.choice] < 0.75:
            print("not sure what to do next:", nxt.probabilities)
            break

        if nxt.choice == "click" and r["where"].center:
            x, y = r["where"].center
            page.mouse.click(x, y)
        elif nxt.choice == "type":
            if r["where"].center:
                page.mouse.click(*r["where"].center)
            page.keyboard.type(nxt.arg_values["text"])
        elif nxt.choice == "scroll":
            page.mouse.wheel(0, 600)
        else:
            break
        history.append(f"{nxt.choice} {nxt.arg_values}")

Why it works

  • One screenshot, three answers. Done-check, next action and target location share one read.
  • Stops instead of guessing. A calibrated probability below 0.75 means the page is ambiguous; a person resolves it rather than the agent clicking at random.
  • History in the state. Listing the steps taken so far keeps the agent from repeating itself.