Mastra.getAgent()
The .getAgent() method is used to retrieve an agent. The method accepts the agent's name and an optional version selector. Passing a version selector returns a promise.
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.
version?:
{ versionId: string } | { status?: 'draft' | 'published' }
Selects a stored version of the agent. When provided, the method returns a promise.
ReturnsDirect link to Returns
agent:
TAgents[TAgentName] | Promise<TAgents[TAgentName]>
The agent instance with the specified name, or a promise that resolves to it when
version is provided. Throws an error if the agent is not found.