diff --git a/nodejs/docs/api/class-page.mdx b/nodejs/docs/api/class-page.mdx
index 0dcd73857f..ad5637ee4a 100644
--- a/nodejs/docs/api/class-page.mdx
+++ b/nodejs/docs/api/class-page.mdx
@@ -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)*#
- - `maxTurns` [number] *(optional)*#
+ - `limits` [Object] *(optional)*#
+ - `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)*#
- `api` "openai" | "openai-compatible" | "anthropic" | "google"
@@ -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.
diff --git a/nodejs/docs/api/class-pageagent.mdx b/nodejs/docs/api/class-pageagent.mdx
index 7d3bddf5fd..f2820ede7d 100644
--- a/nodejs/docs/api/class-pageagent.mdx
+++ b/nodejs/docs/api/class-pageagent.mdx
@@ -49,12 +49,15 @@ await agent.expect('"0 items" to be reported');
- `cacheKey` [string] *(optional)*#
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)*#
+
+ Maximum number of retries when generating each action, defaults to context-wide value specified in `agent` property.
+ - `maxActions` [number] *(optional)*#
+
+ Maximum number of agentic actions to generate, defaults to context-wide value specified in `agent` property.
- `maxTokens` [number] *(optional)*#
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)*#
-
- Maximum number of agentic turns during this call, defaults to context-wide value specified in `agent` property.
- `timeout` [number] *(optional)*#
Request timeout in milliseconds. Defaults to action timeout. Pass `0` to disable timeout.
@@ -88,12 +91,15 @@ await agent.extract('List of items in the cart', z.object({
- `cacheKey` [string] *(optional)*#
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)*#
+
+ Maximum number of retries when generating each action, defaults to context-wide value specified in `agent` property.
+ - `maxActions` [number] *(optional)*#
+
+ Maximum number of agentic actions to generate, defaults to context-wide value specified in `agent` property.
- `maxTokens` [number] *(optional)*#
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)*#
-
- Maximum number of agentic turns during this call, defaults to context-wide value specified in `agent` property.
- `timeout` [number] *(optional)*#
Request timeout in milliseconds. Defaults to action timeout. Pass `0` to disable timeout.
@@ -136,12 +142,15 @@ await agent.perform('Click submit button');
- `cacheKey` [string] *(optional)*#
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)*#
+
+ Maximum number of retries when generating each action, defaults to context-wide value specified in `agent` property.
+ - `maxActions` [number] *(optional)*#
+
+ Maximum number of agentic actions to generate, defaults to context-wide value specified in `agent` property.
- `maxTokens` [number] *(optional)*#
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)*#
-
- Maximum number of agentic turns during this call, defaults to context-wide value specified in `agent` property.
- `timeout` [number] *(optional)*#
Request timeout in milliseconds. Defaults to action timeout. Pass `0` to disable timeout.
@@ -159,6 +168,32 @@ await agent.perform('Click submit button');
+---
+
+### usage {#page-agent-usage}
+
+Added in: v1.58pageAgent.usage
+
+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]<[Object]>#
+ - `turns` [number]
+
+
+ - `inputTokens` [number]
+
+
+ - `outputTokens` [number]
+
+
---
## Events
diff --git a/nodejs/docs/api/class-testoptions.mdx b/nodejs/docs/api/class-testoptions.mdx
index b42e1b9f42..9a34db6242 100644
--- a/nodejs/docs/api/class-testoptions.mdx
+++ b/nodejs/docs/api/class-testoptions.mdx
@@ -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]<[string], [string]> *(optional)*
Secrets to hide from the LLM.
+ - `systemPrompt` [string]
+
+ System prompt for the agent's loop.
---