Quill
Chat

Use cases

Chat

An assistant that answers questions with reports.

The stack you choose picks the code on this page. Options marked coming soon can't be chosen yet.

Copies the Quill CLI's install command: curl -fsSL https://quill.co/install.sh | shView as MarkdownThe whole page, with the code for the chosen stack.

Connect to your existing agent as a tool call

1. Add a new tool

import OpenAI from "openai";
import { askQuill } from "./quill";

// OpenRouter speaks OpenAI's Chat Completions API.
const openrouter = new OpenAI({ baseURL: "https://openrouter.ai/api/v1", apiKey: process.env.OPENROUTER_API_KEY });

const tools: OpenAI.ChatCompletionTool[] = [
  {
    type: "function",
    function: {
      name: "ask_data_assistant",
      description: "Answer a question about the user's data with a report",
      parameters: { type: "object", properties: { question: { type: "string" } }, required: ["question"] },
    },
  },
];

export async function reply(messages: OpenAI.ChatCompletionMessageParam[], user: User) {
  let reportId: string | undefined;
  for (;;) {
    const completion = await openrouter.chat.completions.create({ model: "particle-ai/particle-1", messages, tools });
    const message = completion.choices[0].message;
    messages.push(message);
    if (!message.tool_calls?.length) return { text: message.content ?? "", reportId };
    for (const call of message.tool_calls) {
      if (call.type !== "function") continue;
      reportId = await askQuill(JSON.parse(call.function.arguments).question, user);
      messages.push({ role: "tool", tool_call_id: call.id, content: JSON.stringify({ reportId }) });
    }
  }
}

2. The tool call is a simple request to the Quill /ai endpoint

export async function askQuill(question: string, user: User) {
  const res = await fetch("https://api.quill.co/v1/ai", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.QUILL_PRIVATE_KEY}`,
      "Content-Type": "application/json",
      Accept: "text/event-stream",
    },
    body: JSON.stringify({
      publicKey: process.env.QUILL_PUBLIC_KEY,
      messages: [{ role: "user", content: question }],
      // From your signed-in user, never from the model
      tenants: [{ tenantField: "organization_id", tenantIds: [user.orgId] }],
    }),
  });
  const stream = await res.text();
  return stream.match(/"reportId":"(\w+)"/)?.[1];
}

3. Output of the tool call is the same param that useReport uses

import { Chart, useReport } from "@quillsql/react";

export function Message({ message }: { message: ChatMessage }) {
  if (message.reportId) return <ReportMessage reportId={message.reportId} />;
  return <Bubble role={message.role}>{message.text}</Bubble>;
}

function ReportMessage({ reportId }: { reportId: string }) {
  const { name } = useReport(reportId);
  return (
    <Card title={name} action={<Link href={`/reports/${reportId}`}>Open in report builder</Link>}>
      <Chart reportId={reportId} />
    </Card>
  );
}

You can build any reporting experience with useReport. Here are some examples: Chat, Insight, Reporting and Drilldowns.