# Mastra.getAgent()
[EN] Source: https://mastra.ai/reference/core/getAgent

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

## Usage example

```typescript copy
mastra.getAgent("testAgent");
```

## Parameters

<PropertiesTable
  content={[
    {
      name: "name",
      type: "TAgentName extends keyof TAgents",
      description:
        "The name of the agent to retrieve. Must be a valid agent name that exists in the Mastra configuration.",
    },
  ]}
/>

## Returns

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

## Related

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


---
title: "Reference: Mastra.getAgentById() | Core"
description: "Documentation for the `Mastra.getAgentById()` method in Mastra, which retrieves an agent by its ID."
---