MCPcopy Index your code
hub / github.com/simstudioai/sim / applyContextWindowLimit

Method applyContextWindowLimit

apps/sim/executor/handlers/agent/memory.ts:180–199  ·  view source on GitHub ↗
(messages: Message[], model?: string)

Source from the content-addressed store, hash-verified

178 }
179
180 private applyContextWindowLimit(messages: Message[], model?: string): Message[] {
181 if (!model) return messages
182
183 for (const provider of Object.values(PROVIDER_DEFINITIONS)) {
184 if (provider.contextInformationAvailable === false) continue
185
186 const matchesPattern = provider.modelPatterns?.some((p) => p.test(model))
187 const matchesModel = provider.models.some((m) => m.id === model)
188
189 if (matchesPattern || matchesModel) {
190 const modelDef = provider.models.find((m) => m.id === model)
191 if (modelDef?.contextWindow) {
192 const maxTokens = Math.floor(modelDef.contextWindow * MEMORY.CONTEXT_WINDOW_UTILIZATION)
193 return this.applyTokenWindow(messages, maxTokens, model)
194 }
195 }
196 }
197
198 return messages
199 }
200
201 private async fetchMemory(workspaceId: string, key: string): Promise<Message[]> {
202 const result = await db

Callers 1

fetchMemoryMessagesMethod · 0.95

Calls 2

applyTokenWindowMethod · 0.95
testMethod · 0.80

Tested by

no test coverage detected