Skip to content

Add basic page observation infrastructure#164

Open
domfarolino wants to merge 5 commits intomainfrom
page-observation
Open

Add basic page observation infrastructure#164
domfarolino wants to merge 5 commits intomainfrom
page-observation

Conversation

@domfarolino
Copy link
Copy Markdown
Collaborator

@domfarolino domfarolino commented Apr 16, 2026

This PR adds basic "page observation" and scheduling infrastructure, to lay the ground work for browser-agent-invoked tool execution. After this PR, I'll create one for tool execution, to unblock #146.


Preview | Diff

@domfarolino domfarolino requested a review from markafoltz April 16, 2026 12:01
Copy link
Copy Markdown
Collaborator

@markafoltz markafoltz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few nit picks, it looks like the spec generator API threw a few errors to clean up.

Comment thread index.bs Outdated
Comment thread index.bs
Comment thread index.bs
Comment thread index.bs
view of the page's tools and any other relevant context by getting an [=observation=]. An
<dfn>observation</dfn> is an [=implementation-defined=] data structure containing at least a <dfn
for=observation>tool map</dfn>, which is a [=map=] whose [=map/keys=] are [=Document/unique ID=]s,
and whose [=map/values=] are [=tool definitions=].
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would think this needs to be doubly keyed by (document_id, tool_name) at a minimum?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That'd only be necessary if within a single Document, you could have multiple tools with the same name. But that shouldn't be possible, so keying on document ID means all of the tools associated with that document will be unique. Across multiple Documents, you can have duplicate tool names, but that should be taken care of. Does that sound right or am I missing something?

Comment thread index.bs Outdated
Comment thread index.bs
Comment thread index.bs
Each {{Document}} object has a <dfn for=Document>unique ID</dfn>, which is a [=unique internal
value=].

The times at which a [=browser agent=] [=performs an observation=] are [=implementation-defined=].
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may need to be more proscriptive here; if tools are registered or unregistered, or frames enter or leave the frame tree, those should trigger a re-observation.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. My plan is this: when getTools() exists, whenever we queue tasks on the AI agent queue to update the browser process map of all tools, I'll also add a step about optionally performing observations then. So I was thinking of holding off on that until that infra is laid. How does that sound?

Comment thread index.bs

1. Perform any [=implementation-defined=] steps with |observation| and the [=browser agent=], to
expose the |observation|'s [=observation/tool map=] to the [=browser agent=] in whatever way it
accepts.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect this will also update the tool map exposed to other frames in listTools() once that is spec'ed out? Otherwise I am wondering how we will measure interop since the side effect is only exposed to the browser agent.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually performing an observation will not have any web-observable effects. When I spec the Promise-returning getTools(), we'll have to move to a central browser process location of all combined tools in the frame tree. Then, the page observation logic here will move from doing what APC does in Chromium now (gathering all tools from the tree) to just taking a copy of that browser-side map, and packaging it up here in some way for the observation.

So in short, this is not the map that getTools() will consult. This is just the map for observations. And its instantiation will be simplified once getTools() exists imminently.

Comment thread index.bs

The [=user agent=]'s [=browser's agent=] runs [=in parallel=] to any [=event loops=] associated
with a {{ModelContext}} [=relevant global object=]. Steps running on the [=browser's agent=] get
queued on its <dfn>AI agent queue</dfn>, which is the result of [=starting a new parallel queue=].
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
queued on its <dfn>AI agent queue</dfn>, which is the result of [=starting a new parallel queue=].
queued on its <dfn>browser agent queue</dfn>, which is the result of [=starting a new parallel queue=].

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're using the AI task source in the renderer/Document's event loop, I'd like to keep the browser side equivalent also prefixed with "AI", to mirror this. Is that OK?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants