Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -321,16 +321,14 @@ SAGEMAKER_ACCEPT=application/json # Response content type
# =============================================================================
# CONVERSATION MEMORY CONFIGURATION (Optional)
# =============================================================================
# Enable conversation memory feature (disabled by default)
NEUROLINK_MEMORY_ENABLED=false
# Enable conversation memory feature (ENABLED BY DEFAULT)
NEUROLINK_MEMORY_ENABLED=true # Enable conversation memory (default: true)

# Memory storage type (memory or redis)
STORAGE_TYPE=memory # Options: memory, redis

# Memory limits
NEUROLINK_MEMORY_MAX_SESSIONS=50 # Maximum number of sessions to keep in memory
NEUROLINK_MEMORY_MAX_TURNS_PER_SESSION=50 # Maximum conversation turns per session

# Redis Storage Configuration (used when STORAGE_TYPE=redis)
REDIS_HOST=localhost # Redis server hostname
REDIS_PORT=6379 # Redis server port
Expand Down Expand Up @@ -403,12 +401,16 @@ NEUROLINK_MAX_TOOLS_PER_PROVIDER=5
# Config File Location
NEUROLINK_CONFIG_FILE=./neurolink.config.json

# Summarization (Conversation Memory)
NEUROLINK_SUMMARIZATION_ENABLED=false
NEUROLINK_SUMMARIZATION_THRESHOLD_TURNS=20
NEUROLINK_SUMMARIZATION_TARGET_TURNS=10
NEUROLINK_SUMMARIZATION_PROVIDER=google-ai
NEUROLINK_SUMMARIZATION_MODEL=gemini-2.5-flash
# Summarization (Conversation Memory) - TOKEN-BASED MEMORY ENABLED BY DEFAULT
# Token-based memory is enabled by default and uses 80% of each model's context window
NEUROLINK_SUMMARIZATION_ENABLED=true # Enable summarization (default: true)
NEUROLINK_TOKEN_THRESHOLD=50000 # Optional: Override token threshold (default: 80% of model context)
NEUROLINK_SUMMARIZATION_PROVIDER=vertex # Provider for summarization (default: vertex)
NEUROLINK_SUMMARIZATION_MODEL=gemini-2.5-flash # Model for summarization (default: gemini-2.5-flash)
Comment thread
coderabbitai[bot] marked this conversation as resolved.

# Deprecated: Turn-based memory settings (use TOKEN_THRESHOLD instead)
# NEUROLINK_SUMMARIZATION_THRESHOLD_TURNS=20 # Deprecated: Use token threshold
# NEUROLINK_SUMMARIZATION_TARGET_TURNS=10 # Deprecated: Use token threshold

# Default Generation Parameters
NEUROLINK_DEFAULT_MAX_TOKENS=4096
Expand Down
5 changes: 5 additions & 0 deletions src/cli/loop/optionsSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,9 @@ export const textGenerationOptionsSchema: Record<
type: "string",
description: "Context about tools/MCPs used in the interaction.",
},
enableSummarization: {
type: "boolean",
description:
"Enable or disable automatic conversation summarization for this request.",
},
};
34 changes: 29 additions & 5 deletions src/lib/config/conversationMemory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ IMPORTANT: You are continuing an ongoing conversation. The previous messages in

Always reference and build upon this conversation history when relevant. If the user asks about information mentioned earlier in the conversation, refer to those previous messages to provide accurate, contextual responses.`;

/**
* Percentage of model context window to use for conversation memory threshold
* Default: 80% of model's context window
*/
export const MEMORY_THRESHOLD_PERCENTAGE = 0.8;

/**
* Fallback token threshold if model context unknown
*/
export const DEFAULT_FALLBACK_THRESHOLD = 50000;

/**
* Ratio of threshold to keep as recent unsummarized messages
* When summarization triggers, this percentage of tokens from the end
* are preserved as detailed messages, while older content gets summarized.
*/
export const RECENT_MESSAGES_RATIO = 0.3;

/**
* Structured output instructions for JSON/structured output mode
* Used to ensure AI providers output only valid JSON without conversational filler
Expand All @@ -57,17 +75,23 @@ export function getConversationMemoryDefaults(): ConversationMemoryConfig {
enabled: process.env.NEUROLINK_MEMORY_ENABLED === "true",
maxSessions:
Number(process.env.NEUROLINK_MEMORY_MAX_SESSIONS) || DEFAULT_MAX_SESSIONS,
enableSummarization:
process.env.NEUROLINK_SUMMARIZATION_ENABLED !== "false",
tokenThreshold: process.env.NEUROLINK_TOKEN_THRESHOLD
? Number(process.env.NEUROLINK_TOKEN_THRESHOLD)
: undefined,
summarizationProvider:
process.env.NEUROLINK_SUMMARIZATION_PROVIDER || "vertex",
summarizationModel:
process.env.NEUROLINK_SUMMARIZATION_MODEL || "gemini-2.5-flash",

// Deprecated (for backward compatibility)
maxTurnsPerSession:
Number(process.env.NEUROLINK_MEMORY_MAX_TURNS_PER_SESSION) ||
DEFAULT_MAX_TURNS_PER_SESSION,
enableSummarization: process.env.NEUROLINK_SUMMARIZATION_ENABLED === "true",
summarizationThresholdTurns:
Number(process.env.NEUROLINK_SUMMARIZATION_THRESHOLD_TURNS) || 20,
summarizationTargetTurns:
Number(process.env.NEUROLINK_SUMMARIZATION_TARGET_TURNS) || 10,
summarizationProvider:
process.env.NEUROLINK_SUMMARIZATION_PROVIDER || "vertex",
summarizationModel:
process.env.NEUROLINK_SUMMARIZATION_MODEL || "gemini-2.5-flash",
};
}
3 changes: 0 additions & 3 deletions src/lib/core/conversationMemoryFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ export function createConversationMemoryManager(
config: {
enabled: config.enabled,
maxSessions: config.maxSessions,
maxTurnsPerSession: config.maxTurnsPerSession,
enableSummarization: config.enableSummarization,
summarizationThresholdTurns: config.summarizationThresholdTurns,
summarizationTargetTurns: config.summarizationTargetTurns,
summarizationProvider: config.summarizationProvider,
summarizationModel: config.summarizationModel,
},
Expand Down
9 changes: 0 additions & 9 deletions src/lib/core/conversationMemoryInitializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,6 @@ export async function initializeConversationMemory(config?: {

logger.info(
"[conversationMemoryInitializer] Redis conversation memory manager created successfully",
{
configSource,
host: redisConfig.host || "localhost",
port: redisConfig.port || 6379,
keyPrefix: redisConfig.keyPrefix || "neurolink:conversation:",
maxSessions: memoryConfig.maxSessions,
maxTurnsPerSession: memoryConfig.maxTurnsPerSession,
managerType: redisMemoryManager?.constructor?.name,
},
);

// Perform basic validation
Expand Down
Loading
Loading