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

# Mastra

> Deploy a Mastra agent as it is: streamed text, tool calls and tool results.

## What is supported

`@mastra/core` 1.x. Onecortex recognises a Mastra `Agent` and streams it.

## A complete agent

```yaml agent.yml theme={null}
apiVersion: v1
runtime: node22
entrypoint: agent.ts#agent
dependencies: package.json
```

```json package.json theme={null}
{
  "type": "module",
  "dependencies": {
    "@ai-sdk/openai": "^3.0.0",
    "@mastra/core": "^1.0.0",
    "zod": "^4.0.0"
  }
}
```

```ts agent.ts theme={null}
import { openai } from '@ai-sdk/openai'
import { Agent } from '@mastra/core/agent'
import { createTool } from '@mastra/core/tools'
import { z } from 'zod'

const wordCount = createTool({
  id: 'word_count',
  description: 'Counts the words in a piece of text.',
  inputSchema: z.object({ text: z.string() }),
  execute: async ({ text }) => ({ words: text.split(/\s+/).filter(Boolean).length }),
})

// Reads OPENAI_API_KEY, which you add as a secret on the agent's Config tab.
export const agent = new Agent({
  name: 'assistant',
  instructions: 'Count the words in what the user says, then answer.',
  model: openai('gpt-5'),
  tools: { wordCount },
})
```

Add `OPENAI_API_KEY` as a secret on the agent's **Config** tab, then deploy. Any model works: this one is an example. See [Configuration and secrets](/build/configuration).

<Card title="A complete Mastra example" icon="github" href="https://github.com/onecortex-io/examples/tree/main/recipe-assistant">
  `recipe-assistant`: A Mastra agent with a recipe search tool, filtering by a diet the caller sends. It runs with no model key.
</Card>

## The prompt and the reply

The prompt is the agent's input. The reply is its streamed text.

## Events it reports

| Events | From |
| - | - |
| `text` | The streamed text |
| `tool_call_start`, `tool_call_args`, `tool_call_end` | Each tool call, streamed as it forms |
| `tool_result` | Each tool's result, with `isError` when it failed |
| `done` or `error` | The end of the run: always exactly one |

See [Streaming and events](/build/streaming).

## The caller's fields

In Mastra's request context, under `onecortex`, which a tool reads from its second argument:

```ts theme={null}
execute: async ({ ingredients }, context) => {
  const sent = context.requestContext?.get('onecortex') as { params?: { diet?: string } } | undefined
  const diet = sent?.params?.diet
  // ...
},
```

## Known limits

* Mastra's memory is not configured by Onecortex. Attach your own storage if the agent needs to remember across instances.

## Troubleshooting

| You see | Do this |
| - | - |
| The caller's fields are `undefined` in a tool | Read them from `context.requestContext`, not from the tool's input. |

More on [Troubleshooting](/production/troubleshooting) and [Errors](/production/errors).
