// Create a text session const session = await window.ai.createTextSession(); // Generate text const response = await session.prompt("What is the capital of France?"); console.log(response); // "Paris is the capital of France..." // Streaming response for await (const chunk of session.promptStreaming("Tell me a story")) { process.stdout.write(chunk); }
// List available MCP tools const tools = await window.agent.tools.list(); console.log(tools); // [{name: "memory/add", ...}, ...] // Call a tool directly const result = await window.agent.tools.call({ tool: "memory/add", args: { key: "name", value: "Alice" } });
// Run an agent that can use tools for await (const event of window.agent.run({ task: "Save my name as Alice and then retrieve it", tools: ["memory/add", "memory/get"], maxToolCalls: 5 })) { switch (event.type) { case "status": console.log("Status:", event.message); break; case "tool_call": console.log("Calling:", event.tool); break; case "tool_result": console.log("Result:", event.result); break; case "final": console.log("Done:", event.output); break; } }
This demo showcases the window.ai and window.agent Web Agent APIs. Toggle Tools to use MCP tools or Tab Context to include the current tab's content.
No tools available.
Start an MCP server to see tools here.