Back to Mastra

Reference: Agent.getModel() | Agents

docs/src/content/en/reference/agents/getModel.mdx

2025-12-181.4 KB
Original Source

Agent.getModel()

The .getModel() method retrieves the language model configured for an agent, resolving it if it's a function. This method is used to access the underlying model that powers the agent's capabilities.

Usage example

typescript
await agent.getModel()

Parameters

<PropertiesTable content={[ { name: 'options', type: '{ requestContext?: RequestContext }', isOptional: true, defaultValue: '{}', description: 'Optional configuration object containing request context.', properties: [ { type: '{ requestContext?: RequestContext }', parameters: [ { name: 'requestContext', type: 'RequestContext', isOptional: true, defaultValue: 'undefined', description: 'Request Context for dependency injection and contextual information.', }, ], }, ], }, ]} />

Returns

<PropertiesTable content={[ { name: 'model', type: 'MastraLanguageModel | Promise<MastraLanguageModel>', description: 'The language model configured for the agent, either as a direct instance or a promise that resolves to the model.', }, ]} />

Extended usage example

typescript
await agent.getModel({
  requestContext: new RequestContext(),
})