Loading...
Loading...
MUST be used when adding Pyodide or Python tool support to a Dune app. Do NOT manually configure usePyodideRuntime or wire pythonRuntime into useAtlasChat — this skill handles pyodide installation, hook setup, loading UI, and chat hook wiring. Triggers: Pyodide, Python tools, pythonRuntime, usePyodideRuntime, runPythonCode, Python execution, client-side Python.
npx skill4agent add cognitedata/dune-skills setup-python-toolstype: "runPythonCode"toolConfirmationclientToolpythonRuntimeusePyodideRuntimepythonRuntimeuseAtlasChatPythonToolConfigusePyodideRuntimepackage.jsonuseAtlasChatpyodide@0.29.3pnpm add pyodide@0.29.3npm install pyodide@0.29.3yarn add pyodide@0.29.3Note:,@cognite/dune-industrial-components,@sinclair/typebox,ajvshould already be installed. If not, install them too (see theajv-formatsskill).integrate-atlas-chat
useAtlasChatimport { loadPyodide } from "pyodide";
import { usePyodideRuntime } from "@cognite/dune-industrial-components/atlas-agent/pyodide";
import { useAtlasChat } from "@cognite/dune-industrial-components/atlas-agent/react";
function MyChat() {
const { sdk, isLoading } = useDune();
// Initialize Python runtime (loads Pyodide, installs packages, sets up Cognite SDK)
const {
runtime: pythonRuntime,
loading: pythonLoading,
progress: pythonProgress,
error: pythonError,
isReady: pythonReady,
} = usePyodideRuntime({
loadPyodide,
client: isLoading ? null : sdk,
requirements: ["pandas", "numpy"], // optional — additional packages
});
// ... useAtlasChat below
}| Return field | Type | Description |
|---|---|---|
| | The initialized runtime, or undefined if not ready |
| | True while Pyodide is loading / initializing |
| | Error message if initialization failed |
| | Current init progress for UI display |
| | Convenience: |
{/* Loading — shown above the input while Pyodide initializes */}
{pythonLoading && (
<div className="flex items-center gap-2 rounded-lg border bg-muted/50 px-3 py-2 text-sm text-muted-foreground">
{/* Optional: <IconBrandPython /> from @tabler/icons-react */}
<span>{pythonProgress.stage || "Initializing Python..."}</span>
{pythonProgress.percent > 0 && pythonProgress.percent < 100 && (
<span className="text-xs opacity-70">({pythonProgress.percent}%)</span>
)}
</div>
)}
{/* Error — shown if init fails (after loading finishes) */}
{pythonError && !pythonLoading && (
<div className="flex items-center gap-2 rounded-lg border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive">
<span>Python runtime failed to load</span>
</div>
)}useAtlasChatconst { messages, send, isStreaming, progress, error, reset, abort } = useAtlasChat({
client: isLoading ? null : sdk,
agentExternalId: "my-agent",
tools: [renderTimeSeries], // regular client tools (declared to agent), if any
pythonRuntime, // from usePyodideRuntime — enables Python tool execution
});tools<ChatInput
onSend={handleSend}
disabled={isStreaming || pythonLoading}
// ...
/><ChatHomePage
onSuggestionClick={handleSuggestionClick}
disabled={pythonLoading}
/>