This guide is for developers building Flows custom apps in Cognite Data Fusion (CDF). You will connect your app to the built-in CDF agent: expose app state as resources, register actions the agent can call, and send messages from your UI. Complete the prerequisites before you follow the integration steps. WithDocumentation Index
Fetch the complete documentation index at: https://docs.cognite.com/llms.txt
Use this file to discover all available pages before exploring further.
@cognite/app-sdk@0.3.1 or later, you can:
- Let the agent see your Flows custom app. Expose the app’s content and state as resources the agent can add to its context.
- Let the agent interact with your Flows custom app. Register actions as tools the agent can use to perform tasks in your app on the user’s behalf.
- Send messages from your Flows custom app to the agent. Trigger context-aware prompts when the user clicks a button or reaches a key point in a workflow.
Prerequisites
Before you start, ensure you have:- Access to Cognite Data Fusion (CDF) with appropriate capabilities. See Assign capabilities for more information.
- A Flows development environment set up. See Get started with Flows.
-
@cognite/app-sdk@0.3.1or later installed. This version adds the agent panel, messaging, and server registration APIs used in this guide. -
A
HostAppAPIinstance fromconnectToHostAppon mount:
Integrate the agent
Use yourHostAppAPI instance to control the agent panel, send messages from your app, and register an agent server with the resources and actions the agent can use.
Open the agent panel
Call AgentLayoutPayload options:
api.sendAgentLayoutMode to change the visibility or layout of the agent panel.| Field | Type | Description |
|---|---|---|
mode | 'sidebar' | 'fullscreen' | 'closed' | Target panel layout. |
conversationId | string? | Resume a specific existing conversation. |
agentExternalId | string? | Target a specific registered agent. |
source | AgentSource? | Surface identifier; omit unless required by your host. |
Send the agent a message
Call AgentMessagePayload options:
Use
api.sendAgentMessage to inject text into the agent’s chat, optionally starting a fresh session. Use sendAgentMessage to pre-populate the agent with context when the user clicks a contextual trigger in your app.| Field | Type | Description |
|---|---|---|
message | string | Text to inject into the chat. |
newSession | boolean? | Clear the existing conversation before injecting. |
Call
sendAgentLayoutMode before sendAgentMessage. The agent panel must be open for the user to see the injected message.newSession: true for contextual entry points where the user is starting a new task. Omit it when continuing an existing conversation.Register the agent server
An agent server exposes resources (read-only context the agent can request) and actions (tools the agent can call). Register it once on mount, and unregister it on unmount.In React, manage the lifecycle with
useEffect:Define resources
Resources are read-only data the agent reads to understand the current app state. Each resource has a URI, a name, and a The
read function that returns content.read function returns an array of content parts. Each element is one of:{ type: 'json', data: unknown }— structured data. The agent reasons over JSON directly; prefer this format when you can.{ type: 'text', text: string }— free-form text.
description field is visible to the agent. Use it to explain what the resource contains and when to read it. Treat it like a function docstring.Example: TAR planner resources
The TAR planner application exposes two resources. Both are populated fromTARStorageService (localStorage) and the critical path algorithm, giving the agent a live view of what the user is managing.Define actions
Actions are tools the agent can invoke. They can be read-only queries or mutating operations. Define parameters with a Zod schema. The After a mutating action writes to your state layer, the UI updates on the next render cycle if your components read from the same state. No extra signaling is required.
.describe() call on each field is the agent’s documentation for that parameter.Mutating actions
Mutating actions can write to your app’s state.Verify integration
Load your Flows custom app inside CDF (through the CDF development URL, not onlyhttps://localhost:3001). Confirm the following:
- Open the agent panel from your UI control or a
sendAgentLayoutModecall. - Send a test message and confirm it appears in the agent chat.
- Ask the agent a question that should use a registered resource and confirm the answer reflects your app state.
- If you registered mutating actions, test them only after you understand the risks in Mutating actions.
When integration works, the agent panel opens from your app, messages appear in chat, and resource-backed answers match the state your app exposes.
Recommended project structure
Separate the registration lifecycle from the action and resource definitions to test both independently.buildAgentActions, pass mock service implementations and call handler directly without mounting the hook.
Development and production behavior
connectToHostApp behaves differently depending on where your app runs:
| Environment | connectToHostApp behavior | Effect |
|---|---|---|
| Inside CDF | Resolves with { api } | Full agent integration functionality. |
Standalone development (vite dev) | Rejects | Agent features disabled; hide or disable agent UI triggers. |
connectToHostApp and disable agent features when your app isn’t running inside CDF.
api in state or context. When the host connection succeeds, your registration effect runs and UI components can show or hide agent triggers.