feat(browser): dynamically discover read-only tools (#23805)

This commit is contained in:
cynthialong0-0
2026-03-25 12:16:48 -07:00
committed by GitHub
parent fe92a43e31
commit 86111c4d54
2 changed files with 19 additions and 10 deletions

View File

@@ -379,9 +379,19 @@ describe('browserAgentFactory', () => {
it('should register ALLOW rules for read-only tools', async () => {
mockBrowserManager.getDiscoveredTools.mockResolvedValue([
{ name: 'take_snapshot', description: 'Take snapshot' },
{ name: 'take_screenshot', description: 'Take screenshot' },
{ name: 'list_pages', description: 'list all pages' },
{
name: 'take_snapshot',
description: 'Take snapshot',
},
{
name: 'take_screenshot',
description: 'Take screenshot',
},
{
name: 'list_pages',
description: 'list all pages',
annotations: { readOnlyHint: true },
},
]);
await createBrowserAgentDefinition(mockConfig, mockMessageBus);

View File

@@ -120,13 +120,12 @@ export async function createBrowserAgentDefinition(
}
// Reduce noise for read-only tools in default mode
const readOnlyTools = [
'take_snapshot',
'take_screenshot',
'list_pages',
'list_network_requests',
];
for (const toolName of readOnlyTools) {
const readOnlyTools = (await browserManager.getDiscoveredTools())
.filter((t) => !!t.annotations?.readOnlyHint)
.map((t) => t.name);
const allowlistedReadonlyTools = ['take_snapshot', 'take_screenshot'];
for (const toolName of [...readOnlyTools, ...allowlistedReadonlyTools]) {
if (availableToolNames.includes(toolName)) {
const rule = generateAllowRules(toolName);
if (!existingRules.some((r) => isRuleEqual(r, rule))) {