integrate-fusion-agent
cognitedata/builder-skills
Integrate Atlas/EOS sidebar AI into Fusion apps via @cognite/app-sdk.
What is integrate-fusion-agent?
Adds AI agent capabilities to Flows/Fusion applications by connecting to the platform's Atlas sidebar (EOS/PAIA). Use this when you need to add chat UI, agent features, or LLM interactions to a Fusion app—it provides the standard integration path via @cognite/app-sdk rather than embedding custom chat or calling third-party LLM APIs directly.
- Connect to Fusion host via connectToHostApp and expose the Atlas sidebar launcher
- Send contextual messages to the agent with sendAgentMessage and control layout with sendAgentLayoutMode
- Register agent server with custom resources (read-only app state) and actions (tools/mutations)
- Define Zod-validated action parameters and resource descriptions for the agent to understand
- Fall back gracefully when running outside Fusion (e.g., standalone vite dev)
- Enforce safety gates: no per-row LLM calls, no vendored atlas-agent, no third-party API calls
How to install integrate-fusion-agent
npx skills add https://github.com/cognitedata/builder-skills --skill integrate-fusion-agent- @cognite/app-sdk version 0.3.1 or higher
- React app structure (App.tsx, hooks, context)
- pnpm, npm, or yarn package manager
- Running inside Fusion or handling graceful fallback for standalone environments
How to use integrate-fusion-agent
- 1.Install @cognite/app-sdk (pnpm add @cognite/app-sdk)
- 2.Create a useHostApp hook that calls connectToHostApp and catches rejection outside Fusion
- 3.Enable the Atlas button in the topbar (systemActions.atlas.visible: true via use-topbar skill)
- 4.Build agent resources (read-only state) and actions (tools) in separate modules using createAgentResource and createAgentAction
- 5.Register the agent server on component mount with registerAgentServer and unregister on unmount
- 6.Call sendAgentLayoutMode and sendAgentMessage to open the sidebar and send context when needed
- 7.Test action/resource factories directly without React; use try/catch for Comlink proxy calls, not typeof checks
Use cases
- Add an 'Analyse this item' button that opens the sidebar and sends the item context to the agent
- Expose current app state (filters, visible items, statuses) as a resource the agent can read before answering questions
- Register custom actions so the agent can fetch item details, update statuses, or trigger workflows with user approval
- Build a Fusion app where the agent can see and act on domain-specific data without leaving the sidebar
- Integrate AI into an existing Flows/Fusion application without rewriting the chat or LLM layer
- Fusion app developers adding AI/agent features
- Teams building internal tools on Cognite Fusion platform
- Developers who want to leverage the platform's Atlas sidebar instead of embedding custom chat
integrate-fusion-agent FAQ
Only if the user explicitly requires in-app chat AND connectToHostApp cannot work (e.g., truly standalone app that always rejects). The default is always the Atlas sidebar via @cognite/app-sdk.
No. Do not map chat completions over query results. Use sendAgentMessage to send one request to the sidebar agent, or expose data as a resource for the agent to read.
Mutating actions must document this in their description: 'Call ONLY when the user has explicitly approved the change.' The agent does not auto-confirm; you enforce approval in your UI before the action is registered.
It rejects outside Fusion. Catch the error, set api to null, and hide agent triggers. The app continues to work without AI features.
Build them as pure functions (factories) that take services as arguments. Call the handler directly in unit tests without React or Comlink.
Full instructions (SKILL.md)
Source of truth, from cognitedata/builder-skills.
name: integrate-fusion-agent description: >- MUST be used when adding AI, Atlas, an agent, a chat UI, or LLM features to a Flows/Fusion app. Use the Atlas/EOS sidebar via @cognite/app-sdk — not useAtlasChat, vendored atlas-agent, or per-row chat completions. Triggers: atlas, EOS, PAIA, agent chat, chat UI, sendAgentMessage, sendAgentLayoutMode, registerAgentServer, connectToHostApp, useAtlasChat, LLM. In-app chat: integrate-atlas-chat only if the host sidebar cannot work. allowed-tools: Read, Glob, Grep, Edit, Write, Bash
Integrate Atlas / EOS Sidebar
Default AI path: the platform Atlas sidebar (EOS / Fusion PAIA) via @cognite/app-sdk. Do not embed useAtlasChat, vendor atlas-agent, or call third-party LLM APIs.
integrate-atlas-chat only if the user explicitly requires in-app chat and connectToHostApp cannot provide the sidebar (standalone app; always rejects). There is no manifest field for this.
Implement only what is needed:
- Open — Topbar Atlas button;
sendAgentLayoutModefor in-app triggers - Message —
sendAgentMessageto inject context - Server — resources (app state) and actions (tools)
Step 0 — Read the app
package.json— package manager,@cognite/app-sdksrc/App.tsx— structure, existing SDK usage
Ask which of the three capabilities are needed. Do not offer an in-app chat unless they already insisted.
Step 1 — Install
pnpm add @cognite/app-sdk (or npm/yarn). Minimum 0.3.1.
Step 2 — Connect to the host
connectToHostApp rejects outside Fusion (standalone vite dev). Catch that; hide agent triggers when api is null.
Comlink proxies are callable — setApi(proxy) makes React treat the proxy as an updater and stores a Promise. Always setApi(() => resolvedApi).
// src/hooks/useHostApp.ts
import { useState, useEffect } from 'react';
import { connectToHostApp, type HostAppAPI } from '@cognite/app-sdk';
export function useHostApp(): HostAppAPI | null {
const [api, setApi] = useState<HostAppAPI | null>(null);
useEffect(() => {
connectToHostApp({ applicationName: 'my-app' })
.then(({ api: resolvedApi }) => setApi(() => resolvedApi))
.catch(() => { /* outside Fusion — no-op */ });
}, []);
return api;
}
Call at the root; pass api down or via context. typeof proxy.method === 'function' is always true — do not feature-detect with typeof; use try/catch.
Step 3 — Open the sidebar
Primary launcher: Aura Topbar Atlas (systemActions.atlas.visible: true, see use-topbar). No second "Open Assistant" control.
sendAgentLayoutMode is for contextual triggers only (sidebar | fullscreen | closed):
await api.sendAgentLayoutMode({ mode: 'sidebar' });
Step 4 — Send a message
Pair with sendAgentLayoutMode. newSession: true for a new task from an item; omit to continue the thread. Put names/IDs/state in the message — one sidebar turn, not N completions over query rows.
await api.sendAgentLayoutMode({ mode: 'sidebar' });
await api.sendAgentMessage({
message: `Analyse the schedule for "${itemName}" and suggest how to reduce total duration.`,
newSession: true,
});
Step 5 — Agent server
Register on mount, unregister on unmount. Factories take services as args so they can be unit-tested without React:
src/features/agent/
agentActions.ts — (deps) => Action[]
agentResources.ts — (deps) => Resource[]
useAgentServer.ts — register / unregister
Resource read() returns { type: 'json', data } (preferred) or { type: 'text', text }. Write description like a docstring.
// src/features/agent/agentResources.ts
import { createAgentResource } from '@cognite/app-sdk';
export function buildAgentResources(storage: StorageService) {
return [
createAgentResource({
uri: 'my-app://current-state',
name: 'Current application state',
description:
'Items currently visible, their statuses, and active filters. Read before answering questions about what the user is looking at.',
async read() {
return [{ type: 'json', data: storage.getAll() }];
},
}),
];
}
Actions: snake_case names, Zod params, .describe() on every field. The agent does not confirm before calling — mutating actions must say so in description and require prior user approval.
// src/features/agent/agentActions.ts
import { createAgentAction } from '@cognite/app-sdk';
import { z } from 'zod';
export function buildAgentActions(dataService: DataService) {
return [
createAgentAction({
name: 'get_item_details',
description: 'Full details for an item by ID, including history.',
parameters: z.object({
item_id: z.string().describe('The ID of the item to retrieve'),
}),
async handler({ item_id }) {
const item = await dataService.getItem(item_id);
return { content: [{ type: 'json', data: item }] };
},
}),
];
}
createAgentAction({
name: 'update_item_status',
description:
'Update item status. Call ONLY when the user has explicitly approved the change.',
parameters: z.object({
item_id: z.string().describe('The item to update'),
status: z.enum(['active', 'closed', 'pending']).describe('The new status'),
}),
async handler({ item_id, status }) {
storage.updateStatus(item_id, status);
return { content: [{ type: 'json', data: { success: true } }] };
},
})
// src/features/agent/useAgentServer.ts
import { useEffect } from 'react';
import { createAgentServer, registerAgentServer, type HostAppAPI } from '@cognite/app-sdk';
import { buildAgentActions } from './agentActions';
import { buildAgentResources } from './agentResources';
import { useStorageService } from '../storage/StorageServiceContext';
import { useDataService } from '../data/DataServiceContext';
export function useAgentServer(api: HostAppAPI | null): void {
const storage = useStorageService();
const dataService = useDataService();
useEffect(() => {
if (!api) return;
const server = createAgentServer({
uri: 'my-app', // Fusion namespaces with instance ID
actions: buildAgentActions(dataService),
resources: buildAgentResources(storage),
});
void registerAgentServer(api, server).catch((err: unknown) => {
console.warn('[agent] registerAgentServer failed:', err);
});
return () => {
void api.unregisterAgentServer('my-app').catch((err: unknown) => {
console.warn('[agent] unregisterAgentServer failed:', err);
});
};
}, [api, storage, dataService]);
}
Step 6 — Wire together
function App() {
const api = useHostApp();
useAgentServer(api);
return (
<AppLayout>
<MainContent onAnalyseItem={async (item) => {
if (!api) return;
await api.sendAgentLayoutMode({ mode: 'sidebar' });
await api.sendAgentMessage({
message: `Analyse "${item.name}" (id: ${item.id}).`,
newSession: true,
});
}} />
</AppLayout>
);
}
Test factories directly:
const [getItemAction] = buildAgentActions({
getItem: vi.fn().mockResolvedValue({ id: '1', name: 'Test' }),
});
const result = await getItemAction.handler({ item_id: '1' });
expect(result.content[0].data).toEqual({ id: '1', name: 'Test' });
Hard gate — LLM calls over query results
Do not map chat completions (Atlas agents/chat, OpenAI/Anthropic, useAtlasChat().send) over DMS/SDK rows. Prefer one sendAgentMessage or a resource the sidebar agent can read.
If per-item completions are an explicit product requirement (default: no):
| Rule | Limit |
|---|---|
| Default | 5 completions per user-initiated action |
| Ceiling | 50 — never generate code that can exceed this |
| Cache | space:externalId:lastUpdatedTime; hits do not spend budget |
| Batch | One prompt covering N items, not N calls |
| Trigger | User-initiated only — never on render, poll, or an unbounded list |
| UX | Say when the cap truncated the set |
Forbidden: items.map((row) => complete(row)), Promise.all of completions over a query page.
Checklist
- Topbar Atlas launcher (
use-topbar); no in-app chat widget -
@cognite/app-sdk@0.3.1+;setApi(() => resolvedApi); catch outside-Fusion rejection - Triggers hidden when
apiis null; server registered/unregistered with.catch() - Resource descriptions say what/when; action names
snake_case; mutating actions require prior approval - Factories take services as args; LLM-over-rows capped (5 / max 50) and cached if present
Related skills
More from cognitedata/builder-skills and the wider catalog.

integrate-todo-list
Add a TodoWrite panel to show Atlas agent task progress in your chat UI.

migrate-app-to-flows
Orchestrate full migration of legacy Dune apps to Flows app hosting infrastructure.

performance
Fix Flows app performance: re-renders, query patterns, pagination, memory leaks, and LLM costs.

pull-changes-resolve-conflicts
Safely integrate branch changes by analyzing conflicts before resolving, preserving intentional work.

reveal-3d
Interactive 3D viewer for CAD models, point clouds, and 360° images in Flows apps

security
Find and fix security issues in Flows apps before shipping—handles credentials, input validation, XSS, injection, and auth gaps.