跳到主要内容
非官方简体中文翻译,内容版权归 Mastra 所有,遵循 Apache-2.0 许可。

Agent.getLLM()

The .getLLM() method retrieves the language model instance configured for an agent, resolving it if it's a function. You can also pass a request-scoped model override without mutating the agent's configured model.

Usage example
Usage example的直接链接

await agent.getLLM()
await agent.getLLM({
model: 'openai/gpt-5.6-sol',
})

Parameters
Parameters的直接链接

options?:

{ requestContext?: RequestContext; model?: MastraModelConfig | DynamicArgument<MastraModelConfig> }
= {}
Optional configuration object containing request context and an optional request-scoped model override.
{ requestContext?: RequestContext; model?: MastraModelConfig | DynamicArgument<MastraModelConfig> }

requestContext?:

RequestContext
Request Context for dependency injection and contextual information.

model?:

MastraModelConfig | DynamicArgument<MastraModelConfig>
Optional request-scoped model override. The agent's configured model is not mutated.

Returns
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 example
Extended usage example的直接链接

await agent.getLLM({
requestContext: new RequestContext(),
model: 'openai/gpt-5.6-sol',
})