--- title: Mastra description: Agentic adapter for the Mastra AI Agent framework. --- - package: `@agentic/mastra` - exports: `function createMastraTools` - [source](https://github.com/transitive-bullshit/agentic/blob/main/packages/mastra/src/mastra.ts) - [Mastra docs](https://mastra.ai/docs) ## Install ```bash npm npm install @agentic/mastra @mastra/core ``` ```bash yarn yarn add @agentic/mastra @mastra/core ``` ```bash pnpm pnpm add @agentic/mastra @mastra/core ``` ## Usage ```ts import 'dotenv/config' import { createMastraTools } from '@agentic/mastra' import { WeatherClient } from '@agentic/weather' import { openai } from '@ai-sdk/openai' import { Agent } from '@mastra/core/agent' async function main() { const weather = new WeatherClient() const weatherAgent = new Agent({ name: 'Weather Agent', instructions: 'You are a helpful assistant. Be as concise as possible.', model: openai('gpt-4o-mini'), tools: createMastraTools(weather) }) const res = await weatherAgent.generate( 'What is the weather in San Francisco?' ) console.log(res.text) } await main() ``` Note that this example snippet also requires you to install the AI SDK's OpenAI provider, the Agentic weather tool, and `dotenv`. ```bash npm npm install @ai-sdk/openai @agentic/weather dotenv ``` ```bash yarn yarn add @ai-sdk/openai @agentic/weather dotenv ``` ```bash pnpm pnpm add @ai-sdk/openai @agentic/weather dotenv ``` ## Running this example You'll need a free API key from [weatherapi.com](https://www.weatherapi.com) to run this example. Store it in a local `.env` file as `WEATHER_API_KEY`. You'll need an [OpenAI API key](https://platform.openai.com/docs/quickstart) to run this example. Store it in a local `.env` file as `OPENAI_API_KEY`. ```sh git clone git@github.com:transitive-bullshit/agentic.git cd agentic pnpm install echo 'WEATHER_API_KEY=your-key' >> .env echo 'OPENAI_API_KEY=your-key' >> .env npx tsx examples/mastra/bin/weather.ts ```