Skip to content

Copilot Architecture

Overview

QDash Copilot is an AI-powered assistant that helps experimentalists interpret qubit calibration results. It provides two interaction modes:

  1. Analysis Sidebar -- Task-scoped analysis within the metrics modal, providing contextual interpretation of individual calibration results (e.g., CheckT1, CheckRabi).
  2. Chat Page -- A dedicated chat interface for chip-wide questions, cross-qubit comparisons, and exploratory data analysis.

Both modes use the same underlying LLM agent with tool-calling capabilities, sandboxed Python execution, and SSE streaming for real-time progress feedback.

Component Diagram

Copilot Architecture

Key Files

FileResponsibility
src/qdash/api/routers/copilot.pyFastAPI router with /config, /analyze, /analyze/stream, /chat/stream endpoints; SSE event generation via SSETaskBridge
src/qdash/api/services/copilot_data_service.pyData loading service: build_analysis_context(), build_images_sent_metadata(), qubit/task/history queries, tool executor wiring
src/qdash/api/lib/copilot_agent.pyLLM agent: system prompt construction, OpenAI Responses API calls, tool call loop, response parsing
src/qdash/api/lib/copilot_sandbox.pySandboxed Python execution: AST validation, restricted builtins, resource limits
src/qdash/api/lib/copilot_analysis.pyPydantic models: TaskAnalysisContext, AnalysisResponse, AnalysisContextResult; request schemas
src/qdash/api/lib/sse.pySSE utilities: sse_event() formatter, SSETaskBridge for queue-poll-heartbeat-drain pattern
src/qdash/api/lib/copilot_config.pyConfiguration loader: CopilotConfig, ModelConfig, ScoringThreshold models; YAML loading with local override
src/qdash/datamodel/task_knowledge.pyTaskKnowledge model with domain-specific knowledge per calibration task
config/copilot.yamlMain configuration file for model settings, scoring thresholds, system prompts
ui/src/hooks/useCopilotChat.tsReact hook for the chat page: session management, SSE consumption, localStorage persistence
ui/src/hooks/useAnalysisChat.tsReact hook for the analysis sidebar: task-scoped SSE streaming, message management
ui/src/components/features/chat/CopilotChatPage.tsxChat page UI: session list, message rendering, blocks/chart display
ui/src/components/features/metrics/AnalysisChatPanel.tsxAnalysis sidebar UI within the metrics modal

Configuration

config/copilot.yaml

yaml
enabled: true

# Language settings
thinking_language: en      # Internal reasoning language
response_language: ja      # User-facing response language

# Model settings
model:
  provider: openai         # openai | ollama
  name: gpt-4.1
  temperature: 0.7
  max_output_tokens: 2048

# Metrics for chip health evaluation
evaluation_metrics:
  qubit: [qubit_frequency, anharmonicity, t1, t2_echo, ...]
  coupling: [zx90_gate_fidelity, bell_state_fidelity]

# Scoring thresholds per metric
scoring:
  t1:
    good: 50
    excellent: 100
    bad: 20
    unit: "μs"
    higher_is_better: true
  # ... (see config/copilot.yaml for full list)

# Task analysis settings
analysis:
  enabled: true
  multimodal: true
  max_conversation_turns: 10

Configuration is loaded via ConfigLoader with local override support (copilot.local.yaml).

Environment Variables

VariablePurpose
OPENAI_API_KEYOpenAI API authentication
OLLAMA_URLOllama server URL (default: http://localhost:11434)
NEXT_PUBLIC_API_URLAPI base URL for frontend (default: /api)

Two Modes

Analysis Sidebar

Activated from the metrics modal when viewing a specific task result (e.g., CheckT1 for qubit Q03).

  • Endpoint: POST /copilot/analyze/stream
  • Hook: useAnalysisChat
  • Context: Full TaskAnalysisContext including task knowledge, qubit parameters, experiment results, historical data, neighbor qubit data, and coupling parameters
  • Use case: "Is this T1 result normal?", "Why does the fit R² look low?"

Chat Page

A standalone page (/copilot) for general questions about the calibration system.

  • Endpoint: POST /copilot/chat/stream
  • Hook: useCopilotChat
  • Context: Chip ID, optional qubit ID, scoring thresholds
  • Use case: "Compare T1 across all qubits", "Show me the frequency trend for Q16"
  • Sessions: Persisted to localStorage with multi-session support

Released under the Apache 2.0 License.