Skip to main content
Mastra v1 is coming in January 2026. Get ahead by starting new projects with the beta or upgrade your existing project today.

Mastra.getAgent()

The .getAgent() method is used to retrieve an agent. The method accepts a single string parameter for the agent's name.

Usage exampleDirect link to Usage example

mastra.getAgent("testAgent");

ParametersDirect link to Parameters

name:

TAgentName extends keyof TAgents
The name of the agent to retrieve. Must be a valid agent name that exists in the Mastra configuration.

ReturnsDirect link to Returns

agent:

TAgents[TAgentName]
The agent instance with the specified name. Throws an error if the agent is not found.

On this page