---
title: "Reference: Mastra.getAgent() | Core"
description: "Documentation for the `Agent.getAgent()` method in Mastra, which retrieves an agent by name."
packages:
  - "@mastra/core"
---

# Mastra.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
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/v1/agents/overview)
