Agent.getLLM()
The .getLLM() method retrieves the language model instance configured for an agent, resolving it if it's a function. This method provides access to the underlying LLM that powers the agent's capabilities.
Usage exampleDirect link to Usage example
await agent.getLLM();
ParametersDirect link to Parameters
options?:
{ requestContext?: RequestContext; model?: MastraLanguageModel | DynamicArgument<MastraLanguageModel> }
= {}
Optional configuration object containing request context and optional model override.
ReturnsDirect link to Returns
llm:
MastraLLMV1 | Promise<MastraLLMV1>
The language model instance configured for the agent, either as a direct instance or a promise that resolves to the LLM.
Extended usage exampleDirect link to Extended usage example
await agent.getLLM({
requestContext: new RequestContext(),
model: "openai/gpt-5.1",
});
Options parametersDirect link to Options parameters
requestContext?:
RequestContext
= new RequestContext()
Request Context for dependency injection and contextual information.
model?:
MastraLanguageModel | DynamicArgument<MastraLanguageModel>
Optional model override. If provided, this model will be used used instead of the agent's configured model.