# Mastra.getAgentById()
[EN] Source: https://mastra.ai/reference/core/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

```typescript copy
mastra.getAgentById("test-agent-123");
```

## Parameters

<PropertiesTable
  content={[
    {
      name: "id",
      type: "string",
      description:
        "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

<PropertiesTable
  content={[
    {
      name: "agent",
      type: "Agent",
      description:
        "The agent instance with the specified ID. Throws an error if the agent is not found.",
    },
  ]}
/>

## Related

- [Agents overview](/docs/agents/overview)


---
title: "Reference: Mastra.getAgents() | Core"
description: "Documentation for the `Mastra.getAgents()` method in Mastra, which retrieves all configured agents."
---