@kernel.chat/kbot 3.13.1 → 3.14.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -12
- package/dist/consultation.d.ts +117 -0
- package/dist/consultation.d.ts.map +1 -0
- package/dist/consultation.js +388 -0
- package/dist/consultation.js.map +1 -0
- package/dist/packages/kbot/src/tools/mcp-client.d.ts +2 -0
- package/dist/packages/kbot/src/tools/mcp-client.d.ts.map +1 -0
- package/dist/packages/kbot/src/tools/mcp-client.js +132 -0
- package/dist/packages/kbot/src/tools/mcp-client.js.map +1 -0
- package/dist/packages/kbot/src/tools/mcp-discovery.d.ts +2 -0
- package/dist/packages/kbot/src/tools/mcp-discovery.d.ts.map +1 -0
- package/dist/packages/kbot/src/tools/mcp-discovery.js +433 -0
- package/dist/packages/kbot/src/tools/mcp-discovery.js.map +1 -0
- package/dist/packages/kbot/src/tools/memory-harness.d.ts +2 -0
- package/dist/packages/kbot/src/tools/memory-harness.d.ts.map +1 -0
- package/dist/packages/kbot/src/tools/memory-harness.js +542 -0
- package/dist/packages/kbot/src/tools/memory-harness.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,24 +23,28 @@ npm install -g @kernel.chat/kbot
|
|
|
23
23
|
|
|
24
24
|
---
|
|
25
25
|
|
|
26
|
-
## What's New in v3.
|
|
26
|
+
## What's New in v3.13
|
|
27
27
|
|
|
28
28
|
| Feature | What it means |
|
|
29
29
|
|---------|---------------|
|
|
30
|
-
| **
|
|
31
|
-
| **
|
|
32
|
-
| **
|
|
33
|
-
| **
|
|
34
|
-
| **
|
|
35
|
-
| **
|
|
36
|
-
| **
|
|
37
|
-
| **
|
|
30
|
+
| **Self-Improving** | kbot modifies its own code, tests it, and publishes new versions to npm — autonomously. |
|
|
31
|
+
| **Discovery Daemon** | 24/7 background service — scans HN, GitHub, Reddit, arXiv. Thinks locally via MLX/Ollama ($0). |
|
|
32
|
+
| **OpenClaw Plugin** | kbot is the cognitive engine inside OpenClaw — 50+ messaging channels (WhatsApp, Discord, Telegram). |
|
|
33
|
+
| **Replit Integration** | Auto-detects Replit, activates lite mode. `--lite` flag for cloud IDEs. |
|
|
34
|
+
| **Cognitive Interference** | 11 cognitive modules measured for constructive/destructive interference. Research paper included. |
|
|
35
|
+
| **Standalone Packages** | Brain extracted as independent npm packages: `@kernel.chat/skill-router`, `memory-tiers`, `tool-forge`, `prompt-evolver`. |
|
|
36
|
+
| **MLX on Apple Silicon** | Claude Opus-distilled models run natively. Local brain for the daemon. |
|
|
37
|
+
| **LATS Tree Planning** | Monte Carlo Tree Search for branching plans instead of linear. |
|
|
38
|
+
| **Prompt Evolution** | GEPA-style self-optimizing prompts — evolve from execution traces, auto-rollback bad mutations. |
|
|
39
|
+
| **Collective Learning** | Opt-in anonymized signals. More users → smarter routing for everyone. |
|
|
40
|
+
| **A2A Protocol** | Agent-to-Agent discovery and task delegation. |
|
|
41
|
+
| **11 Cognitive Modules** | Based on peer-reviewed papers. Not metaphors — TypeScript implementations. |
|
|
38
42
|
|
|
39
43
|
---
|
|
40
44
|
|
|
41
45
|
## Why kbot?
|
|
42
46
|
|
|
43
|
-
Other AI
|
|
47
|
+
Other AI agents are static — fixed tools, single providers, no memory, no learning. kbot is the first AI agent that **evolves itself**:
|
|
44
48
|
|
|
45
49
|
- **Forges its own tools** — When kbot encounters a task it can't handle, it creates a new tool on the spot via `forge_tool`. The tool persists, gets tested, and can be shared via the Forge Registry.
|
|
46
50
|
- **Self-evolving** — Autopoietic health monitoring (`kbot vitals`) tracks tool success rates, token budgets, and memory pressure. The immune agent self-audits for drift and regressions.
|
|
@@ -342,7 +346,7 @@ kbot -p "query" > output.txt # Pipe mode — clean output for sc
|
|
|
342
346
|
|
|
343
347
|
## Under the Hood
|
|
344
348
|
|
|
345
|
-
kbot's agent loop runs
|
|
349
|
+
kbot's agent loop runs 11 always-on cognition modules based on peer-reviewed research:
|
|
346
350
|
|
|
347
351
|
| Module | Paper | What it does |
|
|
348
352
|
|--------|-------|-------------|
|
|
@@ -356,8 +360,21 @@ kbot's agent loop runs 10 always-on cognition modules based on peer-reviewed res
|
|
|
356
360
|
| Godel Limits | Godel/UBC | Stuck-loop detection |
|
|
357
361
|
| Simulation | Wolpert, 2008 | Change impact prediction |
|
|
358
362
|
| Emergent Swarm | Project Sid, 2024 | Dynamic role discovery |
|
|
363
|
+
| Cognitive Interference | Hernandez, 2026 | Measures constructive/destructive interference between modules |
|
|
359
364
|
|
|
360
|
-
These aren't metaphors. They're TypeScript modules with paper citations in the headers. See
|
|
365
|
+
These aren't metaphors. They're TypeScript modules with paper citations in the headers. The interference between modules — not the modules themselves — is where intelligent behavior emerges. See the [research paper](../../docs/cognitive-module-interference.md).
|
|
366
|
+
|
|
367
|
+
## Standalone Packages
|
|
368
|
+
|
|
369
|
+
Use kbot's brain without the full agent:
|
|
370
|
+
|
|
371
|
+
| Package | What it does |
|
|
372
|
+
|---------|-------------|
|
|
373
|
+
| [`@kernel.chat/skill-router`](https://www.npmjs.com/package/@kernel.chat/skill-router) | Bayesian agent routing — TrueSkill-style, zero LLM calls |
|
|
374
|
+
| [`@kernel.chat/memory-tiers`](https://www.npmjs.com/package/@kernel.chat/memory-tiers) | Three-tier memory: observations → reflections → identity |
|
|
375
|
+
| [`@kernel.chat/tool-forge`](https://www.npmjs.com/package/@kernel.chat/tool-forge) | Runtime tool creation from structured definitions |
|
|
376
|
+
| [`@kernel.chat/prompt-evolver`](https://www.npmjs.com/package/@kernel.chat/prompt-evolver) | GEPA-style prompt self-optimization from execution traces |
|
|
377
|
+
| [`@kernel.chat/kbot-openclaw`](https://www.npmjs.com/package/@kernel.chat/kbot-openclaw) | OpenClaw plugin — kbot as brain for 50+ messaging channels |
|
|
361
378
|
|
|
362
379
|
## Security
|
|
363
380
|
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { type EvalResult } from './self-eval.js';
|
|
2
|
+
export interface ConsultationClient {
|
|
3
|
+
id: string;
|
|
4
|
+
email: string;
|
|
5
|
+
name?: string;
|
|
6
|
+
industry?: string;
|
|
7
|
+
goals?: string;
|
|
8
|
+
challenges?: string;
|
|
9
|
+
context: Record<string, unknown>;
|
|
10
|
+
intake_complete: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface ConsultationThread {
|
|
13
|
+
id: string;
|
|
14
|
+
client_id: string;
|
|
15
|
+
subject: string;
|
|
16
|
+
status: 'intake' | 'valuation' | 'awaiting_payment' | 'active' | 'completed' | 'capped';
|
|
17
|
+
reply_count: number;
|
|
18
|
+
max_replies: number;
|
|
19
|
+
agent?: string;
|
|
20
|
+
quality_scores: EvalResult[];
|
|
21
|
+
idea_summary?: string;
|
|
22
|
+
market_value_low?: number;
|
|
23
|
+
market_value_high?: number;
|
|
24
|
+
consultation_fee?: number;
|
|
25
|
+
paid?: boolean;
|
|
26
|
+
summary?: string;
|
|
27
|
+
action_items: Array<{
|
|
28
|
+
task: string;
|
|
29
|
+
owner: string;
|
|
30
|
+
}>;
|
|
31
|
+
completed_at?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface ConsultationMessage {
|
|
34
|
+
role: 'client' | 'kbot';
|
|
35
|
+
content: string;
|
|
36
|
+
agent?: string;
|
|
37
|
+
eval_score?: EvalResult;
|
|
38
|
+
}
|
|
39
|
+
export interface ConsultationResult {
|
|
40
|
+
reply: string;
|
|
41
|
+
eval: EvalResult;
|
|
42
|
+
agent: string;
|
|
43
|
+
guardrailBlocked: boolean;
|
|
44
|
+
guardrailMessage?: string;
|
|
45
|
+
threadStatus: 'intake' | 'valuation' | 'awaiting_payment' | 'active' | 'completed' | 'capped';
|
|
46
|
+
summary?: string;
|
|
47
|
+
actionItems?: Array<{
|
|
48
|
+
task: string;
|
|
49
|
+
owner: string;
|
|
50
|
+
}>;
|
|
51
|
+
}
|
|
52
|
+
interface DomainGuardrailResult {
|
|
53
|
+
blocked: boolean;
|
|
54
|
+
domain?: string;
|
|
55
|
+
message?: string;
|
|
56
|
+
suggestedTopic?: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Check if a message touches restricted domains.
|
|
60
|
+
* Uses keyword/regex detection — fast and free ($0).
|
|
61
|
+
*/
|
|
62
|
+
export declare function checkDomainGuardrails(message: string): DomainGuardrailResult;
|
|
63
|
+
/**
|
|
64
|
+
* Parse intake answers from a client's reply.
|
|
65
|
+
* Looks for numbered responses or paragraph breaks.
|
|
66
|
+
*/
|
|
67
|
+
export declare function parseIntakeAnswers(message: string): Partial<ConsultationClient>;
|
|
68
|
+
/**
|
|
69
|
+
* Generate the intake email for a new client.
|
|
70
|
+
*/
|
|
71
|
+
export declare function getIntakeMessage(): string;
|
|
72
|
+
/**
|
|
73
|
+
* Run the critic gate on a consultation response.
|
|
74
|
+
* Returns the response if it passes, or a clarifying question if it doesn't.
|
|
75
|
+
*/
|
|
76
|
+
export declare function criticGate(clientMessage: string, proposedResponse: string, threadHistory: string): Promise<{
|
|
77
|
+
passed: boolean;
|
|
78
|
+
response: string;
|
|
79
|
+
eval: EvalResult;
|
|
80
|
+
}>;
|
|
81
|
+
/**
|
|
82
|
+
* Detect if a client message signals thread closure.
|
|
83
|
+
*/
|
|
84
|
+
export declare function detectThreadClosure(message: string): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Generate a consultation summary with action items.
|
|
87
|
+
* Uses the analyst agent for structured output.
|
|
88
|
+
*/
|
|
89
|
+
export declare function generateThreadSummary(messages: ConsultationMessage[], client: ConsultationClient): Promise<{
|
|
90
|
+
summary: string;
|
|
91
|
+
actionItems: Array<{
|
|
92
|
+
task: string;
|
|
93
|
+
owner: string;
|
|
94
|
+
}>;
|
|
95
|
+
}>;
|
|
96
|
+
/**
|
|
97
|
+
* Process an inbound consultation email through the full pipeline.
|
|
98
|
+
*
|
|
99
|
+
* @param clientEmail - The sender's email address
|
|
100
|
+
* @param clientName - The sender's name (if available)
|
|
101
|
+
* @param subject - Email subject line
|
|
102
|
+
* @param messageBody - Email body text
|
|
103
|
+
* @param db - Database adapter (Supabase client or compatible)
|
|
104
|
+
*/
|
|
105
|
+
export declare function processConsultationEmail(clientEmail: string, clientName: string | null, subject: string, messageBody: string, db: ConsultationDB): Promise<ConsultationResult>;
|
|
106
|
+
export interface ConsultationDB {
|
|
107
|
+
getClientByEmail(email: string): Promise<ConsultationClient | null>;
|
|
108
|
+
createClient(email: string, name: string | null): Promise<ConsultationClient>;
|
|
109
|
+
updateClient(id: string, data: Partial<ConsultationClient>): Promise<void>;
|
|
110
|
+
getActiveThread(clientId: string): Promise<ConsultationThread | null>;
|
|
111
|
+
createThread(clientId: string, subject: string, status: string): Promise<ConsultationThread>;
|
|
112
|
+
updateThread(id: string, data: Partial<ConsultationThread>): Promise<void>;
|
|
113
|
+
addMessage(threadId: string, role: 'client' | 'kbot', content: string, evalScore?: EvalResult, agent?: string): Promise<void>;
|
|
114
|
+
getThreadMessages(threadId: string): Promise<ConsultationMessage[]>;
|
|
115
|
+
}
|
|
116
|
+
export {};
|
|
117
|
+
//# sourceMappingURL=consultation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consultation.d.ts","sourceRoot":"","sources":["../src/consultation.ts"],"names":[],"mappings":"AAWA,OAAO,EAAoB,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAKlE,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAChC,eAAe,EAAE,OAAO,CAAA;CACzB;AAED,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAA;IACV,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,M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gB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAAA;IACnE,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAA;IAC7E,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,kBAAkB,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC1E,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAAA;IACrE,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAA;IAC5F,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,kBAAkB,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC1E,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC7H,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAAA;CACpE"}
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
// kbot Consultation Engine — autonomous email consultation pipeline
|
|
2
|
+
//
|
|
3
|
+
// Flow: inbound email → guardrail check → client lookup → agent routing
|
|
4
|
+
// → generate response → critic gate → send reply
|
|
5
|
+
//
|
|
6
|
+
// Features:
|
|
7
|
+
// 1. Client profile system (intake on first contact)
|
|
8
|
+
// 2. Critic gate (self-eval before sending)
|
|
9
|
+
// 3. Domain guardrails (refuse legal/medical/financial/tax)
|
|
10
|
+
// 4. Thread summary + action items on close
|
|
11
|
+
import { evaluateResponse } from './self-eval.js';
|
|
12
|
+
import { runAgent } from './agent.js';
|
|
13
|
+
const RESTRICTED_DOMAINS = [
|
|
14
|
+
{
|
|
15
|
+
domain: 'legal',
|
|
16
|
+
patterns: [
|
|
17
|
+
/\b(legal advice|lawyer|attorney|lawsuit|sue|litigation|court|plaintiff|defendant|statute|liability|tort|contract law|intellectual property law|patent law|trademark law|copyright law|legal obligation|legal rights|legal counsel)\b/i,
|
|
18
|
+
/\b(should i sue|can i be sued|is this legal|legally binding|terms of service review|NDA review|employment law|labor law)\b/i,
|
|
19
|
+
],
|
|
20
|
+
professional: 'lawyer or legal counsel',
|
|
21
|
+
suggestion: 'business strategy, contract negotiation approach, or risk assessment from a business perspective',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
domain: 'medical',
|
|
25
|
+
patterns: [
|
|
26
|
+
/\b(medical advice|diagnosis|treatment|prescription|medication|symptoms|disease|illness|health condition|clinical|therapy|dosage|side effects|medical condition)\b/i,
|
|
27
|
+
/\b(should i take|what medication|am i sick|health risk|medical opinion)\b/i,
|
|
28
|
+
],
|
|
29
|
+
professional: 'qualified healthcare provider',
|
|
30
|
+
suggestion: 'health tech strategy, wellness program design, or healthcare business operations',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
domain: 'financial',
|
|
34
|
+
patterns: [
|
|
35
|
+
/\b(investment advice|stock picks|buy or sell|portfolio allocation|financial planning|retirement planning|tax-loss harvesting|securities|hedge fund|mutual fund|cryptocurrency investment|forex trading)\b/i,
|
|
36
|
+
/\b(should i invest|which stocks|financial advisor|fiduciary|wealth management|estate planning)\b/i,
|
|
37
|
+
],
|
|
38
|
+
professional: 'licensed financial advisor',
|
|
39
|
+
suggestion: 'business financial strategy, revenue modeling, pricing strategy, or fundraising approach',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
domain: 'tax',
|
|
43
|
+
patterns: [
|
|
44
|
+
/\b(tax advice|tax filing|tax deduction|tax return|tax liability|tax shelter|tax evasion|tax avoidance|IRS|tax audit|tax code|capital gains tax|estate tax|income tax filing)\b/i,
|
|
45
|
+
/\b(how to file taxes|tax write-off|can i deduct|tax bracket|tax-exempt)\b/i,
|
|
46
|
+
],
|
|
47
|
+
professional: 'certified accountant or tax professional',
|
|
48
|
+
suggestion: 'business expense planning, financial modeling, or revenue optimization',
|
|
49
|
+
},
|
|
50
|
+
];
|
|
51
|
+
/**
|
|
52
|
+
* Check if a message touches restricted domains.
|
|
53
|
+
* Uses keyword/regex detection — fast and free ($0).
|
|
54
|
+
*/
|
|
55
|
+
export function checkDomainGuardrails(message) {
|
|
56
|
+
for (const domain of RESTRICTED_DOMAINS) {
|
|
57
|
+
for (const pattern of domain.patterns) {
|
|
58
|
+
if (pattern.test(message)) {
|
|
59
|
+
return {
|
|
60
|
+
blocked: true,
|
|
61
|
+
domain: domain.domain,
|
|
62
|
+
message: `This touches on ${domain.domain} territory. I'd recommend consulting a ${domain.professional} for this specific question. I can definitely help with ${domain.suggestion} instead — would you like to explore that?`,
|
|
63
|
+
suggestedTopic: domain.suggestion,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return { blocked: false };
|
|
69
|
+
}
|
|
70
|
+
// ── Intake System ──
|
|
71
|
+
const INTAKE_QUESTIONS = `Thank you for reaching out to Kernel Consultation.
|
|
72
|
+
|
|
73
|
+
Before I can give you the best possible advice, I'd love to learn a bit about your business. Could you answer these quick questions?
|
|
74
|
+
|
|
75
|
+
1. **What industry are you in?** (e.g., SaaS, e-commerce, healthcare, fintech, agency)
|
|
76
|
+
2. **What does your business do?** (one sentence is fine)
|
|
77
|
+
3. **What's your biggest challenge right now?**
|
|
78
|
+
4. **What are you hoping to achieve in the next 3-6 months?**
|
|
79
|
+
5. **Is there anything specific you'd like help with today?**
|
|
80
|
+
|
|
81
|
+
Just reply to this email with your answers and we'll get started right away.`;
|
|
82
|
+
/**
|
|
83
|
+
* Parse intake answers from a client's reply.
|
|
84
|
+
* Looks for numbered responses or paragraph breaks.
|
|
85
|
+
*/
|
|
86
|
+
export function parseIntakeAnswers(message) {
|
|
87
|
+
const lines = message.split('\n').filter(l => l.trim());
|
|
88
|
+
const answers = { context: {} };
|
|
89
|
+
// Try numbered format first (1. answer, 2. answer, etc.)
|
|
90
|
+
const numbered = lines.filter(l => /^\s*\d+[\.\)]\s*/.test(l));
|
|
91
|
+
if (numbered.length >= 3) {
|
|
92
|
+
const clean = numbered.map(l => l.replace(/^\s*\d+[\.\)]\s*/, '').trim());
|
|
93
|
+
answers.industry = clean[0] || undefined;
|
|
94
|
+
answers.goals = clean[1] || undefined;
|
|
95
|
+
answers.challenges = clean[2] || undefined;
|
|
96
|
+
if (clean[3])
|
|
97
|
+
answers.context.timeline = clean[3];
|
|
98
|
+
if (clean[4])
|
|
99
|
+
answers.context.specific_request = clean[4];
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
// Paragraph format — use the whole message as context
|
|
103
|
+
answers.context = { raw_intake: message };
|
|
104
|
+
// Try to extract industry from keywords
|
|
105
|
+
const industryMatch = message.match(/\b(SaaS|e-commerce|ecommerce|healthcare|fintech|agency|consulting|retail|manufacturing|education|real estate|media|tech|startup)\b/i);
|
|
106
|
+
if (industryMatch)
|
|
107
|
+
answers.industry = industryMatch[1];
|
|
108
|
+
}
|
|
109
|
+
return answers;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Generate the intake email for a new client.
|
|
113
|
+
*/
|
|
114
|
+
export function getIntakeMessage() {
|
|
115
|
+
return INTAKE_QUESTIONS;
|
|
116
|
+
}
|
|
117
|
+
// ── Critic Gate ──
|
|
118
|
+
/** Consultation-specific thresholds (stricter than default) */
|
|
119
|
+
const CONSULTATION_THRESHOLDS = {
|
|
120
|
+
faithfulness: 0.6,
|
|
121
|
+
relevancy: 0.7,
|
|
122
|
+
overall: 0.5,
|
|
123
|
+
};
|
|
124
|
+
const CLARIFYING_QUESTION_PROMPT = `The client asked a question but I'm not confident enough in my answer to send it. Instead of guessing, generate a thoughtful clarifying question that will help me give a better answer. Be specific about what additional information would help.`;
|
|
125
|
+
/**
|
|
126
|
+
* Run the critic gate on a consultation response.
|
|
127
|
+
* Returns the response if it passes, or a clarifying question if it doesn't.
|
|
128
|
+
*/
|
|
129
|
+
export async function criticGate(clientMessage, proposedResponse, threadHistory) {
|
|
130
|
+
const evalResult = await evaluateResponse(clientMessage, proposedResponse, threadHistory);
|
|
131
|
+
const passes = evalResult.faithfulness >= CONSULTATION_THRESHOLDS.faithfulness &&
|
|
132
|
+
evalResult.relevancy >= CONSULTATION_THRESHOLDS.relevancy &&
|
|
133
|
+
evalResult.overall >= CONSULTATION_THRESHOLDS.overall;
|
|
134
|
+
if (passes) {
|
|
135
|
+
return { passed: true, response: proposedResponse, eval: evalResult };
|
|
136
|
+
}
|
|
137
|
+
// Generate a clarifying question instead
|
|
138
|
+
try {
|
|
139
|
+
const clarifyResult = await runAgent(`${CLARIFYING_QUESTION_PROMPT}\n\nClient's message: "${clientMessage}"\n\nThread context: ${threadHistory.slice(0, 500)}`, { agent: 'communicator', skipPlanner: true });
|
|
140
|
+
return {
|
|
141
|
+
passed: false,
|
|
142
|
+
response: clarifyResult.content,
|
|
143
|
+
eval: evalResult,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
// Fallback clarifying question
|
|
148
|
+
return {
|
|
149
|
+
passed: false,
|
|
150
|
+
response: `Thank you for your question. To make sure I give you the most relevant advice, could you provide a bit more context? Specifically, what outcome are you hoping to achieve, and what have you already tried?`,
|
|
151
|
+
eval: evalResult,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
// ── Thread Closure Detection ──
|
|
156
|
+
const CLOSURE_PATTERNS = [
|
|
157
|
+
/\b(thanks?|thank you|thx|cheers|appreciate it|that's all|that's everything|perfect|great|awesome|wonderful)\b/i,
|
|
158
|
+
/\b(goodbye|bye|talk later|have a good|take care|signing off|all set|no more questions)\b/i,
|
|
159
|
+
];
|
|
160
|
+
/**
|
|
161
|
+
* Detect if a client message signals thread closure.
|
|
162
|
+
*/
|
|
163
|
+
export function detectThreadClosure(message) {
|
|
164
|
+
// Short messages with closure words are strong signals
|
|
165
|
+
if (message.length < 100) {
|
|
166
|
+
return CLOSURE_PATTERNS.some(p => p.test(message));
|
|
167
|
+
}
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
// ── Thread Summary Generation ──
|
|
171
|
+
/**
|
|
172
|
+
* Generate a consultation summary with action items.
|
|
173
|
+
* Uses the analyst agent for structured output.
|
|
174
|
+
*/
|
|
175
|
+
export async function generateThreadSummary(messages, client) {
|
|
176
|
+
const transcript = messages
|
|
177
|
+
.map(m => `${m.role === 'client' ? 'Client' : 'Consultant'}: ${m.content}`)
|
|
178
|
+
.join('\n\n');
|
|
179
|
+
const prompt = `Analyze this consultation thread and produce a structured summary.
|
|
180
|
+
|
|
181
|
+
Client: ${client.name || client.email}
|
|
182
|
+
Industry: ${client.industry || 'Not specified'}
|
|
183
|
+
Goals: ${client.goals || 'Not specified'}
|
|
184
|
+
|
|
185
|
+
--- Transcript ---
|
|
186
|
+
${transcript.slice(0, 4000)}
|
|
187
|
+
--- End Transcript ---
|
|
188
|
+
|
|
189
|
+
Produce your response in this EXACT format:
|
|
190
|
+
|
|
191
|
+
## Key Points Discussed
|
|
192
|
+
- [point 1]
|
|
193
|
+
- [point 2]
|
|
194
|
+
- [point 3]
|
|
195
|
+
|
|
196
|
+
## Recommendations
|
|
197
|
+
- [recommendation 1]
|
|
198
|
+
- [recommendation 2]
|
|
199
|
+
|
|
200
|
+
## Action Items
|
|
201
|
+
- [ ] [task description] — Owner: [Client/Consultant]
|
|
202
|
+
- [ ] [task description] — Owner: [Client/Consultant]
|
|
203
|
+
|
|
204
|
+
## Next Steps
|
|
205
|
+
[1-2 sentences on suggested follow-up]`;
|
|
206
|
+
try {
|
|
207
|
+
const result = await runAgent(prompt, { agent: 'analyst', skipPlanner: true });
|
|
208
|
+
const content = result.content;
|
|
209
|
+
// Extract action items from the structured output
|
|
210
|
+
const actionItems = [];
|
|
211
|
+
const actionRegex = /- \[ ?\] (.+?) — Owner: (.+)/g;
|
|
212
|
+
let match;
|
|
213
|
+
while ((match = actionRegex.exec(content)) !== null) {
|
|
214
|
+
actionItems.push({ task: match[1].trim(), owner: match[2].trim() });
|
|
215
|
+
}
|
|
216
|
+
return { summary: content, actionItems };
|
|
217
|
+
}
|
|
218
|
+
catch {
|
|
219
|
+
return {
|
|
220
|
+
summary: `Consultation with ${client.name || client.email} — ${messages.length} messages exchanged.`,
|
|
221
|
+
actionItems: [],
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
// ── Main Pipeline ──
|
|
226
|
+
/**
|
|
227
|
+
* Process an inbound consultation email through the full pipeline.
|
|
228
|
+
*
|
|
229
|
+
* @param clientEmail - The sender's email address
|
|
230
|
+
* @param clientName - The sender's name (if available)
|
|
231
|
+
* @param subject - Email subject line
|
|
232
|
+
* @param messageBody - Email body text
|
|
233
|
+
* @param db - Database adapter (Supabase client or compatible)
|
|
234
|
+
*/
|
|
235
|
+
export async function processConsultationEmail(clientEmail, clientName, subject, messageBody, db) {
|
|
236
|
+
// 1. Domain guardrail check (before any processing)
|
|
237
|
+
const guardrail = checkDomainGuardrails(messageBody);
|
|
238
|
+
if (guardrail.blocked) {
|
|
239
|
+
return {
|
|
240
|
+
reply: guardrail.message,
|
|
241
|
+
eval: { faithfulness: 1, relevancy: 1, overall: 1, shouldRetry: false },
|
|
242
|
+
agent: 'guardrail',
|
|
243
|
+
guardrailBlocked: true,
|
|
244
|
+
guardrailMessage: guardrail.message,
|
|
245
|
+
threadStatus: 'active',
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
// 2. Client lookup / creation
|
|
249
|
+
let client = await db.getClientByEmail(clientEmail);
|
|
250
|
+
if (!client) {
|
|
251
|
+
client = await db.createClient(clientEmail, clientName);
|
|
252
|
+
}
|
|
253
|
+
// 3. If intake not complete, handle intake flow
|
|
254
|
+
if (!client.intake_complete) {
|
|
255
|
+
// Check if this is the first message (send intake questions)
|
|
256
|
+
// or the reply to intake (parse answers)
|
|
257
|
+
const existingThread = await db.getActiveThread(client.id);
|
|
258
|
+
if (!existingThread || existingThread.status === 'intake') {
|
|
259
|
+
if (!existingThread) {
|
|
260
|
+
// First contact — create intake thread and send questions
|
|
261
|
+
const thread = await db.createThread(client.id, subject, 'intake');
|
|
262
|
+
await db.addMessage(thread.id, 'client', messageBody);
|
|
263
|
+
const intakeMsg = getIntakeMessage();
|
|
264
|
+
await db.addMessage(thread.id, 'kbot', intakeMsg);
|
|
265
|
+
return {
|
|
266
|
+
reply: intakeMsg,
|
|
267
|
+
eval: { faithfulness: 1, relevancy: 1, overall: 1, shouldRetry: false },
|
|
268
|
+
agent: 'intake',
|
|
269
|
+
guardrailBlocked: false,
|
|
270
|
+
threadStatus: 'intake',
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
// Reply to intake — parse answers and activate
|
|
275
|
+
await db.addMessage(existingThread.id, 'client', messageBody);
|
|
276
|
+
const answers = parseIntakeAnswers(messageBody);
|
|
277
|
+
await db.updateClient(client.id, { ...answers, intake_complete: true });
|
|
278
|
+
await db.updateThread(existingThread.id, { status: 'active' });
|
|
279
|
+
// Now process their original question + context
|
|
280
|
+
client = { ...client, ...answers, intake_complete: true };
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
// 4. Get or create active thread
|
|
285
|
+
let thread = await db.getActiveThread(client.id);
|
|
286
|
+
if (!thread) {
|
|
287
|
+
thread = await db.createThread(client.id, subject, 'active');
|
|
288
|
+
}
|
|
289
|
+
// 5. Check reply cap
|
|
290
|
+
if (thread.reply_count >= thread.max_replies) {
|
|
291
|
+
// Generate summary and close
|
|
292
|
+
const messages = await db.getThreadMessages(thread.id);
|
|
293
|
+
const { summary, actionItems } = await generateThreadSummary(messages, client);
|
|
294
|
+
await db.updateThread(thread.id, {
|
|
295
|
+
status: 'capped',
|
|
296
|
+
summary,
|
|
297
|
+
action_items: actionItems,
|
|
298
|
+
completed_at: new Date().toISOString(),
|
|
299
|
+
});
|
|
300
|
+
const capMessage = `We've reached the end of this consultation thread (${thread.max_replies} exchanges). Here's a summary of what we covered:\n\n${summary}\n\nTo continue our work together, simply send a new email to start a fresh thread. Thank you for choosing Kernel Consultation.`;
|
|
301
|
+
return {
|
|
302
|
+
reply: capMessage,
|
|
303
|
+
eval: { faithfulness: 1, relevancy: 1, overall: 1, shouldRetry: false },
|
|
304
|
+
agent: 'summary',
|
|
305
|
+
guardrailBlocked: false,
|
|
306
|
+
threadStatus: 'capped',
|
|
307
|
+
summary,
|
|
308
|
+
actionItems,
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
// 6. Record client message
|
|
312
|
+
await db.addMessage(thread.id, 'client', messageBody);
|
|
313
|
+
// 7. Build context for the agent
|
|
314
|
+
const threadMessages = await db.getThreadMessages(thread.id);
|
|
315
|
+
const threadHistory = threadMessages
|
|
316
|
+
.slice(-10) // last 10 messages for context
|
|
317
|
+
.map(m => `${m.role === 'client' ? 'Client' : 'Consultant'}: ${m.content}`)
|
|
318
|
+
.join('\n\n');
|
|
319
|
+
const clientContext = [
|
|
320
|
+
client.industry ? `Industry: ${client.industry}` : '',
|
|
321
|
+
client.goals ? `Goals: ${client.goals}` : '',
|
|
322
|
+
client.challenges ? `Challenges: ${client.challenges}` : '',
|
|
323
|
+
].filter(Boolean).join('\n');
|
|
324
|
+
const systemContext = `You are a professional business consultant responding via email. Be concise, actionable, and specific to the client's business.
|
|
325
|
+
|
|
326
|
+
Client Profile:
|
|
327
|
+
${clientContext || 'No profile data yet.'}
|
|
328
|
+
|
|
329
|
+
Thread History:
|
|
330
|
+
${threadHistory}
|
|
331
|
+
|
|
332
|
+
Respond to the client's latest message. Be professional but warm. Give specific, actionable advice. Do NOT give legal, medical, financial investment, or tax advice.`;
|
|
333
|
+
// 8. Route to specialist agent and generate response
|
|
334
|
+
let agentResponse;
|
|
335
|
+
try {
|
|
336
|
+
agentResponse = await runAgent(`${systemContext}\n\nClient's message: ${messageBody}`, { skipPlanner: true });
|
|
337
|
+
}
|
|
338
|
+
catch (err) {
|
|
339
|
+
return {
|
|
340
|
+
reply: `Thank you for your message. I'm experiencing a temporary issue processing your request. I'll get back to you shortly. If this is urgent, please send a follow-up email.`,
|
|
341
|
+
eval: { faithfulness: 0, relevancy: 0, overall: 0, shouldRetry: false },
|
|
342
|
+
agent: 'error',
|
|
343
|
+
guardrailBlocked: false,
|
|
344
|
+
threadStatus: 'active',
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
// 9. Critic gate — evaluate quality before sending
|
|
348
|
+
const criticResult = await criticGate(messageBody, agentResponse.content, threadHistory);
|
|
349
|
+
// 10. Check for thread closure
|
|
350
|
+
const isClosing = detectThreadClosure(messageBody);
|
|
351
|
+
let finalReply = criticResult.response;
|
|
352
|
+
let threadStatus = 'active';
|
|
353
|
+
let summary;
|
|
354
|
+
let actionItems;
|
|
355
|
+
if (isClosing) {
|
|
356
|
+
// Generate summary
|
|
357
|
+
const messages = await db.getThreadMessages(thread.id);
|
|
358
|
+
const summaryResult = await generateThreadSummary(messages, client);
|
|
359
|
+
summary = summaryResult.summary;
|
|
360
|
+
actionItems = summaryResult.actionItems;
|
|
361
|
+
threadStatus = 'completed';
|
|
362
|
+
finalReply += `\n\n---\n\n**Consultation Summary**\n\n${summary}\n\nThank you for choosing Kernel Consultation. Feel free to reach out anytime you need help.`;
|
|
363
|
+
await db.updateThread(thread.id, {
|
|
364
|
+
status: 'completed',
|
|
365
|
+
summary,
|
|
366
|
+
action_items: actionItems,
|
|
367
|
+
completed_at: new Date().toISOString(),
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
// 11. Record kbot's response
|
|
371
|
+
await db.addMessage(thread.id, 'kbot', finalReply, criticResult.eval, agentResponse.agent);
|
|
372
|
+
// 12. Update thread
|
|
373
|
+
await db.updateThread(thread.id, {
|
|
374
|
+
reply_count: thread.reply_count + 1,
|
|
375
|
+
agent: agentResponse.agent,
|
|
376
|
+
quality_scores: [...(thread.quality_scores || []), criticResult.eval],
|
|
377
|
+
});
|
|
378
|
+
return {
|
|
379
|
+
reply: finalReply,
|
|
380
|
+
eval: criticResult.eval,
|
|
381
|
+
agent: agentResponse.agent,
|
|
382
|
+
guardrailBlocked: false,
|
|
383
|
+
threadStatus,
|
|
384
|
+
summary,
|
|
385
|
+
actionItems,
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
//# sourceMappingURL=consultation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consultation.js","sourceRoot":"","sources":["../src/consultation.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,EAAE;AACF,wEAAwE;AACxE,uDAAuD;AACvD,EAAE;AACF,YAAY;AACZ,uDAAuD;AACvD,8CAA8C;AAC9C,8DAA8D;AAC9D,8CAA8C;AAE9C,OAAO,EAAE,gBAAgB,EAAmB,MAAM,gBAAgB,CAAA;AAClE,OAAO,EAAE,QAAQ,EAAsB,MAAM,YAAY,CAAA;AA6DzD,MAAM,kBAAkB,GAKnB;IACH;QACE,MAAM,EAAE,OAAO;QACf,QAAQ,EAAE;YACR,uOAAuO;YACvO,6HAA6H;SAC9H;QACD,YAAY,EAAE,yBAAyB;QACvC,UAAU,EAAE,kGAAkG;KAC/G;IACD;QACE,MAAM,EAAE,SAAS;QACjB,QAAQ,EAAE;YACR,oKAAoK;YACpK,4EAA4E;SAC7E;QACD,YAAY,EAAE,+BAA+B;QAC7C,UAAU,EAAE,kFAAkF;KAC/F;IACD;QACE,MAAM,EAAE,WAAW;QACnB,QAAQ,EAAE;YACR,4MAA4M;YAC5M,mGAAmG;SACpG;QACD,YAAY,EAAE,4BAA4B;QAC1C,UA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