Integrazioni

Mastra

Incapsula Thunderbit come Tool Mastra per agent e workflow

Mastra รจ un framework TypeScript per agent AI e workflow. La sua primitiva createTool si mappa pulitamente su /distill.

Installazione

npm install @mastra/core zod

Definisci il Tool

import { createTool } from '@mastra/core/tools';
import { z } from 'zod';

const API = 'https://openapi.thunderbit.com/openapi/v1';
const H = { Authorization: `Bearer ${process.env.THUNDERBIT_API_KEY}` };

export const readUrlTool = createTool({
  id: 'read-url',
  description:
    'Fetch a URL and return clean Markdown for the agent to read.',
  inputSchema: z.object({
    url: z.string().url(),
    renderMode: z.enum(['basic', 'advanced']).default('basic'),
  }),
  outputSchema: z.object({ markdown: z.string() }),
  execute: async ({ context }) => {
    const res = await fetch(`${API}/distill`, {
      method: 'POST',
      headers: { ...H, 'Content-Type': 'application/json' },
      body: JSON.stringify(context),
    });
    const json = await res.json();
    return { markdown: json.data.markdown };
  },
});

Collega in un Agent

import { Agent } from '@mastra/core/agent';
import { openai } from '@ai-sdk/openai';

export const researcher = new Agent({
  name: 'researcher',
  instructions: 'Use read-url to fetch any URL the user asks about.',
  model: openai('gpt-4o'),
  tools: { readUrlTool },
});

Usa in un Workflow

Per pipeline multi-step, chiama /batch/distill da uno Step Mastra e fai polling fino a COMPLETED โ€” vedi Batch Job Lifecycle.

Correlati