Mastra.getAgentById()
The .getAgentById() method is used to retrieve an agent by its ID. The method accepts a single string parameter for the agent's ID.
Usage exampleDirect link to Usage example
mastra.getAgentById("test-agent-123");
ParametersDirect link to Parameters
id:
string
The ID of the agent to retrieve. The method will first search for an agent with this ID, and if not found, will attempt to use it as a name to call getAgent().
ReturnsDirect link to Returns
agent:
Agent
The agent instance with the specified ID. Throws an error if the agent is not found.