Skip to content

Accept instruction and schema positionally in Python observe and extract - #2539

Merged
miguelg719 merged 1 commit into
v4-spikefrom
v4-spike-python-positional
Aug 3, 2026
Merged

Accept instruction and schema positionally in Python observe and extract#2539
miguelg719 merged 1 commit into
v4-spikefrom
v4-spike-python-positional

Conversation

@miguelg719

@miguelg719 miguelg719 commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • move instruction (and schema) ahead of the bare * in Stagehand.observe and Stagehand.extract, matching act and the TypeScript and Go SDKs
  • update the 61 Python call sites in the examples, README, and v4 docs to the positional form
  • correct the AI-rules line that told assistants observe and extract take keyword-only arguments
  • add a signature test so act/observe/extract cannot drift back to keyword-only

Backward compatible: callers already passing these as keywords are unaffected.

Validation

  • ruff format --check, ruff check, ty check
  • pytest (211 passed)
  • vitest run rules/ast-grep packages/docs/tests (42 passed)

@miguelg719
miguelg719 requested a review from a team as a code owner July 31, 2026 20:02
@changeset-bot

changeset-bot Bot commented Jul 31, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 7daa322

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 16 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.
Architecture diagram
sequenceDiagram
    participant Caller as Python SDK Caller
    participant Stagehand as Stagehand Class
    participant Test as Signature Test (pytest)

    Note over Caller,Stagehand: NEW: Positional calling convention

    Caller->>Stagehand: observe("Find the button")  NEW: positional instruction
    Stagehand->>Stagehand: process observe
    Stagehand-->>Caller: ObserveResult

    Caller->>Stagehand: extract("Get title", PageInfo)  NEW: pos instruction+schema
    Stagehand->>Stagehand: execute extraction
    Stagehand-->>Caller: ExtractResult

    alt Keyword‑only (unchanged)
        Caller->>Stagehand: observe(instruction="...", selector="...")
    end

    Note over Test: Enforces POSITIONAL_OR_KEYWORD before *

    Test->>Stagehand: inspect.signature(observe)
    Test-->>Test: assert 1st param is positional (instruction)
    Test->>Stagehand: inspect.signature(extract)
    Test-->>Test: assert 1st & 2nd params are positional (instruction, schema)
    Test->>Stagehand: inspect.signature(act)
    Test-->>Test: assert first param is positional (instruction)

    Note over Test: All remaining params must be KEYWORD_ONLY
Loading

Re-trigger cubic

@miguelg719
miguelg719 force-pushed the v4-spike-python-positional branch from 6122801 to e4deddb Compare August 3, 2026 05:17
…and extract

Stagehand.observe and Stagehand.extract made instruction (and schema)
keyword-only, while Stagehand.act and both the TypeScript and Go SDKs take
them positionally. Move them ahead of the bare * so required semantic
arguments are positional in every language, with options keyword-only.

Backward compatible for callers already passing them as keywords. Updates
the Python examples, README, and v4 docs snippets to the positional form,
and adds a signature test so act/observe/extract cannot drift back.
@miguelg719
miguelg719 force-pushed the v4-spike-python-positional branch from afe2307 to 7daa322 Compare August 3, 2026 21:54
@miguelg719
miguelg719 merged commit 7580caa into v4-spike Aug 3, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants