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
17 changes: 14 additions & 3 deletions nodejs/docs/api/class-page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,18 @@ await page.agent(options);
- `cacheOutFile` [string] *(optional)*

When specified, generated entries are written into the `cacheOutFile` instead of updating the `cacheFile`.
- `maxTokens` [number] *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="page-agent-option-max-tokens"/><a href="#page-agent-option-max-tokens" class="list-anchor">#</a>
- `maxTurns` [number] *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="page-agent-option-max-turns"/><a href="#page-agent-option-max-turns" class="list-anchor">#</a>
- `limits` [Object] *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="page-agent-option-limits"/><a href="#page-agent-option-limits" class="list-anchor">#</a>
- `maxTokens` [number] *(optional)*

Maximum number of tokens to consume. The agentic loop will stop after input + output tokens exceed this value. Defaults to unlimited.
- `maxActions` [number] *(optional)*

Maximum number of agentic actions to generate, defaults to 10.
- `maxActionRetries` [number] *(optional)*

Maximum number retries per action, defaults to 3.

Maximum number of agentic turns to take per call. Defaults to 10.
Limits to use for the agentic loop.
- `provider` [Object] *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="page-agent-option-provider"/><a href="#page-agent-option-provider" class="list-anchor">#</a>
- `api` "openai" | "openai-compatible" | "anthropic" | "google"

Expand All @@ -293,6 +301,9 @@ await page.agent(options);
- `apiKey` [string]

API key for the LLM provider.
- `apiTimeout` [number] *(optional)*

Amount of time to wait for the provider to respond to each request.
- `model` [string]

Model identifier within the provider. Required in non-cache mode.
Expand Down
53 changes: 44 additions & 9 deletions nodejs/docs/api/class-pageagent.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ await agent.expect('"0 items" to be reported');
- `cacheKey` [string] *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="page-agent-expect-option-cache-key"/><a href="#page-agent-expect-option-cache-key" class="list-anchor">#</a>

All the agentic actions are converted to the Playwright calls and are cached. By default, they are cached globally with the `task` as a key. This option allows controlling the cache key explicitly.
- `maxActionRetries` [number] *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="page-agent-expect-option-max-action-retries"/><a href="#page-agent-expect-option-max-action-retries" class="list-anchor">#</a>

Maximum number of retries when generating each action, defaults to context-wide value specified in `agent` property.
- `maxActions` [number] *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="page-agent-expect-option-max-actions"/><a href="#page-agent-expect-option-max-actions" class="list-anchor">#</a>

Maximum number of agentic actions to generate, defaults to context-wide value specified in `agent` property.
- `maxTokens` [number] *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="page-agent-expect-option-max-tokens"/><a href="#page-agent-expect-option-max-tokens" class="list-anchor">#</a>

Maximum number of tokens to consume. The agentic loop will stop after input + output tokens exceed this value. Defaults to context-wide value specified in `agent` property.
- `maxTurns` [number] *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="page-agent-expect-option-max-turns"/><a href="#page-agent-expect-option-max-turns" class="list-anchor">#</a>

Maximum number of agentic turns during this call, defaults to context-wide value specified in `agent` property.
- `timeout` [number] *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="page-agent-expect-option-timeout"/><a href="#page-agent-expect-option-timeout" class="list-anchor">#</a>

Request timeout in milliseconds. Defaults to action timeout. Pass `0` to disable timeout.
Expand Down Expand Up @@ -88,12 +91,15 @@ await agent.extract('List of items in the cart', z.object({
- `cacheKey` [string] *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="page-agent-extract-option-cache-key"/><a href="#page-agent-extract-option-cache-key" class="list-anchor">#</a>

All the agentic actions are converted to the Playwright calls and are cached. By default, they are cached globally with the `task` as a key. This option allows controlling the cache key explicitly.
- `maxActionRetries` [number] *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="page-agent-extract-option-max-action-retries"/><a href="#page-agent-extract-option-max-action-retries" class="list-anchor">#</a>

Maximum number of retries when generating each action, defaults to context-wide value specified in `agent` property.
- `maxActions` [number] *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="page-agent-extract-option-max-actions"/><a href="#page-agent-extract-option-max-actions" class="list-anchor">#</a>

Maximum number of agentic actions to generate, defaults to context-wide value specified in `agent` property.
- `maxTokens` [number] *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="page-agent-extract-option-max-tokens"/><a href="#page-agent-extract-option-max-tokens" class="list-anchor">#</a>

Maximum number of tokens to consume. The agentic loop will stop after input + output tokens exceed this value. Defaults to context-wide value specified in `agent` property.
- `maxTurns` [number] *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="page-agent-extract-option-max-turns"/><a href="#page-agent-extract-option-max-turns" class="list-anchor">#</a>

Maximum number of agentic turns during this call, defaults to context-wide value specified in `agent` property.
- `timeout` [number] *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="page-agent-extract-option-timeout"/><a href="#page-agent-extract-option-timeout" class="list-anchor">#</a>

Request timeout in milliseconds. Defaults to action timeout. Pass `0` to disable timeout.
Expand Down Expand Up @@ -136,12 +142,15 @@ await agent.perform('Click submit button');
- `cacheKey` [string] *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="page-agent-perform-option-cache-key"/><a href="#page-agent-perform-option-cache-key" class="list-anchor">#</a>

All the agentic actions are converted to the Playwright calls and are cached. By default, they are cached globally with the `task` as a key. This option allows controlling the cache key explicitly.
- `maxActionRetries` [number] *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="page-agent-perform-option-max-action-retries"/><a href="#page-agent-perform-option-max-action-retries" class="list-anchor">#</a>

Maximum number of retries when generating each action, defaults to context-wide value specified in `agent` property.
- `maxActions` [number] *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="page-agent-perform-option-max-actions"/><a href="#page-agent-perform-option-max-actions" class="list-anchor">#</a>

Maximum number of agentic actions to generate, defaults to context-wide value specified in `agent` property.
- `maxTokens` [number] *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="page-agent-perform-option-max-tokens"/><a href="#page-agent-perform-option-max-tokens" class="list-anchor">#</a>

Maximum number of tokens to consume. The agentic loop will stop after input + output tokens exceed this value. Defaults to context-wide value specified in `agent` property.
- `maxTurns` [number] *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="page-agent-perform-option-max-turns"/><a href="#page-agent-perform-option-max-turns" class="list-anchor">#</a>

Maximum number of agentic turns during this call, defaults to context-wide value specified in `agent` property.
- `timeout` [number] *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="page-agent-perform-option-timeout"/><a href="#page-agent-perform-option-timeout" class="list-anchor">#</a>

Request timeout in milliseconds. Defaults to action timeout. Pass `0` to disable timeout.
Expand All @@ -159,6 +168,32 @@ await agent.perform('Click submit button');



---

### usage {#page-agent-usage}

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.58</font><x-search>pageAgent.usage</x-search>

Returns the current token usage for this agent.

**Usage**

```js
const usage = await agent.usage();
console.log(`Tokens used: ${usage.inputTokens} in, ${usage.outputTokens} out`);
```

**Returns**
- [Promise]&lt;[Object]&gt;<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="page-agent-usage-return"/><a href="#page-agent-usage-return" class="list-anchor">#</a>
- `turns` [number]


- `inputTokens` [number]


- `outputTokens` [number]


---

## Events
Expand Down
43 changes: 29 additions & 14 deletions nodejs/docs/api/class-testoptions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -104,30 +104,45 @@ testOptions.agentOptions

**Type**
- [Object]
- `api` [string] *(optional)*

LLM provider to use. Required in non-cache mode.
- `apiKey` [string] *(optional)*

Key for the LLM provider.
- `apiEndpoint` [string] *(optional)*
- `provider` [Object]
- `api` "openai" | "openai-compatible" | "anthropic" | "google"

API to use.
- `apiEndpoint` [string] *(optional)*

Endpoint to use if different from default.
- `apiKey` [string]

API key for the LLM provider.
- `apiTimeout` [number] *(optional)*

Amount of time to wait for the provider to respond to each request.
- `model` [string]

Model identifier within the provider. Required in non-cache mode.

LLM provider endpoint.
- `model` [string] *(optional)*

Model identifier within the provider. Required in non-cache mode.
- `cachePathTemplate` [string] *(optional)*

Cache file template to use/generate code for performed actions into.
- `maxTurns` [number] *(optional)*
- `limits` [Object]
- `maxTokens` [number] *(optional)*

Maximum number of tokens to consume. The agentic loop will stop after input + output tokens exceed this value. Defaults to unlimited.
- `maxActions` [number] *(optional)*

Maximum number of agentic actions to generate, defaults to 10.
- `maxActionRetries` [number] *(optional)*

Maximum number retries per action, defaults to 3.

Maximum number of agentic turns to take per call. Defaults to 10.
- `maxTokens` [number] *(optional)*

Maximum number of tokens to consume per call. The agentic loop will stop after input + output tokens exceed this value. Defaults on unlimited.
- `secrets` [Object]&lt;[string], [string]&gt; *(optional)*

Secrets to hide from the LLM.
- `systemPrompt` [string]

System prompt for the agent's loop.

---

Expand Down