Skip to main content

AgentProvider

AgentProvider is the root component for the Agent SDK. It sets up the chat engine, theming, and provides context to all child components.

Usage

import { AgentProvider, AgentChat } from '@kapaai/agent-react';

<AgentProvider
getSessionToken={async () => {
const res = await fetch('/api/session', { method: 'POST' });
return res.json();
}}
projectId="your-project-id"
integrationId="your-integration-id"
tools={myTools}
context={myContext}
builtinToolMeta={{
search_knowledge_base: { displayName: 'Search Knowledge Base' },
}}
theme={{ accentColor: '#2563eb', colorScheme: 'dark' }}
>
<AgentChat branding={{ title: 'AI Assistant' }} />
</AgentProvider>

Props

PropTypeRequiredDescription
getSessionToken() => Promise<...>YesAsync function that returns a session token. Accepts the raw Kapa API response directly. Called lazily on first message. See Authentication.
projectIdstringYesYour Kapa project ID.
integrationIdstringYesYour Kapa integration ID.
toolsAgentTool<TContext>[]NoClient-side tool definitions. Defaults to []. See Custom tools.
contextTContextNoContext object passed to every tool's execute function. Defaults to {}.
builtinToolMetaRecord<string, ToolDisplayMeta>NoDisplay metadata for server-side built-in tools (e.g. search_knowledge_base).
customInstructionsstringNoAdditional system prompt instructions for the agent.
userEndUserInfoNoEnd user metadata (email, name) for analytics.
onEventOnAgentEventNoCallback for analytics events (message_sent, response_completed, tool_executed, etc.).
themeAgentThemeConfigNoVisual theme. See Theming.

In addition to the core events, the React SDK also emits panel_opened and panel_closed events when using AgentPanel.

AgentThemeConfig

FieldTypeDefaultDescription
accentColorstring'#9333ea'Primary color (hex). A full palette is generated automatically.
colorScheme'dark' | 'light' | 'auto''dark'Color scheme. 'auto' follows system preference.
fontFamilystring'Inter, system-ui, sans-serif'Font family for the entire chat UI.
fontSizenumber14Base font size in pixels.
radius'sharp' | 'soft' | 'round' | 'pill''soft'Border radius style.

See Theming for details and examples.

ToolDisplayMeta

The agent includes a built-in search_knowledge_base tool that searches your project's knowledge base server-side. Since it's not a client tool, you can't define or execute it — but you can customize how it appears in the chat. See Built-in tools for details.

builtinToolMeta={{
search_knowledge_base: {
displayName: 'Search Knowledge Base',
icon: IconSearch, // optional
iconColor: '#38bdf8', // optional
},
}}