# 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

**name** (`TAgentName extends keyof TAgents`): The name of the agent to retrieve. Must be a valid agent name that exists in the Mastra configuration.

## Returns

**agent** (`TAgents[TAgentName]`): The agent instance with the specified name. Throws an error if the agent is not found.

## Related

- [Agents overview](https://mastra.ai/docs/agents/overview)