Skip to main content

runAgent()

Execute an AI agent with a natural language instruction.

Signature

runAgent(prompt: string, context: BrowserContext, options?: RunAgentOptions): Promise<string>

Parameters

ParameterTypeRequiredDescription
promptstringYesNatural language instruction
contextBrowserContextYesPlaywright browser context
optionsobjectNoConfiguration options

Options

OptionTypeDefaultDescription
verbosebooleantrueEnable console logging
agentTypestring'claude'Agent backend: 'claude' or 'langchain'
providerstring'anthropic'LLM provider: 'anthropic', 'openai', 'google'
modelstring-Override default model name
recursionLimitnumber100Max agent recursion depth
returnUsagebooleanfalseReturn usage statistics
modelConfigobject-Additional model configuration

Returns

  • Default: Promise<string> — Final agent response
  • With returnUsage: true: Promise<{ result: string, usage: object }> — Response with token usage

Examples

Basic Usage

import { runAgent } from "openqa";

test("example", async ({ context }) => {
  const result = await runAgent("Click the login button", context);
});

With Options

await runAgent("Fill the form", context, {
  verbose: false,
  agentType: "langchain",
  provider: "openai",
  model: "gpt-4o"
});

Using Different Agents

await runAgent("Click submit", context);
// Uses Claude Agent SDK

Session Management

Reset agent session for a browser context:
await runAgent.resetSession(context);

Direct Agent Access

Import individual agents directly:
import { runClaudeAgent, runLangChainAgent } from "openqa";

// Use Claude Agent SDK directly
await runClaudeAgent(prompt, context, options);

// Use LangChain agent directly
await runLangChainAgent(prompt, context, options);