The Copilot AI Assistant is a sophisticated AI-powered system designed to assist users in building, debugging, and managing workflows. It is accessible through two primary interfaces: the Mothership (a workspace-level global assistant) and the Workflow Panel (a context-aware assistant embedded in the workflow editor).
For details on specific subsystems, see the following child pages:
edit_workflow, run_workflow, and research.agent, ask, plan) and slash commands.useChat hook.The Copilot system bridges "Natural Language Space" (user intent) with "Code Entity Space" (workflow blocks, database records, and tool executions) through a multi-layered orchestration process.
The following diagram illustrates how user messages are transformed into actionable code operations and persisted entities.
Sources:
The useChat hook is the primary engine for AI interaction in both the Mothership and Workflow views. It manages message history, file attachments, and complex streaming logic.
| Feature | Implementation |
|---|---|
| Streaming | Handles Server-Sent Events (SSE) via ReadableStream apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts:170-186 |
| Recovery | Manages lastEventId and activeStream persistence for session recovery apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts:115-138 |
| Tool Handling | Tracks pendingToolPromises and executes client-side tools apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts:6-10 |
The backend orchestrator manages the communication between the Next.js API and the internal Sim Agent service. It handles long-running tool executions and "Async Pauses" where the agent waits for external results.
Key Functions:
orchestrateCopilotStream: Coordinates the loop between the LLM and tool execution apps/sim/lib/copilot/orchestrator/index.ts82-143runStreamLoop: Manages the network connection to the Go-side agent API apps/sim/lib/copilot/orchestrator/index.ts183-197executeToolAndReport: Executes a tool and feeds the result back into the LLM context apps/sim/lib/copilot/orchestrator/sse/handlers/handlers.ts23Sources:
Copilot tools are divided into server-side (executed by the backend) and client-side (executed in the browser).
The Copilot can extract tabular data from tool outputs and materialize them as files in the workspace. For example, function_execute or user_table results can be converted to CSV and uploaded to the workspace file manager using uploadWorkspaceFile apps/sim/lib/copilot/orchestrator/sse/handlers/tool-execution.ts150-205
Sources:
The Mothership is the global AI interface found on the workspace home page. It allows for broad queries across multiple workflows and resources. It is initialized via useChat with workspace-specific options apps/sim/app/workspace/[workspaceId]/home/home.tsx:156-160.
Inside the workflow editor, the Copilot is integrated into a resizable Panel apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/panel.tsx:97-112. It shares state with the WorkflowStore and WorkflowRegistry to provide context-aware suggestions and editing capabilities.
Key UI Elements:
AgentGroup component apps/sim/app/workspace/[workspaceId]/home/components/message-content/message-content.tsx:138-169.Sources: