import { ChatOpenAI } from "@langchain/openai"; import type { AIMessageChunk } from "@langchain/core/messages"; import type { BaseLanguageModelInput, StructuredOutputMethodOptions } from "@langchain/core/language_models/base"; import type { Runnable } from "@langchain/core/runnables"; import type { InteropZodType } from "@langchain/core/utils/types"; /** Settings that can be configured per agent. */ export interface ModelSettings { model: string; temperature?: number; maxTokens?: number; reasoning?: { effort?: 'minimal' | 'low' | 'medium' | 'high' | 'xhigh'; exclude?: boolean; }; } /** * Runtime configuration for the protocol package. * When passed via `ToolContext.modelConfig`, all fields (`apiKey`, `baseURL`, `chatModel`, * `chatReasoningEffort`) are honored by `ChatAgent` when the chat graph runs. * Other protocol agents don't read from `ToolContext` but may accept an explicit `ModelConfig` * as a direct parameter to `createModel()`. * All fields fall back to environment variables if not provided. */ export interface ModelConfig { /** OpenRouter API key. Falls back to OPENROUTER_API_KEY env var. */ apiKey?: string; /** OpenRouter base URL. Falls back to OPENROUTER_BASE_URL env var. */ baseURL?: string; /** Override the chat agent model. Falls back to CHAT_MODEL env var. */ chatModel?: string; /** Override the chat reasoning effort. Falls back to CHAT_REASONING_EFFORT env var. */ chatReasoningEffort?: 'minimal' | 'low' | 'medium' | 'high' | 'xhigh'; } /** Per-agent model settings before canonical assignments are applied. */ declare function getBaseModelConfig(config?: ModelConfig): { [Agent in "intentInferrer" | "intentIndexer" | "intentVerifier" | "intentReconciler" | "intentClarifier" | "profileGenerator" | "hydeGenerator" | "hydeValidator" | "lensInferrer" | "opportunityEvaluator" | "opportunityPresenter" | "negotiator" | "negotiationScreener" | "negotiationReflector" | "homeCategorizer" | "suggestionGenerator" | "chatTitleGenerator" | "negotiationInsights" | "chatContextSummarizer" | "questioner" | "signalIntakePack" | "negotiationSummarizer" | "poolDiscriminatorMiner" | "poolDiscriminatorAssigner" | "negotiationEvidenceMiner" | "inviteGenerator" | "premiseAnalyzer" | "premiseDecomposer" | "premiseIndexer" | "userContextGenerator" | "networkRecommender" | "interruptClassifier" | "chat"]: Omit<{ readonly intentInferrer: { readonly model: "google/gemini-2.5-flash"; }; readonly intentIndexer: { readonly model: "google/gemini-2.5-flash"; }; readonly intentVerifier: { readonly model: "google/gemini-2.5-flash"; }; readonly intentReconciler: { readonly model: "google/gemini-2.5-flash"; }; readonly intentClarifier: { readonly model: "google/gemini-2.5-flash"; }; readonly profileGenerator: { readonly model: "google/gemini-2.5-flash"; }; readonly hydeGenerator: { readonly model: "google/gemini-2.5-flash"; }; readonly hydeValidator: { readonly model: "google/gemini-2.5-flash"; readonly temperature: 0; readonly maxTokens: 2048; }; readonly lensInferrer: { readonly model: "google/gemini-2.5-flash"; }; readonly opportunityEvaluator: { readonly model: "google/gemini-2.5-flash"; }; readonly opportunityPresenter: { readonly model: "google/gemini-2.5-flash"; }; readonly negotiator: { readonly model: "google/gemini-2.5-flash"; }; readonly negotiationScreener: { readonly model: "google/gemini-2.5-flash"; readonly temperature: 0.2; readonly maxTokens: 1024; }; readonly negotiationReflector: { readonly model: "google/gemini-2.5-flash"; readonly temperature: 0.3; readonly maxTokens: 2048; }; readonly homeCategorizer: { readonly model: "google/gemini-2.5-flash"; }; readonly suggestionGenerator: { readonly model: "google/gemini-2.5-flash"; readonly temperature: 0.4; readonly maxTokens: 512; }; readonly chatTitleGenerator: { readonly model: "google/gemini-2.5-flash"; readonly temperature: 0.3; readonly maxTokens: 32; }; readonly negotiationInsights: { readonly model: "google/gemini-2.5-flash"; readonly temperature: 0.4; readonly maxTokens: 512; }; readonly chatContextSummarizer: { readonly model: "google/gemini-2.5-flash"; readonly temperature: 0.2; readonly maxTokens: 512; }; readonly questioner: { readonly model: "google/gemini-2.5-flash"; readonly temperature: 0.5; readonly maxTokens: 1024; }; readonly signalIntakePack: { readonly model: "google/gemini-2.5-flash"; readonly temperature: 0.3; readonly maxTokens: 1024; }; readonly negotiationSummarizer: { readonly model: "google/gemini-2.5-flash"; readonly temperature: 0.2; readonly maxTokens: 256; }; readonly poolDiscriminatorMiner: { readonly model: "google/gemini-2.5-flash"; readonly temperature: 0.2; readonly maxTokens: 4096; }; readonly poolDiscriminatorAssigner: { readonly model: "google/gemini-2.5-flash"; readonly temperature: 0.1; readonly maxTokens: 16384; }; readonly negotiationEvidenceMiner: { readonly model: "google/gemini-2.5-flash"; readonly temperature: 0.2; readonly maxTokens: 4096; }; readonly inviteGenerator: { readonly model: "google/gemini-2.5-flash"; readonly temperature: 0.3; readonly maxTokens: 512; }; readonly premiseAnalyzer: { readonly model: "google/gemini-2.5-flash"; }; readonly premiseDecomposer: { readonly model: "google/gemini-2.5-flash"; }; readonly premiseIndexer: { readonly model: "google/gemini-2.5-flash"; }; readonly userContextGenerator: { readonly model: "google/gemini-2.5-flash"; readonly temperature: 0.3; readonly maxTokens: 512; }; readonly networkRecommender: { readonly model: "google/gemini-2.5-flash"; readonly temperature: 0.2; readonly maxTokens: 512; }; readonly interruptClassifier: { readonly model: "google/gemini-2.5-flash"; readonly temperature: 0; readonly maxTokens: 16; }; readonly chat: { readonly model: "google/gemini-3-pro-preview"; readonly maxTokens: 8192; readonly reasoning: { readonly effort: NonNullable["effort"]; readonly exclude: true; }; }; }[Agent], "model"> & { model: string; }; }; /** Key identifying one of the per-agent model configurations. */ export type ModelAgent = keyof ReturnType; /** * Returns the model name string for the given agent key. * @param agent - Key from MODEL_CONFIG identifying which agent's settings to use. * @param config - Optional runtime config overrides. */ export declare function getModelName(agent: ModelAgent, config?: ModelConfig): string; /** * Creates a ChatOpenAI instance configured for OpenRouter. * @param agent - Key identifying which agent's model settings to use. * @param config - Optional runtime config overrides. */ export declare function createModel(agent: ModelAgent, config?: ModelConfig): ChatOpenAI; /** * Creates the fallback ChatOpenAI for an agent, or undefined when fallbacks * are disabled or the fallback would be the same model as the primary. * Reuses the agent's sampling settings but drops `reasoning` kwargs, which are * primary-model specific. */ export declare function createFallbackModel(agent: ModelAgent, config?: ModelConfig): ChatOpenAI | undefined; /** * Creates a structured-output model with runnable-level retry and cross-model * fallback. Equivalent to `createModel(agent).withStructuredOutput(schema, options)` * plus `.withRetry(...)` and `.withFallbacks([...])`. * * Retry covers transient provider errors *and* schema parse/validation * failures; the fallback model (see OPENROUTER_FALLBACK_MODEL) is bound to the * same schema so a provider outage degrades to a different vendor instead of * failing the call. Abort signals pass through: aborts are never retried and * skip the fallback. * * @param agent - Key identifying which agent's model settings to use. * @param outputSchema - Zod schema or JSON-schema response format. * @param options - Same options as `withStructuredOutput` (e.g. `{ name }`). * @param config - Optional runtime model config overrides. */ export declare function createStructuredModel = Record>(agent: ModelAgent, outputSchema: InteropZodType | Record, options?: StructuredOutputMethodOptions, config?: ModelConfig): Runnable; /** * Creates a plain-completion model with runnable-level retry and cross-model * fallback, for call sites that `invoke()` the model directly (no * `withStructuredOutput`/`bindTools`/`stream` chaining). * * @param agent - Key identifying which agent's model settings to use. * @param config - Optional runtime model config overrides. */ export declare function createResilientModel(agent: ModelAgent, config?: ModelConfig): Runnable; export {};