返回 Skill 列表
extension
分类: 内容与媒体无需 API Key

libmemory

libmemory - 为LLM上下文窗口提供内存管理。WindowBuilder从对话历史和工具中构建受令牌限制的上下文。createWindow工厂简化了窗口创建过程。MemoryIndex存储对话标识符。用于管理聊天历史、构建LLM提示词以及优化上下文窗口。

person作者: jakexiaohubgithub

libmemory Skill

When to Use

  • Building context windows for LLM calls
  • Managing conversation history with token limits
  • Constructing prompts from messages and tools
  • Optimizing context for model token budgets

Key Concepts

WindowBuilder: Constructs context windows by selecting messages and tools that fit within token budget.

MemoryIndex: Stores conversation message identifiers for retrieval.

Token budgeting: Allocates tokens across system prompt, history, and tools.

Usage Patterns

Pattern 1: Build context window

import { WindowBuilder } from "@copilot-ld/libmemory";

const builder = new WindowBuilder(tokenizer);
const window = await builder.build({
  messages: conversationHistory,
  tools: availableTools,
  budget: 4000,
});

Pattern 2: Factory usage

import { createWindow } from "@copilot-ld/libmemory";

const window = await createWindow(resourceId, {
  maxTokens: 4000,
  systemPrompt: "You are a helpful assistant.",
});

Integration

Used by Memory service and Agent service. Works with libllm for token counting.