CoherenceManager (context/coherence-manager.ts)

EstateWise-Chapel-Hill-Chatbot · agentic-ai/src/context/coherence-manager.ts · typescript · MIT
ai, tag:knn-classified

* Coherence manager: tracks conversation turns, entities, and summaries to maintain coherent multi-turn context. /

// Source: https://github.com/hoangsonww/EstateWise-Chapel-Hill-Chatbot | License: MIT | Copyright 2026 Son Nguyen
// Provided via justclaw.it.com; keep this notice with the code.
/**
 * Coherence manager: tracks conversation turns, entities, and
 * summaries to maintain coherent multi-turn context.
 */

export interface CoherenceContext {
  summary: string | null;
  entities: Record<string, string[]>;
  recentMessages: CoherenceMessage[];
  totalTurns: number;
  estimatedTokens: number;
}

export interface CoherenceMessage {
  role: "user" | "assistant" | "system" | "tool";
  content: string;
  turn: number;
}

export class CoherenceManager {
  private messages: CoherenceMessage[] = [];
  private entities = new Map<string, Set<string>>();
  private summary: string | null = null;
  private

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key