The Mastra adapter allows you to use AgentMark prompts with Mastra’s agentic workflow framework.
Installation
npm install @agentmark/mastra-v0-adapter mastra
Setup
Create your AgentMark client with Mastra’s model registry:
import { createAgentMarkClient } from '@agentmark/sdk';
import { MastraModelRegistry } from '@agentmark/mastra-v0-adapter';
import { Anthropic } from 'mastra/llms';
export const client = createAgentMarkClient({
models: new MastraModelRegistry({
'claude-3-5-sonnet-20241022': new Anthropic({
model: 'claude-3-5-sonnet-20241022',
apiKey: process.env.ANTHROPIC_API_KEY!,
}),
}),
});
Running Prompts
AgentMark prompts return Mastra agents via formatAgent(), which you can then use with formatMessages():
import { client } from './agentmark.client';
const prompt = await client.loadTextPrompt('greeting.prompt.mdx');
const agent = await prompt.formatAgent({
props: { name: 'Alice' }
});
const [messages, options] = agent.formatMessages();
const result = await agent.generate(messages, options);
console.log(result.text);
Object Generation
For structured output, use object prompts:
import { client } from './agentmark.client';
import { z } from 'zod';
const prompt = await client.loadObjectPrompt('extract.prompt.mdx', {
schema: z.object({
sentiment: z.enum(['positive', 'negative', 'neutral']),
confidence: z.number(),
}),
});
const agent = await prompt.formatAgent({
props: { text: 'This product is amazing!' }
});
const [messages, options] = agent.formatMessages();
const result = await agent.generate(messages, options);
console.log(result.object);
// { sentiment: 'positive', confidence: 0.95 }
Configure tools in your client:
import { createAgentMarkClient } from '@agentmark/sdk';
import { MastraModelRegistry, MastraToolRegistry } from '@agentmark/mastra-v0-adapter';
import { createTool } from 'mastra/tools';
import { z } from 'zod';
const weatherTool = createTool({
id: 'weather',
description: 'Get current weather for a location',
inputSchema: z.object({
location: z.string(),
}),
execute: async ({ context }) => {
const { location } = context;
return `The weather in ${location} is sunny and 72°F`;
},
});
export const client = createAgentMarkClient({
models: new MastraModelRegistry({ /* ... */ }),
tools: new MastraToolRegistry({
weather: weatherTool,
}),
});
Then use tools in your prompts:
---
name: weather
text_config:
model_name: claude-3-5-sonnet-20241022
tools:
- weather
---
<System>You are a helpful weather assistant.</System>
<User>What's the weather in {props.location}?</User>
Next Steps
Have Questions?
We’re here to help! Choose the best way to reach us: