Documentation Index
Fetch the complete documentation index at: https://mintlify.com/alibaba/page-agent/llms.txt
Use this file to discover all available pages before exploring further.
PageAgentCore from @page-agent/core is the headless base class that powers the entire Re-Act agent loop. It owns the LLM client, tool registry, and history stream, but imposes no UI — making it the right foundation for custom-panel implementations, testing harnesses, or server-side orchestration. PageAgent extends this class by adding a floating panel on top.
Import
Constructor
PageAgentCoreConfig is an AgentConfig plus a pageController field:
PageController instance. This separation means you can swap out, mock, or extend the DOM layer independently of the agent logic.
LLM Connection
OpenAI-compatible LLM API base URL, e.g.
https://api.openai.com/v1.Model name to use, e.g.
gpt-4o or qwen-max.API key for the LLM provider.
Agent Behaviour
A
PageController instance that the agent will use for all DOM queries and browser actions.Sets the default working language in the agent system prompt.
Maximum number of Re-Act loop iterations. When the limit is reached the agent sets
success: false and returns.Pause in seconds between consecutive steps to allow pages to stabilise.
Add, override, or remove built-in tools.
Instructions injected into the LLM prompt on every step.
Transform the simplified DOM string before it is sent to the LLM. Runs after DOM extraction.
Completely replace the default system prompt. Incorrect prompts will break agent behaviour.
Experimental Options
Activate the
execute_javascript built-in tool. Can bypass safety guards and data-masking.Fetch
/llms.txt from the current origin once per task and include it in the LLM context.Lifecycle Hooks
Called once before the task loop begins. Throwing here cancels the task.
Called after the task loop ends regardless of outcome.
Called before each step.
stepCount is 0-indexed.Called after each step with the current history snapshot.
Called synchronously during
dispose().Properties
Unique identifier for this agent instance, generated at construction.
The resolved configuration object with defaults applied (
maxSteps guaranteed to be a number).Live registry of all active tools. Modified at construction time according to
customTools and experimentalScriptExecutionTool. Do not mutate this map at runtime.The
PageController instance used for all DOM operations.The
task string passed to the most recent execute() call. Empty string before the first call.A unique ID generated at the start of each
execute() call. Useful for correlating logs across lifecycle hooks.The persistent event log for the current task. Reset to
[] at the start of every execute() call. Populated during the run with step, observation, user_takeover, retry, and error events.true after dispose() has been called.Callback used by the
ask_user built-in tool. The ask_user tool is disabled when this property is unset. The implementation must reject the promise when options.signal is aborted.Current lifecycle status (getter). One of:
'idle' | 'running' | 'completed' | 'error' | 'stopped'.Result of the most recently completed run (getter).
null before the first run finishes.Methods
execute(task)
history, taskId, and all internal step state.
Throws (not caught internally) when:
agent.disposed === trueagent.status === 'running'taskis an empty string
maxSteps exceeded) are caught, recorded as error history events, and returned as ExecutionResult with success: false.
stop()
AbortController, then waits until the run has fully settled (including all onAfterStep / onAfterTask hooks). A no-op if the agent is not running.
dispose()
pageController.dispose(), and emits the 'dispose' event. After disposal the instance is inert and cannot be reused.
pushObservation(content)
<agent_history> as an observation event before the next step begins. The observation persists in the LLM context for all subsequent steps within the same task.
Observation text to make visible in the agent’s memory.
Observations queued via
pushObservation are batched and emitted as a single historychange event at the start of the next step’s observe phase.Events
PageAgentCore extends EventTarget. Subscribe with agent.addEventListener(type, handler).
| Event | Type | Description |
|---|---|---|
statuschange | Event | status changed. Read agent.status in the handler. |
historychange | Event | history was mutated (new event pushed). |
activity | CustomEvent<AgentActivity> | Transient real-time feedback. NOT stored in history. |
dispose | Event | Agent has been disposed. |
AgentActivity shapes
Re-Act Agent Loop
At each step the agent follows an observe → think → act cycle. The loop repeats until thedone tool is called, the task is stopped, or maxSteps is exceeded.
AgentOutput macro-tool wraps all registered tools into a single structured output, enforcing the reflection-before-action mental model. The LLM must provide evaluation_previous_goal, memory, and next_goal before specifying which tool to call.
Building a Custom UI
Related
PageAgent
Ready-to-use subclass with a built-in floating panel — the quickest way to get started.
PageController
DOM extraction and browser interaction layer injected into PageAgentCore.