Browse documentation

Examples

Research agent

Search approved sources and return a typed cited report.

A research function has a clear input and output. Start it as a persistent run when the caller can disconnect before the report is ready.

import { flary, z } from "flary";

const app = flary({ model: "openai/gpt-5" });

const sources = app.tools({
  sources: app.mcp("approved-sources"),
});

export const research = app.fn({
  input: z.object({
    question: z.string().min(1),
    scope: z.string().min(1),
  }),
  output: z.object({
    answer: z.string(),
    citations: z.array(z.string().url()),
    uncertainty: z.string(),
  }),
  tools: sources,
  prompt: ({ question, scope }) => `
Research only from approved sources.
Cite each material claim.

Scope: ${scope}
Question: ${question}
`,
});

Resolve approved-sources in trusted host code. Its credentials do not enter the prompt or tool schema.

const run = await api.research.start({
  question: "Which vendors support SCIM provisioning?",
  scope: "Approved security and vendor documentation only.",
});

for await (const event of run.stream()) {
  render(event);
}

The run ID stays valid after a browser or network disconnect.