import { BaseCheckpointSaver } from "@langchain/langgraph"; import { BaseMessage } from "@langchain/core/messages"; import { type ChatPersonaConfig } from "./chat.persona.js"; import type { ChatGraphCompositeDatabase } from "../shared/interfaces/database.interface.js"; import type { Embedder } from "../shared/interfaces/embedder.interface.js"; import type { Scraper } from "../shared/interfaces/scraper.interface.js"; import type { ChatSessionReader } from "../shared/interfaces/chat-session.interface.js"; import type { ProtocolDeps } from "../shared/agent/tool.helpers.js"; /** * Factory class to build and compile the Chat Graph. * * Architecture: ReAct-Style Agent Loop * * The graph contains a single node that runs an agent loop: * 1. Agent receives messages (conversation + tool results) * 2. Agent decides: call tools OR respond to user * 3. If tools called → execute → add results → loop back * 4. If response → exit loop → stream to user * * This replaces the previous 17-node conditional routing architecture * with a flexible, LLM-driven approach that can handle multi-step * reasoning and self-correction. */ export declare class ChatGraphFactory { private database; private embedder; private scraper; private chatSession; private protocolDeps; /** Persona driving this graph's agent loop. Defaults to the orchestrator. */ private persona; private streamingService; constructor(database: ChatGraphCompositeDatabase, embedder: Embedder, scraper: Scraper, chatSession: ChatSessionReader, protocolDeps: ProtocolDeps, /** Persona driving this graph's agent loop. Defaults to the orchestrator. */ persona?: ChatPersonaConfig); /** * Returns a sibling factory sharing all dependencies but driven by a * different persona. Used to derive per-session persona factories (e.g. the * negotiator, whose identity comes from the user's personal agent row) from * the composition-root orchestrator factory without re-wiring deps. * * @param persona - The persona config for the derived factory * @returns A new ChatGraphFactory with identical deps and the given persona */ withPersona(persona: ChatPersonaConfig): ChatGraphFactory; /** * Creates and compiles the Chat Graph without persistence. * @returns Compiled StateGraph ready for invocation */ createGraph(): import("@langchain/langgraph").CompiledStateGraph<{ userId: string; networkId: string | undefined; scopeType: import("../index.js").ToolScopeType | undefined; scopeId: string | undefined; sessionId: string | undefined; messages: BaseMessage, import("@langchain/core/messages").MessageType>[]; iterationCount: number; shouldContinue: boolean; responseText: string | undefined; error: string | undefined; debugMeta: { graph: string; iterations: number; tools: import("./chat-streaming.types.js").DebugMetaToolCall[]; llm: import("./chat-streaming.types.js").DebugMetaLlm; orchestratorNegotiations?: import("./chat-streaming.types.js").DebugMetaOrchestratorNegotiations; } | undefined; routingDecision: import("./chat.state.js").RoutingDecision | undefined; subgraphResults: import("./chat.state.js").SubgraphResults | undefined; userProfile: unknown; }, { userId?: string | undefined; networkId?: string | import("@langchain/langgraph").OverwriteValue | undefined; scopeType?: import("../index.js").ToolScopeType | import("@langchain/langgraph").OverwriteValue | undefined; scopeId?: string | import("@langchain/langgraph").OverwriteValue | undefined; sessionId?: string | import("@langchain/langgraph").OverwriteValue | undefined; messages?: BaseMessage, import("@langchain/core/messages").MessageType>[] | import("@langchain/langgraph").OverwriteValue, import("@langchain/core/messages").MessageType>[]> | undefined; iterationCount?: number | import("@langchain/langgraph").OverwriteValue | undefined; shouldContinue?: boolean | import("@langchain/langgraph").OverwriteValue | undefined; responseText?: string | import("@langchain/langgraph").OverwriteValue | undefined; error?: string | import("@langchain/langgraph").OverwriteValue | undefined; debugMeta?: { graph: string; iterations: number; tools: import("./chat-streaming.types.js").DebugMetaToolCall[]; llm: import("./chat-streaming.types.js").DebugMetaLlm; orchestratorNegotiations?: import("./chat-streaming.types.js").DebugMetaOrchestratorNegotiations; } | import("@langchain/langgraph").OverwriteValue<{ graph: string; iterations: number; tools: import("./chat-streaming.types.js").DebugMetaToolCall[]; llm: import("./chat-streaming.types.js").DebugMetaLlm; orchestratorNegotiations?: import("./chat-streaming.types.js").DebugMetaOrchestratorNegotiations; } | undefined> | undefined; routingDecision?: import("./chat.state.js").RoutingDecision | import("@langchain/langgraph").OverwriteValue | undefined; subgraphResults?: import("./chat.state.js").SubgraphResults | import("@langchain/langgraph").OverwriteValue | undefined; userProfile?: unknown; }, "__start__" | "agent_loop", { userId: { (annotation: import("@langchain/langgraph").SingleReducer): import("@langchain/langgraph").BaseChannel, unknown>; (): import("@langchain/langgraph").LastValue; Root: (sd: S) => import("@langchain/langgraph").AnnotationRoot; }; networkId: import("@langchain/langgraph").BaseChannel | undefined, unknown>; scopeType: import("@langchain/langgraph").BaseChannel | undefined, unknown>; scopeId: import("@langchain/langgraph").BaseChannel | undefined, unknown>; sessionId: import("@langchain/langgraph").BaseChannel | undefined, unknown>; messages: import("@langchain/langgraph").BaseChannel, import("@langchain/core/messages").MessageType>[], BaseMessage, import("@langchain/core/messages").MessageType>[] | import("@langchain/langgraph").OverwriteValue, import("@langchain/core/messages").MessageType>[]>, unknown>; iterationCount: import("@langchain/langgraph").BaseChannel, unknown>; shouldContinue: import("@langchain/langgraph").BaseChannel, unknown>; responseText: import("@langchain/langgraph").BaseChannel | undefined, unknown>; error: import("@langchain/langgraph").BaseChannel | undefined, unknown>; debugMeta: import("@langchain/langgraph").BaseChannel<{ graph: string; iterations: number; tools: import("./chat-streaming.types.js").DebugMetaToolCall[]; llm: import("./chat-streaming.types.js").DebugMetaLlm; orchestratorNegotiations?: import("./chat-streaming.types.js").DebugMetaOrchestratorNegotiations; } | undefined, { graph: string; iterations: number; tools: import("./chat-streaming.types.js").DebugMetaToolCall[]; llm: import("./chat-streaming.types.js").DebugMetaLlm; orchestratorNegotiations?: import("./chat-streaming.types.js").DebugMetaOrchestratorNegotiations; } | import("@langchain/langgraph").OverwriteValue<{ graph: string; iterations: number; tools: import("./chat-streaming.types.js").DebugMetaToolCall[]; llm: import("./chat-streaming.types.js").DebugMetaLlm; orchestratorNegotiations?: import("./chat-streaming.types.js").DebugMetaOrchestratorNegotiations; } | undefined> | undefined, unknown>; routingDecision: import("@langchain/langgraph").BaseChannel | undefined, unknown>; subgraphResults: import("@langchain/langgraph").BaseChannel | undefined, unknown>; userProfile: import("@langchain/langgraph").BaseChannel; }, { userId: { (annotation: import("@langchain/langgraph").SingleReducer): import("@langchain/langgraph").BaseChannel, unknown>; (): import("@langchain/langgraph").LastValue; Root: (sd: S) => import("@langchain/langgraph").AnnotationRoot; }; networkId: import("@langchain/langgraph").BaseChannel | undefined, unknown>; scopeType: import("@langchain/langgraph").BaseChannel | undefined, unknown>; scopeId: import("@langchain/langgraph").BaseChannel | undefined, unknown>; sessionId: import("@langchain/langgraph").BaseChannel | undefined, unknown>; messages: import("@langchain/langgraph").BaseChannel, import("@langchain/core/messages").MessageType>[], BaseMessage, import("@langchain/core/messages").MessageType>[] | import("@langchain/langgraph").OverwriteValue, import("@langchain/core/messages").MessageType>[]>, unknown>; iterationCount: import("@langchain/langgraph").BaseChannel, unknown>; shouldContinue: import("@langchain/langgraph").BaseChannel, unknown>; responseText: import("@langchain/langgraph").BaseChannel | undefined, unknown>; error: import("@langchain/langgraph").BaseChannel | undefined, unknown>; debugMeta: import("@langchain/langgraph").BaseChannel<{ graph: string; iterations: number; tools: import("./chat-streaming.types.js").DebugMetaToolCall[]; llm: import("./chat-streaming.types.js").DebugMetaLlm; orchestratorNegotiations?: import("./chat-streaming.types.js").DebugMetaOrchestratorNegotiations; } | undefined, { graph: string; iterations: number; tools: import("./chat-streaming.types.js").DebugMetaToolCall[]; llm: import("./chat-streaming.types.js").DebugMetaLlm; orchestratorNegotiations?: import("./chat-streaming.types.js").DebugMetaOrchestratorNegotiations; } | import("@langchain/langgraph").OverwriteValue<{ graph: string; iterations: number; tools: import("./chat-streaming.types.js").DebugMetaToolCall[]; llm: import("./chat-streaming.types.js").DebugMetaLlm; orchestratorNegotiations?: import("./chat-streaming.types.js").DebugMetaOrchestratorNegotiations; } | undefined> | undefined, unknown>; routingDecision: import("@langchain/langgraph").BaseChannel | undefined, unknown>; subgraphResults: import("@langchain/langgraph").BaseChannel | undefined, unknown>; userProfile: import("@langchain/langgraph").BaseChannel; }, import("@langchain/langgraph").StateDefinition, { agent_loop: { messages: BaseMessage, import("@langchain/core/messages").MessageType>[]; responseText: string; iterationCount: number; shouldContinue: boolean; debugMeta: { graph: string; iterations: number; tools: import("./chat-streaming.types.js").DebugMetaToolCall[]; llm: import("./chat-streaming.types.js").DebugMetaLlm; orchestratorNegotiations?: import("./chat-streaming.types.js").DebugMetaOrchestratorNegotiations; discoveryQuestions?: import("./chat-streaming.types.js").DebugMetaDiscoveryQuestions; }; error?: undefined; } | { error: string; responseText: string; shouldContinue: boolean; messages?: undefined; iterationCount?: undefined; debugMeta?: undefined; }; }, unknown, unknown, []>; /** * Creates a streaming-enabled graph with optional checkpointer for persistence. * @param checkpointer - Optional checkpointer (e.g., MemorySaver or PostgresSaver) * @returns Compiled StateGraph ready for streaming */ createStreamingGraph(checkpointer?: BaseCheckpointSaver): import("@langchain/langgraph").CompiledStateGraph<{ userId: string; networkId: string | undefined; scopeType: import("../index.js").ToolScopeType | undefined; scopeId: string | undefined; sessionId: string | undefined; messages: BaseMessage, import("@langchain/core/messages").MessageType>[]; iterationCount: number; shouldContinue: boolean; responseText: string | undefined; error: string | undefined; debugMeta: { graph: string; iterations: number; tools: import("./chat-streaming.types.js").DebugMetaToolCall[]; llm: import("./chat-streaming.types.js").DebugMetaLlm; orchestratorNegotiations?: import("./chat-streaming.types.js").DebugMetaOrchestratorNegotiations; } | undefined; routingDecision: import("./chat.state.js").RoutingDecision | undefined; subgraphResults: import("./chat.state.js").SubgraphResults | undefined; userProfile: unknown; }, { userId?: string | undefined; networkId?: string | import("@langchain/langgraph").OverwriteValue | undefined; scopeType?: import("../index.js").ToolScopeType | import("@langchain/langgraph").OverwriteValue | undefined; scopeId?: string | import("@langchain/langgraph").OverwriteValue | undefined; sessionId?: string | import("@langchain/langgraph").OverwriteValue | undefined; messages?: BaseMessage, import("@langchain/core/messages").MessageType>[] | import("@langchain/langgraph").OverwriteValue, import("@langchain/core/messages").MessageType>[]> | undefined; iterationCount?: number | import("@langchain/langgraph").OverwriteValue | undefined; shouldContinue?: boolean | import("@langchain/langgraph").OverwriteValue | undefined; responseText?: string | import("@langchain/langgraph").OverwriteValue | undefined; error?: string | import("@langchain/langgraph").OverwriteValue | undefined; debugMeta?: { graph: string; iterations: number; tools: import("./chat-streaming.types.js").DebugMetaToolCall[]; llm: import("./chat-streaming.types.js").DebugMetaLlm; orchestratorNegotiations?: import("./chat-streaming.types.js").DebugMetaOrchestratorNegotiations; } | import("@langchain/langgraph").OverwriteValue<{ graph: string; iterations: number; tools: import("./chat-streaming.types.js").DebugMetaToolCall[]; llm: import("./chat-streaming.types.js").DebugMetaLlm; orchestratorNegotiations?: import("./chat-streaming.types.js").DebugMetaOrchestratorNegotiations; } | undefined> | undefined; routingDecision?: import("./chat.state.js").RoutingDecision | import("@langchain/langgraph").OverwriteValue | undefined; subgraphResults?: import("./chat.state.js").SubgraphResults | import("@langchain/langgraph").OverwriteValue | undefined; userProfile?: unknown; }, "__start__" | "agent_loop", { userId: { (annotation: import("@langchain/langgraph").SingleReducer): import("@langchain/langgraph").BaseChannel, unknown>; (): import("@langchain/langgraph").LastValue; Root: (sd: S) => import("@langchain/langgraph").AnnotationRoot; }; networkId: import("@langchain/langgraph").BaseChannel | undefined, unknown>; scopeType: import("@langchain/langgraph").BaseChannel | undefined, unknown>; scopeId: import("@langchain/langgraph").BaseChannel | undefined, unknown>; sessionId: import("@langchain/langgraph").BaseChannel | undefined, unknown>; messages: import("@langchain/langgraph").BaseChannel, import("@langchain/core/messages").MessageType>[], BaseMessage, import("@langchain/core/messages").MessageType>[] | import("@langchain/langgraph").OverwriteValue, import("@langchain/core/messages").MessageType>[]>, unknown>; iterationCount: import("@langchain/langgraph").BaseChannel, unknown>; shouldContinue: import("@langchain/langgraph").BaseChannel, unknown>; responseText: import("@langchain/langgraph").BaseChannel | undefined, unknown>; error: import("@langchain/langgraph").BaseChannel | undefined, unknown>; debugMeta: import("@langchain/langgraph").BaseChannel<{ graph: string; iterations: number; tools: import("./chat-streaming.types.js").DebugMetaToolCall[]; llm: import("./chat-streaming.types.js").DebugMetaLlm; orchestratorNegotiations?: import("./chat-streaming.types.js").DebugMetaOrchestratorNegotiations; } | undefined, { graph: string; iterations: number; tools: import("./chat-streaming.types.js").DebugMetaToolCall[]; llm: import("./chat-streaming.types.js").DebugMetaLlm; orchestratorNegotiations?: import("./chat-streaming.types.js").DebugMetaOrchestratorNegotiations; } | import("@langchain/langgraph").OverwriteValue<{ graph: string; iterations: number; tools: import("./chat-streaming.types.js").DebugMetaToolCall[]; llm: import("./chat-streaming.types.js").DebugMetaLlm; orchestratorNegotiations?: import("./chat-streaming.types.js").DebugMetaOrchestratorNegotiations; } | undefined> | undefined, unknown>; routingDecision: import("@langchain/langgraph").BaseChannel | undefined, unknown>; subgraphResults: import("@langchain/langgraph").BaseChannel | undefined, unknown>; userProfile: import("@langchain/langgraph").BaseChannel; }, { userId: { (annotation: import("@langchain/langgraph").SingleReducer): import("@langchain/langgraph").BaseChannel, unknown>; (): import("@langchain/langgraph").LastValue; Root: (sd: S) => import("@langchain/langgraph").AnnotationRoot; }; networkId: import("@langchain/langgraph").BaseChannel | undefined, unknown>; scopeType: import("@langchain/langgraph").BaseChannel | undefined, unknown>; scopeId: import("@langchain/langgraph").BaseChannel | undefined, unknown>; sessionId: import("@langchain/langgraph").BaseChannel | undefined, unknown>; messages: import("@langchain/langgraph").BaseChannel, import("@langchain/core/messages").MessageType>[], BaseMessage, import("@langchain/core/messages").MessageType>[] | import("@langchain/langgraph").OverwriteValue, import("@langchain/core/messages").MessageType>[]>, unknown>; iterationCount: import("@langchain/langgraph").BaseChannel, unknown>; shouldContinue: import("@langchain/langgraph").BaseChannel, unknown>; responseText: import("@langchain/langgraph").BaseChannel | undefined, unknown>; error: import("@langchain/langgraph").BaseChannel | undefined, unknown>; debugMeta: import("@langchain/langgraph").BaseChannel<{ graph: string; iterations: number; tools: import("./chat-streaming.types.js").DebugMetaToolCall[]; llm: import("./chat-streaming.types.js").DebugMetaLlm; orchestratorNegotiations?: import("./chat-streaming.types.js").DebugMetaOrchestratorNegotiations; } | undefined, { graph: string; iterations: number; tools: import("./chat-streaming.types.js").DebugMetaToolCall[]; llm: import("./chat-streaming.types.js").DebugMetaLlm; orchestratorNegotiations?: import("./chat-streaming.types.js").DebugMetaOrchestratorNegotiations; } | import("@langchain/langgraph").OverwriteValue<{ graph: string; iterations: number; tools: import("./chat-streaming.types.js").DebugMetaToolCall[]; llm: import("./chat-streaming.types.js").DebugMetaLlm; orchestratorNegotiations?: import("./chat-streaming.types.js").DebugMetaOrchestratorNegotiations; } | undefined> | undefined, unknown>; routingDecision: import("@langchain/langgraph").BaseChannel | undefined, unknown>; subgraphResults: import("@langchain/langgraph").BaseChannel | undefined, unknown>; userProfile: import("@langchain/langgraph").BaseChannel; }, import("@langchain/langgraph").StateDefinition, { agent_loop: { messages: BaseMessage, import("@langchain/core/messages").MessageType>[]; responseText: string; iterationCount: number; shouldContinue: boolean; debugMeta: { graph: string; iterations: number; tools: import("./chat-streaming.types.js").DebugMetaToolCall[]; llm: import("./chat-streaming.types.js").DebugMetaLlm; orchestratorNegotiations?: import("./chat-streaming.types.js").DebugMetaOrchestratorNegotiations; discoveryQuestions?: import("./chat-streaming.types.js").DebugMetaDiscoveryQuestions; }; error?: undefined; } | { error: string; responseText: string; shouldContinue: boolean; messages?: undefined; iterationCount?: undefined; debugMeta?: undefined; }; }, unknown, unknown, []>; /** * Load previous messages from a session and convert to LangChain messages. * Handles token truncation to fit within context window limits. * * @param sessionId - The session ID to load context from * @param maxMessages - Maximum number of messages to load (default: 20) * @returns Array of LangChain BaseMessage objects */ loadSessionContext(sessionId: string, maxMessages?: number): Promise; /** * Streams chat events with full session context. * Delegates to ChatGraphStreamingService. */ streamChatEventsWithContext(input: { userId: string; message: string; sessionId: string; maxContextMessages?: number; networkId?: string; prefillMessages?: Array<{ role: "assistant" | "user"; content: string; }>; /** Per-run identifier used to form a composite LangGraph thread_id (sessionId:runId). */ runId?: string; }, checkpointer?: BaseCheckpointSaver, signal?: AbortSignal): AsyncGenerator; /** * Streams chat events from the graph execution. * Delegates to ChatGraphStreamingService. */ streamChatEvents(input: { userId: string; messages: BaseMessage[]; }, sessionId: string, checkpointer?: BaseCheckpointSaver, signal?: AbortSignal): AsyncGenerator; /** * Internal method to build the graph structure. * @returns Uncompiled StateGraph */ private buildGraph; }