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 example
mastra.getAgentById("test-agent-123");
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().
Returns
agent:
Agent
The agent instance with the specified ID. Throws an error if the agent is not found.