( modelHandle: string, models: LettaModel[], currentConfig: LlmConfig | undefined, )
| 399 | * precedence over the current value. |
| 400 | */ |
| 401 | export function buildLlmConfig( |
| 402 | modelHandle: string, |
| 403 | models: LettaModel[], |
| 404 | currentConfig: LlmConfig | undefined, |
| 405 | ): LlmConfig { |
| 406 | const slashIdx = modelHandle.indexOf('/'); |
| 407 | const providerName = slashIdx > 0 ? modelHandle.substring(0, slashIdx) : undefined; |
| 408 | const modelName = slashIdx > 0 ? modelHandle.substring(slashIdx + 1) : modelHandle; |
| 409 | |
| 410 | const modelInfo = findModel(models, modelHandle); |
| 411 | |
| 412 | // Spread current config to preserve settings, then override model fields |
| 413 | const config: LlmConfig = { |
| 414 | ...(currentConfig || {}), |
| 415 | model: modelName, |
| 416 | handle: modelHandle, |
| 417 | provider_name: providerName || modelInfo?.provider_type || currentConfig?.provider_name, |
| 418 | model_endpoint_type: modelInfo?.provider_type || currentConfig?.model_endpoint_type, |
| 419 | }; |
| 420 | |
| 421 | // LETTA_CONTEXT_WINDOW env var overrides the current value |
| 422 | const envContextWindow = process.env.LETTA_CONTEXT_WINDOW; |
| 423 | if (envContextWindow) { |
| 424 | const parsed = parseInt(envContextWindow, 10); |
| 425 | if (!isNaN(parsed) && parsed > 0) { |
| 426 | config.context_window = parsed; |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | return config; |
| 431 | } |
| 432 | |
| 433 | /** |
| 434 | * Update agent's model configuration via the llm_config PATCH. |
no test coverage detected