> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wazoo.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Mastra

> Connect Worlds to Mastra

[Mastra](https://mastra.ai/) is an un-opinionated AI engine designed to run
programmatic intelligence natively alongside your core application code. Since
Mastra is built on Vercel AI SDK standards, Worlds tools work out of the box
with Mastra agents.

## Installation

Install both the Mastra core and Worlds AI SDK:

<CodeGroup>
  ```bash deno theme={null}
  deno add jsr:@mastra/core jsr:@wazoo/worlds-ai-sdk
  ```

  ```bash npm theme={null}
  npx jsr add @mastra/core @wazoo/worlds-ai-sdk
  ```

  ```bash bun theme={null}
  bunx jsr add @mastra/core @wazoo/worlds-ai-sdk
  ```

  ```bash pnpm theme={null}
  pnpm i jsr:@mastra/core jsr:@wazoo/worlds-ai-sdk
  ```
</CodeGroup>

## Usage

You can pass Worlds tools directly to a Mastra `Agent`.

```typescript theme={null}
import { Agent } from "@mastra/core/agent";
import { openai } from "@ai-sdk/openai";
import { Worlds } from "@wazoo/worlds-sdk";
import { createTools } from "@wazoo/worlds-ai-sdk";

const worlds = new Worlds({
  apiKey: process.env.WORLDS_API_KEY,
});

// Initialize the Worlds toolset
const { executeSparql, searchEntities } = createTools({
  worlds,
  sources: ["my-world-slug"],
});

// Create a Mastra agent with Worlds tools
const agent = new Agent({
  name: "WorldsAgent",
  instructions: "You are a knowledge graph assistant.",
  model: openai("gpt-4o"),
  tools: {
    executeSparql,
    searchEntities,
  },
});

const result = await agent.generate("Find all people in my world.");
console.log(result.text);
```

## Granular selection

If you only need specific tools, you can import and initialize them
individually:

```typescript theme={null}
import { Agent } from "@mastra/core/agent";
import { openai } from "@ai-sdk/openai";
import { Worlds } from "@wazoo/worlds-sdk";
import { createSearchEntitiesTool } from "@wazoo/worlds-ai-sdk";

const worlds = new Worlds({
  apiKey: process.env.WORLDS_API_KEY,
});

const sources = ["my-world-slug"];

const agent = new Agent({
  name: "SearchAgent",
  model: openai("gpt-4o"),
  tools: {
    search: createSearchEntitiesTool({ worlds, sources }),
  },
});
```
