Skip to content
Merged
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
5 changes: 5 additions & 0 deletions docs/src/api/class-page.md
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,11 @@ Maximum number of agentic turns to take per call. Defaults to 10.

Secrets to hide from the LLM.

### option: Page.agent.systemPrompt
* since: v1.58
- `systemPrompt` <[string]>

System prompt for the agent's loop.

## async method: Page.bringToFront
* since: v1.8
Expand Down
5 changes: 5 additions & 0 deletions packages/playwright-client/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2143,6 +2143,11 @@ export interface Page {
* Secrets to hide from the LLM.
*/
secrets?: { [key: string]: string; };

/**
* System prompt for the agent's loop.
*/
systemPrompt?: string;
}): Promise<PageAgent>;

/**
Expand Down
1 change: 1 addition & 0 deletions packages/playwright-core/src/client/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,7 @@ export class Page extends ChannelOwner<channels.PageChannel> implements api.Page
maxTokens: options.maxTokens,
maxTurns: options.maxTurns,
secrets: options.secrets ? Object.entries(options.secrets).map(([name, value]) => ({ name, value })) : undefined,
systemPrompt: options.systemPrompt,
};
const { agent } = await this._channel.agent(params);
return PageAgent.from(agent);
Expand Down
5 changes: 3 additions & 2 deletions packages/playwright-core/src/protocol/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1491,12 +1491,13 @@ scheme.PageAgentParams = tObject({
api: tOptional(tString),
apiKey: tOptional(tString),
apiEndpoint: tOptional(tString),
model: tOptional(tString),
cacheFile: tOptional(tString),
cacheOutFile: tOptional(tString),
secrets: tOptional(tArray(tType('NameValue'))),
maxTurns: tOptional(tInt),
maxTokens: tOptional(tInt),
model: tOptional(tString),
secrets: tOptional(tArray(tType('NameValue'))),
systemPrompt: tOptional(tString),
});
scheme.PageAgentResult = tObject({
agent: tChannel(['PageAgent']),
Expand Down
24 changes: 17 additions & 7 deletions packages/playwright-core/src/server/agent/pageAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,26 @@ async function runLoop(progress: Progress, context: Context, toolDefinitions: To
...context.events,
});

const task = `${userTask}
const task: string[] = [];
if (context.agentParams.systemPrompt) {
task.push('### System');
task.push(context.agentParams.systemPrompt);
task.push('');
}

### Context history
${context.history.map(h => `- ${h.type}: ${h.description}`).join('\n')}
task.push('### Task');
task.push(userTask);

### Page snapshot
${full}
`;
if (context.history.length) {
task.push('### Context history');
task.push(context.history.map(h => `- ${h.type}: ${h.description}`).join('\n'));
task.push('');
}
task.push('### Page snapshot');
task.push(full);
task.push('');
await loop.run(task.join('\n'));

await loop.run(task);
return { result: resultSchema ? reportedResult() : undefined };
}

Expand Down
5 changes: 5 additions & 0 deletions packages/playwright-core/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2143,6 +2143,11 @@ export interface Page {
* Secrets to hide from the LLM.
*/
secrets?: { [key: string]: string; };

/**
* System prompt for the agent's loop.
*/
systemPrompt?: string;
}): Promise<PageAgent>;

/**
Expand Down
10 changes: 6 additions & 4 deletions packages/protocol/src/channels.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2586,23 +2586,25 @@ export type PageAgentParams = {
api?: string,
apiKey?: string,
apiEndpoint?: string,
model?: string,
cacheFile?: string,
cacheOutFile?: string,
secrets?: NameValue[],
maxTurns?: number,
maxTokens?: number,
model?: string,
secrets?: NameValue[],
systemPrompt?: string,
};
export type PageAgentOptions = {
api?: string,
apiKey?: string,
apiEndpoint?: string,
model?: string,
cacheFile?: string,
cacheOutFile?: string,
secrets?: NameValue[],
maxTurns?: number,
maxTokens?: number,
model?: string,
secrets?: NameValue[],
systemPrompt?: string,
};
export type PageAgentResult = {
agent: PageAgentChannel,
Expand Down
7 changes: 4 additions & 3 deletions packages/protocol/src/protocol.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2019,14 +2019,15 @@ Page:
api: string?
apiKey: string?
apiEndpoint: string?
model: string?
cacheFile: string?
cacheOutFile: string?
maxTurns: int?
maxTokens: int?
model: string?
secrets:
type: array?
items: NameValue
maxTurns: int?
maxTokens: int?
systemPrompt: string?
returns:
agent: PageAgent

Expand Down
24 changes: 12 additions & 12 deletions tests/playwright-test/stable-test-runner/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/playwright-test/stable-test-runner/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"private": true,
"dependencies": {
"@playwright/test": "^1.58.0-alpha-1767864918000"
"@playwright/test": "^1.58.0-alpha-2026-01-12"
}
}
Loading