fix: add variable substitution to keys step during cache replay

Closed
A7
7mo ago
+30-11

Fixes #1776

Problem

The keys tool has no variable substitution in either the live execution or cache replay paths. When the agent uses %variableName% tokens with the keys tool, the literal token string gets typed instead of the resolved value.

Fix

This PR combines two fixes into one:

1. Live execution (original fix by @trillville from #1777)

  • Accept variables parameter in keysTool (matching typeTool)
  • Call substituteVariables() before page.type() in the method === "type" branch
  • Pass variables to keysTool in createAgentTools
  • Update schema description to advertise available variables to the LLM
  • Return original token in result to avoid exposing sensitive values to LLM

2. Cache replay (new fix)

  • Import substituteVariables in AgentCache.ts
  • Pass variables through to replayAgentKeysStep
  • Call substituteVariables(text, variables) before page.type() in the replay path

Without fix #2, cached keys steps with method="type" replay by typing literal %variableName% tokens even when variables are provided, since replayAgentKeysStep had no access to the variables map.

Credit

The live execution fix (part 1) is from @trillville's work in #1777/#1813. We merged it here with the cache replay fix per @pirate's request to consolidate into a single PR.