Step through the basics: detect the API, get permission, and make your first AI-powered tool call.
// Check for Web Agent API availability if (window.ai && window.agent) { console.log('Web Agent API is ready!'); }
const result = await window.agent.requestPermissions({ scopes: [ 'model:prompt', 'model:tools', 'mcp:tools.list', 'mcp:tools.call' ], reason: 'Getting Started demo' }); if (result.granted) { console.log('Permission granted!'); }
const tools = await window.agent.tools.list(); console.log(`Found ${tools.length} tools:`); tools.forEach(t => console.log(` • ${t.name}`));
for await (const event of window.agent.run({ task: 'What is the current time?', maxToolCalls: 3 })) { if (event.type === 'tool_call') { console.log('Using tool:', event.tool); } if (event.type === 'final') { console.log('Response:', event.output); } }
// The agent's final response from the previous step console.log(response);