Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.agentmark.co/llms.txt

Use this file to discover all available pages before exploring further.

AgentMark provides type safety through JSON Schema definitions in your prompt files. npx agentmark generate-types compiles those schemas to TypeScript types you can pass to createAgentMarkClient<T>() for compile-time validation and IDE autocomplete.

Defining types

Define input and output types in your prompt files using JSON Schema:
math/addition.prompt.mdx
---
name: math/addition
object_config:
  model_name: openai/gpt-4o
  schema:
    type: object
    properties:
      answer:
        type: number
        description: "The sum of the two numbers"
    required: [answer]
input_schema:
  type: object
  properties:
    a:
      type: number
      description: "First number to add"
    b:
      type: number
      description: "Second number to add"
  required: [a, b]
---

<System>You compute sums.</System>
<User>What is {props.a} + {props.b}?</User>

Generating types

Generate TS types with the CLI:
npx agentmark generate-types --root-dir ./agentmark > agentmark.types.ts
For the prompt above, the generator emits:
agentmark.types.ts
// Auto-generated types from AgentMark
// Do not edit this file directly

interface Math$AdditionIn {
  a: number;
  b: number;
}


interface Math$AdditionOut {
  answer: number;
}


type Math$Addition = {
  kind: 'object';
  input:  Math$AdditionIn;
  output: Math$AdditionOut;
};

export default interface AgentmarkTypes {
  "math/addition.prompt.mdx": Math$Addition,
  "math/addition.prompt": Math$Addition,
  "math/addition": Math$Addition
}
Note two things:
  1. The wrapper (Math$Addition) is a type alias, while Math$AdditionIn / Math$AdditionOut are interfaces.
  2. Each prompt gets three key aliases — the full path with .prompt.mdx, the path ending in .prompt, and the bare name. Any of the three resolves to the same type when you call loadTextPrompt / loadObjectPrompt.

Using generated types

import PromptTypes from './agentmark.types';
import { createAgentMarkClient, VercelAIModelRegistry } from "@agentmark-ai/ai-sdk-v5-adapter";
import { ApiLoader } from "@agentmark-ai/loader-api";
import { openai } from "@ai-sdk/openai";
import { generateObject, tool } from "ai";
import { z } from "zod";

const loader = ApiLoader.local({ baseUrl: "http://localhost:9418" });

const modelRegistry = new VercelAIModelRegistry();
modelRegistry.registerProviders({ openai });

// AI SDK v5 uses `inputSchema`, not `parameters` (that's v4).
const sumTool = tool({
  description: "Add two numbers together",
  inputSchema: z.object({
    a: z.number().describe("First number"),
    b: z.number().describe("Second number"),
  }),
  execute: async ({ a, b }) => ({ answer: a + b }),
});

const client = createAgentMarkClient<PromptTypes>({
  loader,
  modelRegistry,
  tools: { sum: sumTool },
});

// TypeScript enforces correct types
const prompt = await client.loadObjectPrompt("math/addition.prompt.mdx");
const input = await prompt.format({
  props: {
    a: 5,   // must be number per input_schema
    b: 3,
  },
});

const result = await generateObject(input);
const answer: number = result.object.answer;  // type-safe

Benefits

  1. Compile-time safety — TypeScript flags prop-shape mismatches before runtime.
  2. IDE support — autocomplete and inline descriptions on props and outputs.
  3. Consistent interfaces — the same PromptTypes drives both the loader and the caller.
  4. Documentation — JSON Schema descriptions flow through to TS JSDoc comments.
  5. Validation — the adapter validates inputs and structured outputs against the schema at runtime.

Best practices

  1. Define both input_schema and object_config.schema (when the prompt is an object prompt) in your prompt files.
  2. Use descriptive property names and add description fields — they become JSDoc comments.
  3. Mark required properties using required.
  4. Regenerate types after any schema edit: npx agentmark generate-types --root-dir ./agentmark > agentmark.types.ts.
  5. Commit agentmark.types.ts to version control so CI type-checks the contract.

Have Questions?

We’re here to help! Choose the best way to reach us: