Skip to main content
Mastra v1 is coming in January 2026. Get ahead by starting new projects with the beta or upgrade your existing project today.

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 exampleDirect link to Usage example

await agent.getModel();

ParametersDirect link to Parameters

{ runtimeContext = new RuntimeContext() }?:

{ runtimeContext?: RuntimeContext }
= new RuntimeContext()
Optional configuration object containing runtime context.

ReturnsDirect link to Returns

model:

MastraLanguageModel | Promise<MastraLanguageModel>
The language model configured for the agent, either as a direct instance or a promise that resolves to the model.

Extended usage exampleDirect link to Extended usage example

await agent.getModel({
runtimeContext: new RuntimeContext(),
});

Options parametersDirect link to Options parameters

runtimeContext?:

RuntimeContext
= undefined
Runtime context for dependency injection and contextual information.

On this page