AI

Mastra

Last updated on

Use Paradoc tools with Mastra agents

@paradoc/mastra wraps the @paradoc/ai-tools operations with Mastra's createTool(). Pass the tools to a Mastra Agent.

Installation

npm install @paradoc/mastra @mastra/core zod

Peer dependencies: @mastra/core ^1.64.0 and zod ^4.1.12. Requires Node.js 22.13 or newer.

Usage

import { Agent } from "@mastra/core/agent"
import { paradocTools } from "@paradoc/mastra"

const agent = new Agent({
  id: "document-agent",
  name: "Document agent",
  instructions: "Use the Paradoc tools to inspect and complete documents.",
  model: "openai/gpt-4o",
  tools: paradocTools({
    defaultRegistryUrl: "https://public.paradoc.dev",
  }),
})

Composing with other tools

paradocTools() returns an object keyed by tool name. Each tool's Mastra id is the same snake_case name. Spread it next to your own tools, or pick the ones you need:

import { paradocTools } from "@paradoc/mastra"

const { inspect_artifact, fill, get_fill_state, update_fill } = paradocTools()

const agent = new Agent({
  id: "intake-agent",
  name: "Intake agent",
  instructions: "Collect the values the form needs, one question at a time.",
  model: "openai/gpt-4o",
  tools: { inspect_artifact, fill, get_fill_state, update_fill },
})

Each operation also has its own factory, such as render(). Each factory is also the named and default export of its package subpath, such as @paradoc/mastra/render.

Configuration

The adapter takes ParadocMastraConfig, an alias of ParadocToolsConfig:

OptionTypeDescription
maxOutputBytesnumberMaximum bytes of content the model sees. Default DEFAULT_MODEL_OUTPUT_MAX_BYTES (16,384).

The limit applies to text and base64 content, such as a render result. Content over the limit is cut and marked truncated: true. Your application code still gets the full result.

const tools = paradocTools({
  defaultRegistryUrl: "https://public.paradoc.dev",
  maxOutputBytes: 32_000,
})

Mastra's execution abortSignal is combined with signal and context.signal.

API

paradocTools(config?)

Returns ten Mastra tools keyed by their snake_case names.

KeyFactory
get_registrygetRegistry()
get_artifactgetArtifact()
inspect_artifactinspectArtifact()
validate_artifactvalidateArtifact()
validate_inputvalidateInput()
fillfill()
get_fill_stategetFillState()
update_fillupdateFill()
renderrender()
extractextract()

Every factory takes an optional ParadocMastraConfig. The package also exports operationNames and DEFAULT_MODEL_OUTPUT_MAX_BYTES.

Types

The package exports ParadocMastraConfig and re-exports ParadocToolsConfig, OperationName, ToolDefinitions, and the input and output type of every operation from @paradoc/ai-tools:

import type {
  ParadocMastraConfig,
  FillOutput,
  FillStateOutput,
  RenderOutput,
} from "@paradoc/mastra"

On this page