# Assistant Frame API URL: /docs/copilots/assistant-frame Share model context across iframe boundaries *** title: Assistant Frame API description: Share model context across iframe boundaries --------------------------------------------------------- The Assistant Frame API enables iframes to provide model context (tools and instructions) to a parent window's assistant. This is particularly useful for embedded applications, plugins, or sandboxed components that need to contribute capabilities to the main assistant. ## Overview The Assistant Frame system consists of two main components: * **AssistantFrameProvider**: Runs inside the iframe and provides model context * **AssistantFrameHost**: Runs in the parent window and consumes context from iframes ## Basic Usage ### In the iframe (Provider) The iframe acts as a provider of model context using `AssistantFrameProvider`: ```tsx // iframe.tsx import { AssistantFrameProvider } from "@assistant-ui/react"; import { ModelContextRegistry } from "@assistant-ui/react"; import { z } from "zod"; // Create a registry to manage your model context const registry = new ModelContextRegistry(); // Expose the registry to the parent window AssistantFrameProvider.addModelContextProvider(registry); // Add tools that will be available to the parent assistant registry.addTool({ toolName: "searchProducts", description: "Search for products in the catalog", parameters: z.object({ query: z.string(), category: z.string().optional(), }), execute: async ({ query, category }) => { // Tool implementation runs in the iframe const results = await searchAPI(query, category); return { products: results }; }, }); // Add system instructions const instructionHandle = registry.addInstruction( "You are a helpful assistant.", ); // update the instruction instructionHandle.update("You have access to a product catalog search tool."); ``` ### In the parent window (Host) The parent window consumes the iframe's context using `AssistantFrameHost`: ```tsx // parent.tsx import { useAssistantFrameHost } from "@assistant-ui/react"; import { useRef } from "react"; function ParentComponent() { const iframeRef = useRef(null); // Connect to the iframe's model context useAssistantFrameHost({ iframeRef, targetOrigin: "https://trusted-iframe-domain.com", // optional for increased security }); return (
{/* Your assistant-ui */}