Skip to content

keys tool does not perform variable substitution #1776

Closed

Description

@trillville

Environment Information

Stagehand:

  • Language/SDK: TypeScript
  • Stagehand version: 3.1.0

AI Provider:

  • Provider: Anthropic
  • Model: claude-sonnet-4-6

Issue Description

The keys tool with method: "type" does not call substituteVariables() before typing, so %variableName% tokens are typed literally instead of being resolved. The type tool correctly calls
https://github.com/browserbase/stagehand/blob/main/lib/v3/agent/tools/type.ts#L28, but the keys tool sends the raw value directly to https://github.com/browserbase/stagehand/blob/main/lib/v3/agent/tools/keys.ts#L33.

Additionally, variables is passed to type, act, fillForm, and fillFormVision in
https://github.com/browserbase/stagehand/blob/main/lib/v3/agent/tools/index.ts, but not to keys.

This is somewhat easy to trigger in practice: when the agent needs to clear an existing field value before typing a new one, it naturally uses the keys tool for the whole flow (Ctrl+A → Delete → type), and the final type step skips substitution.

Steps to Reproduce

  1. Create an agent with variables (e.g. { token: "my-secret-value" })
  2. Give it a task that involves clearing an existing input field and replacing it with %token%
  3. The agent uses keys for the flow: keys(press, Ctrl+A) → keys(press, Delete) → keys(type, %token%)
  4. The literal string %token% is typed instead of my-secret-value

Suggested fix

In keys.ts, the keysTool factory should accept variables (like typeTool does) and substitute before typing

Activity

  1. added a commit that references this issue on Apr 9, 2026
    8543c11
  2. added a commit that references this issue on Aug 4, 2026
    f65d00e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions