fix: get context windows from server (#787)

Co-authored-by: cpacker <packercharles@gmail.com>
Co-authored-by: Letta <noreply@letta.com>
This commit is contained in:
Ari Webb
2026-02-03 16:15:09 -08:00
committed by GitHub
parent be8ae56abe
commit e411940d5c
4 changed files with 20 additions and 8 deletions

View File

@@ -8,6 +8,7 @@ import type {
AgentType,
} from "@letta-ai/letta-client/resources/agents/agents";
import { DEFAULT_AGENT_NAME } from "../constants";
import { getModelContextWindow } from "./available-models";
import { getClient } from "./client";
import { getDefaultMemoryBlocks } from "./memory";
import {
@@ -282,10 +283,11 @@ export async function createAgent(
}
// Get the model's context window from its configuration (if known)
// For unknown models (e.g., from self-hosted servers), don't set a context window
// and let the server use its default
// First try models.json, then fall back to API-cached context window for BYOK models
const modelUpdateArgs = getModelUpdateArgs(modelHandle);
const contextWindow = modelUpdateArgs?.context_window as number | undefined;
const contextWindow =
(modelUpdateArgs?.context_window as number | undefined) ??
(await getModelContextWindow(modelHandle));
// Resolve system prompt content:
// 1. If systemPromptCustom is provided, use it as-is