@carlonicora/nestjs-neo4jsonapi 1.4.1 → 1.5.0
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/dist/agents/agents.modules.d.ts.map +1 -1
- package/dist/agents/agents.modules.js +21 -2
- package/dist/agents/agents.modules.js.map +1 -1
- package/dist/agents/community.detector/community.detector.module.d.ts +3 -0
- package/dist/agents/community.detector/community.detector.module.d.ts.map +1 -0
- package/dist/agents/community.detector/community.detector.module.js +25 -0
- package/dist/agents/community.detector/community.detector.module.js.map +1 -0
- package/dist/agents/community.detector/services/community.detector.service.d.ts +63 -0
- package/dist/agents/community.detector/services/community.detector.service.d.ts.map +1 -0
- package/dist/agents/community.detector/services/community.detector.service.js +343 -0
- package/dist/agents/community.detector/services/community.detector.service.js.map +1 -0
- package/dist/agents/community.summariser/community.summariser.module.d.ts +3 -0
- package/dist/agents/community.summariser/community.summariser.module.d.ts.map +1 -0
- package/dist/agents/community.summariser/community.summariser.module.js +33 -0
- package/dist/agents/community.summariser/community.summariser.module.js.map +1 -0
- package/dist/agents/community.summariser/processors/community.summariser.processor.d.ts +21 -0
- package/dist/agents/community.summariser/processors/community.summariser.processor.d.ts.map +1 -0
- package/dist/agents/community.summariser/processors/community.summariser.processor.js +70 -0
- package/dist/agents/community.summariser/processors/community.summariser.processor.js.map +1 -0
- package/dist/agents/community.summariser/services/community.summariser.service.d.ts +26 -0
- package/dist/agents/community.summariser/services/community.summariser.service.d.ts.map +1 -0
- package/dist/agents/community.summariser/services/community.summariser.service.js +155 -0
- package/dist/agents/community.summariser/services/community.summariser.service.js.map +1 -0
- package/dist/agents/drift/contexts/drift.context.d.ts +56 -0
- package/dist/agents/drift/contexts/drift.context.d.ts.map +1 -0
- package/dist/agents/drift/contexts/drift.context.js +91 -0
- package/dist/agents/drift/contexts/drift.context.js.map +1 -0
- package/dist/agents/drift/drift.module.d.ts +3 -0
- package/dist/agents/drift/drift.module.d.ts.map +1 -0
- package/dist/agents/drift/drift.module.js +44 -0
- package/dist/agents/drift/drift.module.js.map +1 -0
- package/dist/agents/drift/nodes/community.search.node.service.d.ts +12 -0
- package/dist/agents/drift/nodes/community.search.node.service.d.ts.map +1 -0
- package/dist/agents/drift/nodes/community.search.node.service.js +57 -0
- package/dist/agents/drift/nodes/community.search.node.service.js.map +1 -0
- package/dist/agents/drift/nodes/followup.node.service.d.ts +28 -0
- package/dist/agents/drift/nodes/followup.node.service.d.ts.map +1 -0
- package/dist/agents/drift/nodes/followup.node.service.js +174 -0
- package/dist/agents/drift/nodes/followup.node.service.js.map +1 -0
- package/dist/agents/drift/nodes/hyde.node.service.d.ts +21 -0
- package/dist/agents/drift/nodes/hyde.node.service.d.ts.map +1 -0
- package/dist/agents/drift/nodes/hyde.node.service.js +114 -0
- package/dist/agents/drift/nodes/hyde.node.service.js.map +1 -0
- package/dist/agents/drift/nodes/primer.answer.node.service.d.ts +17 -0
- package/dist/agents/drift/nodes/primer.answer.node.service.d.ts.map +1 -0
- package/dist/agents/drift/nodes/primer.answer.node.service.js +110 -0
- package/dist/agents/drift/nodes/primer.answer.node.service.js.map +1 -0
- package/dist/agents/drift/nodes/synthesis.node.service.d.ts +17 -0
- package/dist/agents/drift/nodes/synthesis.node.service.d.ts.map +1 -0
- package/dist/agents/drift/nodes/synthesis.node.service.js +105 -0
- package/dist/agents/drift/nodes/synthesis.node.service.js.map +1 -0
- package/dist/agents/drift/services/drift.migration.service.d.ts +47 -0
- package/dist/agents/drift/services/drift.migration.service.d.ts.map +1 -0
- package/dist/agents/drift/services/drift.migration.service.js +114 -0
- package/dist/agents/drift/services/drift.migration.service.js.map +1 -0
- package/dist/agents/drift/services/drift.search.service.d.ts +52 -0
- package/dist/agents/drift/services/drift.search.service.d.ts.map +1 -0
- package/dist/agents/drift/services/drift.search.service.js +185 -0
- package/dist/agents/drift/services/drift.search.service.js.map +1 -0
- package/dist/agents/graph.creator/interfaces/chunk.analysis.interface.d.ts +4 -0
- package/dist/agents/graph.creator/interfaces/chunk.analysis.interface.d.ts.map +1 -1
- package/dist/agents/graph.creator/services/graph.creator.service.d.ts +1 -1
- package/dist/agents/graph.creator/services/graph.creator.service.d.ts.map +1 -1
- package/dist/agents/graph.creator/services/graph.creator.service.js +43 -0
- package/dist/agents/graph.creator/services/graph.creator.service.js.map +1 -1
- package/dist/agents/index.d.ts +8 -0
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +18 -1
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/responder/contexts/responder.context.d.ts +3 -0
- package/dist/agents/responder/contexts/responder.context.d.ts.map +1 -1
- package/dist/agents/responder/contexts/responder.context.js +8 -0
- package/dist/agents/responder/contexts/responder.context.js.map +1 -1
- package/dist/agents/responder/factories/responder.context.factory.d.ts +1 -0
- package/dist/agents/responder/factories/responder.context.factory.d.ts.map +1 -1
- package/dist/agents/responder/factories/responder.context.factory.js +2 -0
- package/dist/agents/responder/factories/responder.context.factory.js.map +1 -1
- package/dist/agents/responder/nodes/responder.answer.node.service.d.ts +22 -0
- package/dist/agents/responder/nodes/responder.answer.node.service.d.ts.map +1 -1
- package/dist/agents/responder/nodes/responder.answer.node.service.js +155 -0
- package/dist/agents/responder/nodes/responder.answer.node.service.js.map +1 -1
- package/dist/agents/responder/responder.module.d.ts.map +1 -1
- package/dist/agents/responder/responder.module.js +2 -1
- package/dist/agents/responder/responder.module.js.map +1 -1
- package/dist/agents/responder/services/responder.service.d.ts +17 -1
- package/dist/agents/responder/services/responder.service.d.ts.map +1 -1
- package/dist/agents/responder/services/responder.service.js +49 -5
- package/dist/agents/responder/services/responder.service.js.map +1 -1
- package/dist/common/interfaces/agents/graph.creator.interface.d.ts +4 -0
- package/dist/common/interfaces/agents/graph.creator.interface.d.ts.map +1 -1
- package/dist/config/enums/queue.id.d.ts +2 -1
- package/dist/config/enums/queue.id.d.ts.map +1 -1
- package/dist/config/enums/queue.id.js +1 -0
- package/dist/config/enums/queue.id.js.map +1 -1
- package/dist/config/interfaces/config.prompts.interface.d.ts +5 -0
- package/dist/config/interfaces/config.prompts.interface.d.ts.map +1 -1
- package/dist/foundations/chunk/services/chunk.service.d.ts.map +1 -1
- package/dist/foundations/chunk/services/chunk.service.js +8 -0
- package/dist/foundations/chunk/services/chunk.service.js.map +1 -1
- package/dist/foundations/community/community.module.d.ts +5 -0
- package/dist/foundations/community/community.module.d.ts.map +1 -0
- package/dist/foundations/community/community.module.js +29 -0
- package/dist/foundations/community/community.module.js.map +1 -0
- package/dist/foundations/community/entities/community.entity.d.ts +18 -0
- package/dist/foundations/community/entities/community.entity.d.ts.map +1 -0
- package/dist/foundations/community/entities/community.entity.js +3 -0
- package/dist/foundations/community/entities/community.entity.js.map +1 -0
- package/dist/foundations/community/entities/community.map.d.ts +8 -0
- package/dist/foundations/community/entities/community.map.d.ts.map +1 -0
- package/dist/foundations/community/entities/community.map.js +23 -0
- package/dist/foundations/community/entities/community.map.js.map +1 -0
- package/dist/foundations/community/entities/community.meta.d.ts +3 -0
- package/dist/foundations/community/entities/community.meta.d.ts.map +1 -0
- package/dist/foundations/community/entities/community.meta.js +10 -0
- package/dist/foundations/community/entities/community.meta.js.map +1 -0
- package/dist/foundations/community/entities/community.model.d.ts +4 -0
- package/dist/foundations/community/entities/community.model.d.ts.map +1 -0
- package/dist/foundations/community/entities/community.model.js +15 -0
- package/dist/foundations/community/entities/community.model.js.map +1 -0
- package/dist/foundations/community/repositories/community.repository.d.ts +138 -0
- package/dist/foundations/community/repositories/community.repository.d.ts.map +1 -0
- package/dist/foundations/community/repositories/community.repository.js +446 -0
- package/dist/foundations/community/repositories/community.repository.js.map +1 -0
- package/dist/foundations/community/services/community.service.d.ts +8 -0
- package/dist/foundations/community/services/community.service.d.ts.map +1 -0
- package/dist/foundations/community/services/community.service.js +28 -0
- package/dist/foundations/community/services/community.service.js.map +1 -0
- package/dist/foundations/keyconcept/entities/key.concept.entity.d.ts +1 -0
- package/dist/foundations/keyconcept/entities/key.concept.entity.d.ts.map +1 -1
- package/dist/foundations/keyconcept/entities/key.concept.map.d.ts.map +1 -1
- package/dist/foundations/keyconcept/entities/key.concept.map.js +1 -0
- package/dist/foundations/keyconcept/entities/key.concept.map.js.map +1 -1
- package/dist/foundations/keyconcept/repositories/keyconcept.repository.d.ts +13 -2
- package/dist/foundations/keyconcept/repositories/keyconcept.repository.d.ts.map +1 -1
- package/dist/foundations/keyconcept/repositories/keyconcept.repository.js +22 -2
- package/dist/foundations/keyconcept/repositories/keyconcept.repository.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.FollowUpNodeService = exports.defaultFollowupPrompt = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const config_1 = require("@nestjs/config");
|
|
15
|
+
const zod_1 = require("zod");
|
|
16
|
+
const llm_service_1 = require("../../../core/llm/services/llm.service");
|
|
17
|
+
const logging_service_1 = require("../../../core/logging/services/logging.service");
|
|
18
|
+
const community_repository_1 = require("../../../foundations/community/repositories/community.repository");
|
|
19
|
+
exports.defaultFollowupPrompt = `
|
|
20
|
+
You are a knowledge analyst conducting a detailed investigation.
|
|
21
|
+
|
|
22
|
+
## Your Task
|
|
23
|
+
|
|
24
|
+
Given a follow-up question and community context, provide:
|
|
25
|
+
1. A detailed answer to the specific question
|
|
26
|
+
2. Additional follow-up questions if the investigation should continue
|
|
27
|
+
|
|
28
|
+
## Guidelines
|
|
29
|
+
|
|
30
|
+
- Focus on answering the specific follow-up question
|
|
31
|
+
- Use entity details and relationships from the community members
|
|
32
|
+
- Be specific and cite relevant entities when possible
|
|
33
|
+
- Only suggest more follow-up questions if there are clear gaps to explore
|
|
34
|
+
|
|
35
|
+
## Output
|
|
36
|
+
|
|
37
|
+
Provide:
|
|
38
|
+
- **answer**: Detailed answer to the follow-up question (100-300 words)
|
|
39
|
+
- **additionalQuestions**: 0-2 additional questions if further investigation is needed
|
|
40
|
+
- **shouldContinue**: Whether the investigation should continue (true if important gaps remain)
|
|
41
|
+
`;
|
|
42
|
+
const outputSchema = zod_1.z.object({
|
|
43
|
+
answer: zod_1.z.string().describe("Detailed answer to the follow-up question (100-300 words)"),
|
|
44
|
+
additionalQuestions: zod_1.z.array(zod_1.z.string()).describe("0-2 additional questions if further investigation is needed"),
|
|
45
|
+
shouldContinue: zod_1.z.boolean().describe("Whether the investigation should continue"),
|
|
46
|
+
});
|
|
47
|
+
const inputSchema = zod_1.z.object({
|
|
48
|
+
originalQuestion: zod_1.z.string().describe("The original user question"),
|
|
49
|
+
followUpQuestion: zod_1.z.string().describe("The current follow-up question to answer"),
|
|
50
|
+
priorContext: zod_1.z.string().describe("Context gathered from prior investigation steps"),
|
|
51
|
+
communityDetails: zod_1.z.string().describe("Details about community members and relationships"),
|
|
52
|
+
});
|
|
53
|
+
let FollowUpNodeService = class FollowUpNodeService {
|
|
54
|
+
constructor(llmService, communityRepository, logger, configService) {
|
|
55
|
+
this.llmService = llmService;
|
|
56
|
+
this.communityRepository = communityRepository;
|
|
57
|
+
this.logger = logger;
|
|
58
|
+
this.configService = configService;
|
|
59
|
+
this.maxQuestionsPerStep = 3;
|
|
60
|
+
const prompts = this.configService.get("prompts");
|
|
61
|
+
this.systemPrompt = prompts?.driftFollowup ?? exports.defaultFollowupPrompt;
|
|
62
|
+
}
|
|
63
|
+
async execute(params) {
|
|
64
|
+
const { state } = params;
|
|
65
|
+
const currentIndex = state.currentFollowUpIndex;
|
|
66
|
+
const currentDepth = state.currentDepth;
|
|
67
|
+
this.logger.debug(`FollowUp Node: processing question ${currentIndex + 1}/${state.followUpQuestions.length} at depth ${currentDepth}`, "FollowUpNodeService");
|
|
68
|
+
// Check if we've processed all questions at current depth
|
|
69
|
+
if (currentIndex >= state.followUpQuestions.length) {
|
|
70
|
+
// Check if we have additional questions from previous answers and haven't reached max depth
|
|
71
|
+
const additionalQuestions = this.collectAdditionalQuestions(state.followUpAnswers);
|
|
72
|
+
if (additionalQuestions.length > 0 && currentDepth + 1 < state.maxDepth) {
|
|
73
|
+
// Move to next depth level with additional questions
|
|
74
|
+
return {
|
|
75
|
+
hops: 1,
|
|
76
|
+
followUpQuestions: additionalQuestions.slice(0, this.maxQuestionsPerStep),
|
|
77
|
+
currentFollowUpIndex: 0,
|
|
78
|
+
currentDepth: currentDepth + 1,
|
|
79
|
+
nextStep: "followup",
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
// No more questions to process
|
|
83
|
+
return {
|
|
84
|
+
hops: 1,
|
|
85
|
+
nextStep: "synthesis",
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
// Process current follow-up question
|
|
89
|
+
const currentQuestion = state.followUpQuestions[currentIndex];
|
|
90
|
+
const communityDetails = await this.gatherCommunityDetails(state.matchedCommunities.map((c) => c.id));
|
|
91
|
+
const inputParams = {
|
|
92
|
+
originalQuestion: state.question,
|
|
93
|
+
followUpQuestion: currentQuestion,
|
|
94
|
+
priorContext: state.priorContext,
|
|
95
|
+
communityDetails,
|
|
96
|
+
};
|
|
97
|
+
const llmResponse = await this.llmService.call({
|
|
98
|
+
inputSchema: inputSchema,
|
|
99
|
+
inputParams: inputParams,
|
|
100
|
+
outputSchema: outputSchema,
|
|
101
|
+
systemPrompts: [this.systemPrompt],
|
|
102
|
+
temperature: 0.3,
|
|
103
|
+
});
|
|
104
|
+
// Create the follow-up answer record
|
|
105
|
+
const followUpAnswer = {
|
|
106
|
+
question: currentQuestion,
|
|
107
|
+
answer: llmResponse.answer,
|
|
108
|
+
depth: currentDepth,
|
|
109
|
+
additionalQuestions: llmResponse.additionalQuestions,
|
|
110
|
+
shouldContinue: llmResponse.shouldContinue,
|
|
111
|
+
};
|
|
112
|
+
// Update prior context with this answer
|
|
113
|
+
const updatedPriorContext = `${state.priorContext}\n\nQ: ${currentQuestion}\nA: ${llmResponse.answer}`;
|
|
114
|
+
this.logger.debug(`FollowUp Node complete: answered question, ${llmResponse.additionalQuestions.length} additional questions`, "FollowUpNodeService");
|
|
115
|
+
return {
|
|
116
|
+
hops: 1,
|
|
117
|
+
followUpAnswers: [followUpAnswer],
|
|
118
|
+
priorContext: updatedPriorContext,
|
|
119
|
+
currentFollowUpIndex: currentIndex + 1,
|
|
120
|
+
tokens: llmResponse.tokenUsage,
|
|
121
|
+
nextStep: "followup", // Continue processing follow-ups
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Collect additional questions from follow-up answers that should continue
|
|
126
|
+
*/
|
|
127
|
+
collectAdditionalQuestions(followUpAnswers) {
|
|
128
|
+
const questions = [];
|
|
129
|
+
for (const answer of followUpAnswers) {
|
|
130
|
+
if (answer.shouldContinue && answer.additionalQuestions.length > 0) {
|
|
131
|
+
questions.push(...answer.additionalQuestions);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return questions;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Gather detailed information about communities for local search
|
|
138
|
+
*/
|
|
139
|
+
async gatherCommunityDetails(communityIds) {
|
|
140
|
+
const details = [];
|
|
141
|
+
for (const communityId of communityIds.slice(0, 3)) {
|
|
142
|
+
try {
|
|
143
|
+
const community = await this.communityRepository.findById(communityId);
|
|
144
|
+
if (!community)
|
|
145
|
+
continue;
|
|
146
|
+
const members = await this.communityRepository.findMemberKeyConcepts(communityId);
|
|
147
|
+
const relationships = await this.communityRepository.findMemberRelationships(communityId);
|
|
148
|
+
const memberDetails = members
|
|
149
|
+
.map((m) => {
|
|
150
|
+
const desc = m.description ? ` - ${m.description}` : "";
|
|
151
|
+
return ` - ${m.value}${desc}`;
|
|
152
|
+
})
|
|
153
|
+
.join("\n");
|
|
154
|
+
const relationshipDetails = relationships.length > 0
|
|
155
|
+
? relationships.map((r) => ` - ${r.keyConcept1} <-> ${r.keyConcept2}`).join("\n")
|
|
156
|
+
: " (no explicit relationships)";
|
|
157
|
+
details.push(`## ${community.name}\n\nMembers:\n${memberDetails}\n\nRelationships:\n${relationshipDetails}`);
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
this.logger.warn(`Failed to gather details for community ${communityId}: ${error.message}`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return details.join("\n\n---\n\n");
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
exports.FollowUpNodeService = FollowUpNodeService;
|
|
167
|
+
exports.FollowUpNodeService = FollowUpNodeService = __decorate([
|
|
168
|
+
(0, common_1.Injectable)(),
|
|
169
|
+
__metadata("design:paramtypes", [llm_service_1.LLMService,
|
|
170
|
+
community_repository_1.CommunityRepository,
|
|
171
|
+
logging_service_1.AppLoggingService,
|
|
172
|
+
config_1.ConfigService])
|
|
173
|
+
], FollowUpNodeService);
|
|
174
|
+
//# sourceMappingURL=followup.node.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"followup.node.service.js","sourceRoot":"","sources":["../../../../src/agents/drift/nodes/followup.node.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,2CAA+C;AAC/C,6BAAwB;AAExB,wEAAoE;AACpE,oFAAmF;AACnF,2GAAuG;AA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,OAAO,CAAC,IAAI,CAAC,MAAM,SAAS,CAAC,IAAI,iBAAiB,aAAa,uBAAuB,mBAAmB,EAAE,CAAC,CAAC;YAC/G,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,0CAA0C,WAAW,KAAM,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;YACzG,CAAC;QACH,CAAC;QAED,OAAO,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IACrC,CAAC;CACF,CAAA;AA5IY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,mBAAU,GAAE;qCAMoB,wBAAU;QACD,0CAAmB;QAChC,mCAAiB;QACV,sBAAa;GARpC,mBAAmB,CA4I/B"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ConfigService } from "@nestjs/config";
|
|
2
|
+
import { BaseConfigInterface } from "../../../config/interfaces";
|
|
3
|
+
import { EmbedderService } from "../../../core";
|
|
4
|
+
import { LLMService } from "../../../core/llm/services/llm.service";
|
|
5
|
+
import { AppLoggingService } from "../../../core/logging/services/logging.service";
|
|
6
|
+
import { CommunityRepository } from "../../../foundations/community/repositories/community.repository";
|
|
7
|
+
import { DriftContext, DriftContextState } from "../contexts/drift.context";
|
|
8
|
+
export declare const defaultHydePrompt = "\nYou are a knowledge synthesis expert. Given a question, generate a hypothetical answer\nthat would appear in a community summary report.\n\n## Context\n\nCommunity summaries are narrative reports that describe clusters of related entities\nfrom a knowledge graph. They typically:\n- Identify the main theme or domain\n- Describe key entities and their roles\n- Explain relationships between entities\n- Provide contextual information\n\n## Your Task\n\nGenerate a hypothetical answer to the question as if it were extracted from a\ncommunity summary report. The answer should:\n- Be written in the same style as a community report\n- Include relevant entity names and relationships\n- Provide context and explanation\n- Be comprehensive but concise (100-200 words)\n\n## Important\n\nDo NOT try to answer the question factually. Generate a HYPOTHETICAL answer\nthat captures the TYPE of information that would answer this question.\n";
|
|
9
|
+
export declare class HydeNodeService {
|
|
10
|
+
private readonly llmService;
|
|
11
|
+
private readonly embedderService;
|
|
12
|
+
private readonly communityRepository;
|
|
13
|
+
private readonly logger;
|
|
14
|
+
private readonly configService;
|
|
15
|
+
private readonly systemPrompt;
|
|
16
|
+
constructor(llmService: LLMService, embedderService: EmbedderService, communityRepository: CommunityRepository, logger: AppLoggingService, configService: ConfigService<BaseConfigInterface>);
|
|
17
|
+
execute(params: {
|
|
18
|
+
state: typeof DriftContext.State;
|
|
19
|
+
}): Promise<Partial<DriftContextState>>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=hyde.node.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hyde.node.service.d.ts","sourceRoot":"","sources":["../../../../src/agents/drift/nodes/hyde.node.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAE,mBAAmB,EAA0B,MAAM,4BAA4B,CAAC;AACzF,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gDAAgD,CAAC;AACnF,OAAO,EAAE,mBAAmB,EAAE,MAAM,kEAAkE,CAAC;AACvG,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAE5E,eAAO,MAAM,iBAAiB,46BA0B7B,CAAC;AAaF,qBACa,eAAe;IAIxB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,mBAAmB;IACpC,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAPhC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;gBAGnB,UAAU,EAAE,UAAU,EACtB,eAAe,EAAE,eAAe,EAChC,mBAAmB,EAAE,mBAAmB,EACxC,MAAM,EAAE,iBAAiB,EACzB,aAAa,EAAE,aAAa,CAAC,mBAAmB,CAAC;IAM9D,OAAO,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,OAAO,YAAY,CAAC,KAAK,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;CA8CjG"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.HydeNodeService = exports.defaultHydePrompt = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const config_1 = require("@nestjs/config");
|
|
15
|
+
const zod_1 = require("zod");
|
|
16
|
+
const core_1 = require("../../../core");
|
|
17
|
+
const llm_service_1 = require("../../../core/llm/services/llm.service");
|
|
18
|
+
const logging_service_1 = require("../../../core/logging/services/logging.service");
|
|
19
|
+
const community_repository_1 = require("../../../foundations/community/repositories/community.repository");
|
|
20
|
+
exports.defaultHydePrompt = `
|
|
21
|
+
You are a knowledge synthesis expert. Given a question, generate a hypothetical answer
|
|
22
|
+
that would appear in a community summary report.
|
|
23
|
+
|
|
24
|
+
## Context
|
|
25
|
+
|
|
26
|
+
Community summaries are narrative reports that describe clusters of related entities
|
|
27
|
+
from a knowledge graph. They typically:
|
|
28
|
+
- Identify the main theme or domain
|
|
29
|
+
- Describe key entities and their roles
|
|
30
|
+
- Explain relationships between entities
|
|
31
|
+
- Provide contextual information
|
|
32
|
+
|
|
33
|
+
## Your Task
|
|
34
|
+
|
|
35
|
+
Generate a hypothetical answer to the question as if it were extracted from a
|
|
36
|
+
community summary report. The answer should:
|
|
37
|
+
- Be written in the same style as a community report
|
|
38
|
+
- Include relevant entity names and relationships
|
|
39
|
+
- Provide context and explanation
|
|
40
|
+
- Be comprehensive but concise (100-200 words)
|
|
41
|
+
|
|
42
|
+
## Important
|
|
43
|
+
|
|
44
|
+
Do NOT try to answer the question factually. Generate a HYPOTHETICAL answer
|
|
45
|
+
that captures the TYPE of information that would answer this question.
|
|
46
|
+
`;
|
|
47
|
+
const outputSchema = zod_1.z.object({
|
|
48
|
+
hypotheticalAnswer: zod_1.z
|
|
49
|
+
.string()
|
|
50
|
+
.describe("A hypothetical answer written in the style of a community summary report (100-200 words)"),
|
|
51
|
+
});
|
|
52
|
+
const inputSchema = zod_1.z.object({
|
|
53
|
+
question: zod_1.z.string().describe("The user's question to generate a hypothetical answer for"),
|
|
54
|
+
sampleSummary: zod_1.z.string().optional().describe("An optional sample community summary for style reference"),
|
|
55
|
+
});
|
|
56
|
+
let HydeNodeService = class HydeNodeService {
|
|
57
|
+
constructor(llmService, embedderService, communityRepository, logger, configService) {
|
|
58
|
+
this.llmService = llmService;
|
|
59
|
+
this.embedderService = embedderService;
|
|
60
|
+
this.communityRepository = communityRepository;
|
|
61
|
+
this.logger = logger;
|
|
62
|
+
this.configService = configService;
|
|
63
|
+
const prompts = this.configService.get("prompts");
|
|
64
|
+
this.systemPrompt = prompts?.hydeGenerator ?? exports.defaultHydePrompt;
|
|
65
|
+
}
|
|
66
|
+
async execute(params) {
|
|
67
|
+
this.logger.debug(`HyDE Node: generating hypothetical answer for "${params.state.question}"`, "HydeNodeService");
|
|
68
|
+
// Optionally fetch a sample community summary for style reference
|
|
69
|
+
let sampleSummary;
|
|
70
|
+
try {
|
|
71
|
+
const communities = await this.communityRepository.findByLevel({ level: 1 });
|
|
72
|
+
if (communities.length > 0 && communities[0].summary) {
|
|
73
|
+
sampleSummary = communities[0].summary;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
// Ignore - sample is optional
|
|
78
|
+
}
|
|
79
|
+
// Generate hypothetical answer via LLM
|
|
80
|
+
const inputParams = {
|
|
81
|
+
question: params.state.question,
|
|
82
|
+
sampleSummary,
|
|
83
|
+
};
|
|
84
|
+
const llmResponse = await this.llmService.call({
|
|
85
|
+
inputSchema: inputSchema,
|
|
86
|
+
inputParams: inputParams,
|
|
87
|
+
outputSchema: outputSchema,
|
|
88
|
+
systemPrompts: [this.systemPrompt],
|
|
89
|
+
temperature: 0.5,
|
|
90
|
+
});
|
|
91
|
+
// Generate embedding for the hypothetical answer
|
|
92
|
+
const embedding = await this.embedderService.vectoriseText({
|
|
93
|
+
text: llmResponse.hypotheticalAnswer,
|
|
94
|
+
});
|
|
95
|
+
this.logger.debug(`HyDE Node complete: generated ${llmResponse.hypotheticalAnswer.length} char answer`, "HydeNodeService");
|
|
96
|
+
return {
|
|
97
|
+
hops: 1,
|
|
98
|
+
hypotheticalAnswer: llmResponse.hypotheticalAnswer,
|
|
99
|
+
hydeEmbedding: embedding,
|
|
100
|
+
tokens: llmResponse.tokenUsage,
|
|
101
|
+
nextStep: "community_search",
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
exports.HydeNodeService = HydeNodeService;
|
|
106
|
+
exports.HydeNodeService = HydeNodeService = __decorate([
|
|
107
|
+
(0, common_1.Injectable)(),
|
|
108
|
+
__metadata("design:paramtypes", [llm_service_1.LLMService,
|
|
109
|
+
core_1.EmbedderService,
|
|
110
|
+
community_repository_1.CommunityRepository,
|
|
111
|
+
logging_service_1.AppLoggingService,
|
|
112
|
+
config_1.ConfigService])
|
|
113
|
+
], HydeNodeService);
|
|
114
|
+
//# sourceMappingURL=hyde.node.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hyde.node.service.js","sourceRoot":"","sources":["../../../../src/agents/drift/nodes/hyde.node.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,2CAA+C;AAC/C,6BAAwB;AAExB,wCAAgD;AAChD,wEAAoE;AACpE,oFAAmF;AACnF,2GAAuG;AAG1F,QAAA,iBAAiB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BhC,CAAC;AAEF,MAAM,YAAY,GAAG,OAAC,CAAC,MAAM,CAAC;IAC5B,kBAAkB,EAAE,OAAC;SAClB,MAAM,EAAE;SACR,QAAQ,CAAC,0FAA0F,CAAC;CACxG,CAAC,CAAC;AAEH,MAAM,WAAW,GAAG,OAAC,CAAC,MAAM,CAAC;IAC3B,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,2DAA2D,CAAC;IAC1F,aAAa,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,0DAA0D,CAAC;CAC1G,CAAC,CAAC;AAGI,IAAM,eAAe,GAArB,MAAM,eAAe;IAG1B,YACmB,UAAsB,EACtB,eAAgC,EAChC,mBAAwC,EACxC,MAAyB,EACzB,aAAiD;QAJjD,eAAU,GAAV,UAAU,CAAY;QACtB,oBAAe,GAAf,eAAe,CAAiB;QAChC,wBAAmB,GAAnB,mBAAmB,CAAqB;QACxC,WAAM,GAAN,MAAM,CAAmB;QACzB,kBAAa,GAAb,aAAa,CAAoC;QAElE,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAyB,SAAS,CAAC,CAAC;QAC1E,IAAI,CAAC,YAAY,GAAG,OAAO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kB,EAAE,WAAW,CAAC,kBAAkB;YAClD,aAAa,EAAE,SAAS;YACxB,MAAM,EAAE,WAAW,CAAC,UAAU;YAC9B,QAAQ,EAAE,kBAAkB;SAC7B,CAAC;IACJ,CAAC;CACF,CAAA;AA5DY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;qCAKoB,wBAAU;QACL,sBAAe;QACX,0CAAmB;QAChC,mCAAiB;QACV,sBAAa;GARpC,eAAe,CA4D3B"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ConfigService } from "@nestjs/config";
|
|
2
|
+
import { BaseConfigInterface } from "../../../config/interfaces";
|
|
3
|
+
import { LLMService } from "../../../core/llm/services/llm.service";
|
|
4
|
+
import { AppLoggingService } from "../../../core/logging/services/logging.service";
|
|
5
|
+
import { DriftContext, DriftContextState } from "../contexts/drift.context";
|
|
6
|
+
export declare const defaultPrimerPrompt = "\nYou are a knowledge synthesis expert analyzing community reports from a knowledge graph.\n\n## Your Task\n\nGiven a question and relevant community summaries, provide:\n1. An initial broad answer based on the community context\n2. Follow-up questions that would help drill deeper into the specifics\n\n## Guidelines\n\n- Synthesize information from multiple community summaries\n- Provide a comprehensive but high-level answer\n- Generate follow-up questions that target specific details\n- Rate your confidence in the answer\n\n## Output\n\nProvide:\n- **answer**: Your initial answer synthesizing the community context (200-400 words)\n- **followUpQuestions**: 2-4 specific questions to drill deeper\n- **confidence**: Your confidence score (0-100) based on relevance of matched communities\n";
|
|
7
|
+
export declare class PrimerAnswerNodeService {
|
|
8
|
+
private readonly llmService;
|
|
9
|
+
private readonly logger;
|
|
10
|
+
private readonly configService;
|
|
11
|
+
private readonly systemPrompt;
|
|
12
|
+
constructor(llmService: LLMService, logger: AppLoggingService, configService: ConfigService<BaseConfigInterface>);
|
|
13
|
+
execute(params: {
|
|
14
|
+
state: typeof DriftContext.State;
|
|
15
|
+
}): Promise<Partial<DriftContextState>>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=primer.answer.node.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"primer.answer.node.service.d.ts","sourceRoot":"","sources":["../../../../src/agents/drift/nodes/primer.answer.node.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAE,mBAAmB,EAA0B,MAAM,4BAA4B,CAAC;AACzF,OAAO,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gDAAgD,CAAC;AACnF,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAE5E,eAAO,MAAM,mBAAmB,iyBAsB/B,CAAC;AAgBF,qBACa,uBAAuB;IAIhC,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,aAAa;IALhC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;gBAGnB,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,iBAAiB,EACzB,aAAa,EAAE,aAAa,CAAC,mBAAmB,CAAC;IAM9D,OAAO,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,OAAO,YAAY,CAAC,KAAK,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;CAqDjG"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PrimerAnswerNodeService = exports.defaultPrimerPrompt = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const config_1 = require("@nestjs/config");
|
|
15
|
+
const zod_1 = require("zod");
|
|
16
|
+
const llm_service_1 = require("../../../core/llm/services/llm.service");
|
|
17
|
+
const logging_service_1 = require("../../../core/logging/services/logging.service");
|
|
18
|
+
exports.defaultPrimerPrompt = `
|
|
19
|
+
You are a knowledge synthesis expert analyzing community reports from a knowledge graph.
|
|
20
|
+
|
|
21
|
+
## Your Task
|
|
22
|
+
|
|
23
|
+
Given a question and relevant community summaries, provide:
|
|
24
|
+
1. An initial broad answer based on the community context
|
|
25
|
+
2. Follow-up questions that would help drill deeper into the specifics
|
|
26
|
+
|
|
27
|
+
## Guidelines
|
|
28
|
+
|
|
29
|
+
- Synthesize information from multiple community summaries
|
|
30
|
+
- Provide a comprehensive but high-level answer
|
|
31
|
+
- Generate follow-up questions that target specific details
|
|
32
|
+
- Rate your confidence in the answer
|
|
33
|
+
|
|
34
|
+
## Output
|
|
35
|
+
|
|
36
|
+
Provide:
|
|
37
|
+
- **answer**: Your initial answer synthesizing the community context (200-400 words)
|
|
38
|
+
- **followUpQuestions**: 2-4 specific questions to drill deeper
|
|
39
|
+
- **confidence**: Your confidence score (0-100) based on relevance of matched communities
|
|
40
|
+
`;
|
|
41
|
+
const outputSchema = zod_1.z.object({
|
|
42
|
+
answer: zod_1.z.string().describe("Initial broad answer synthesizing the community context (200-400 words)"),
|
|
43
|
+
followUpQuestions: zod_1.z
|
|
44
|
+
.array(zod_1.z.string())
|
|
45
|
+
.describe("2-4 specific follow-up questions to drill deeper into the topic"),
|
|
46
|
+
confidence: zod_1.z.number().min(0).max(100).describe("Confidence score based on relevance of matched communities"),
|
|
47
|
+
});
|
|
48
|
+
const inputSchema = zod_1.z.object({
|
|
49
|
+
question: zod_1.z.string().describe("The user's original question"),
|
|
50
|
+
communitySummaries: zod_1.z.string().describe("Relevant community summaries from vector search"),
|
|
51
|
+
communityCount: zod_1.z.number().describe("Number of communities matched"),
|
|
52
|
+
});
|
|
53
|
+
let PrimerAnswerNodeService = class PrimerAnswerNodeService {
|
|
54
|
+
constructor(llmService, logger, configService) {
|
|
55
|
+
this.llmService = llmService;
|
|
56
|
+
this.logger = logger;
|
|
57
|
+
this.configService = configService;
|
|
58
|
+
const prompts = this.configService.get("prompts");
|
|
59
|
+
this.systemPrompt = prompts?.driftPrimer ?? exports.defaultPrimerPrompt;
|
|
60
|
+
}
|
|
61
|
+
async execute(params) {
|
|
62
|
+
this.logger.debug(`Primer Answer Node: generating initial answer from ${params.state.matchedCommunities.length} communities`, "PrimerAnswerNodeService");
|
|
63
|
+
// Handle case where no communities were found
|
|
64
|
+
if (params.state.matchedCommunities.length === 0) {
|
|
65
|
+
return {
|
|
66
|
+
hops: 1,
|
|
67
|
+
initialAnswer: "No relevant community context found for this question.",
|
|
68
|
+
followUpQuestions: [],
|
|
69
|
+
confidence: 0,
|
|
70
|
+
priorContext: "",
|
|
71
|
+
nextStep: "synthesis",
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const inputParams = {
|
|
75
|
+
question: params.state.question,
|
|
76
|
+
communitySummaries: params.state.communitySummaries,
|
|
77
|
+
communityCount: params.state.matchedCommunities.length,
|
|
78
|
+
};
|
|
79
|
+
const llmResponse = await this.llmService.call({
|
|
80
|
+
inputSchema: inputSchema,
|
|
81
|
+
inputParams: inputParams,
|
|
82
|
+
outputSchema: outputSchema,
|
|
83
|
+
systemPrompts: [this.systemPrompt],
|
|
84
|
+
temperature: 0.3,
|
|
85
|
+
});
|
|
86
|
+
this.logger.debug(`Primer Answer Node complete: ${llmResponse.followUpQuestions.length} follow-ups, confidence: ${llmResponse.confidence}`, "PrimerAnswerNodeService");
|
|
87
|
+
// Determine next step based on follow-up questions
|
|
88
|
+
const hasFollowUps = llmResponse.followUpQuestions.length > 0;
|
|
89
|
+
const nextStep = hasFollowUps ? "followup" : "synthesis";
|
|
90
|
+
return {
|
|
91
|
+
hops: 1,
|
|
92
|
+
initialAnswer: llmResponse.answer,
|
|
93
|
+
followUpQuestions: llmResponse.followUpQuestions,
|
|
94
|
+
confidence: llmResponse.confidence,
|
|
95
|
+
priorContext: llmResponse.answer,
|
|
96
|
+
currentFollowUpIndex: 0,
|
|
97
|
+
currentDepth: 0,
|
|
98
|
+
tokens: llmResponse.tokenUsage,
|
|
99
|
+
nextStep,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
exports.PrimerAnswerNodeService = PrimerAnswerNodeService;
|
|
104
|
+
exports.PrimerAnswerNodeService = PrimerAnswerNodeService = __decorate([
|
|
105
|
+
(0, common_1.Injectable)(),
|
|
106
|
+
__metadata("design:paramtypes", [llm_service_1.LLMService,
|
|
107
|
+
logging_service_1.AppLoggingService,
|
|
108
|
+
config_1.ConfigService])
|
|
109
|
+
], PrimerAnswerNodeService);
|
|
110
|
+
//# sourceMappingURL=primer.answer.node.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"primer.answer.node.service.js","sourceRoot":"","sources":["../../../../src/agents/drift/nodes/primer.answer.node.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,2CAA+C;AAC/C,6BAAwB;AAExB,wEAAoE;AACpE,oFAAmF;AAGtE,QAAA,mBAAmB,GAAG;;;;;;;;;;;;;;;;;;;;;;CAsBlC,CAAC;AAEF,MAAM,YAAY,GAAG,OAAC,CAAC,MAAM,CAAC;IAC5B,MAAM,EAAE,OAAC,CAAC,MAAM,EAA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CAAA;AAjEY,0DAAuB;kCAAvB,uBAAuB;IADnC,IAAA,mBAAU,GAAE;qCAKoB,wBAAU;QACd,mCAAiB;QACV,sBAAa;GANpC,uBAAuB,CAiEnC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ConfigService } from "@nestjs/config";
|
|
2
|
+
import { BaseConfigInterface } from "../../../config/interfaces";
|
|
3
|
+
import { LLMService } from "../../../core/llm/services/llm.service";
|
|
4
|
+
import { AppLoggingService } from "../../../core/logging/services/logging.service";
|
|
5
|
+
import { DriftContext, DriftContextState } from "../contexts/drift.context";
|
|
6
|
+
export declare const defaultSynthesisPrompt = "\nYou are a knowledge synthesis expert producing a final comprehensive answer.\n\n## Your Task\n\nSynthesize all gathered information into a final, comprehensive answer to the user's question.\n\n## Input\n\nYou will receive:\n1. The original question\n2. An initial broad answer from community context\n3. Detailed answers from follow-up investigations\n\n## Guidelines\n\n- Integrate all relevant information cohesively\n- Structure your response clearly\n- Cite specific entities and relationships when relevant\n- Acknowledge any limitations or gaps in the available information\n- Be comprehensive but concise\n\n## Output\n\nProvide a final comprehensive answer (300-600 words) that addresses the user's question\nusing all available context.\n";
|
|
7
|
+
export declare class SynthesisNodeService {
|
|
8
|
+
private readonly llmService;
|
|
9
|
+
private readonly logger;
|
|
10
|
+
private readonly configService;
|
|
11
|
+
private readonly systemPrompt;
|
|
12
|
+
constructor(llmService: LLMService, logger: AppLoggingService, configService: ConfigService<BaseConfigInterface>);
|
|
13
|
+
execute(params: {
|
|
14
|
+
state: typeof DriftContext.State;
|
|
15
|
+
}): Promise<Partial<DriftContextState>>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=synthesis.node.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"synthesis.node.service.d.ts","sourceRoot":"","sources":["../../../../src/agents/drift/nodes/synthesis.node.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAE,mBAAmB,EAA0B,MAAM,4BAA4B,CAAC;AACzF,OAAO,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gDAAgD,CAAC;AACnF,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAE5E,eAAO,MAAM,sBAAsB,mvBA0BlC,CAAC;AAaF,qBACa,oBAAoB;IAI7B,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,aAAa;IALhC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;gBAGnB,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,iBAAiB,EACzB,aAAa,EAAE,aAAa,CAAC,mBAAmB,CAAC;IAM9D,OAAO,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,OAAO,YAAY,CAAC,KAAK,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;CA6CjG"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.SynthesisNodeService = exports.defaultSynthesisPrompt = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const config_1 = require("@nestjs/config");
|
|
15
|
+
const zod_1 = require("zod");
|
|
16
|
+
const llm_service_1 = require("../../../core/llm/services/llm.service");
|
|
17
|
+
const logging_service_1 = require("../../../core/logging/services/logging.service");
|
|
18
|
+
exports.defaultSynthesisPrompt = `
|
|
19
|
+
You are a knowledge synthesis expert producing a final comprehensive answer.
|
|
20
|
+
|
|
21
|
+
## Your Task
|
|
22
|
+
|
|
23
|
+
Synthesize all gathered information into a final, comprehensive answer to the user's question.
|
|
24
|
+
|
|
25
|
+
## Input
|
|
26
|
+
|
|
27
|
+
You will receive:
|
|
28
|
+
1. The original question
|
|
29
|
+
2. An initial broad answer from community context
|
|
30
|
+
3. Detailed answers from follow-up investigations
|
|
31
|
+
|
|
32
|
+
## Guidelines
|
|
33
|
+
|
|
34
|
+
- Integrate all relevant information cohesively
|
|
35
|
+
- Structure your response clearly
|
|
36
|
+
- Cite specific entities and relationships when relevant
|
|
37
|
+
- Acknowledge any limitations or gaps in the available information
|
|
38
|
+
- Be comprehensive but concise
|
|
39
|
+
|
|
40
|
+
## Output
|
|
41
|
+
|
|
42
|
+
Provide a final comprehensive answer (300-600 words) that addresses the user's question
|
|
43
|
+
using all available context.
|
|
44
|
+
`;
|
|
45
|
+
const outputSchema = zod_1.z.object({
|
|
46
|
+
finalAnswer: zod_1.z.string().describe("Final comprehensive answer synthesizing all gathered information (300-600 words)"),
|
|
47
|
+
});
|
|
48
|
+
const inputSchema = zod_1.z.object({
|
|
49
|
+
question: zod_1.z.string().describe("The original user question"),
|
|
50
|
+
initialAnswer: zod_1.z.string().describe("Initial broad answer from community context"),
|
|
51
|
+
followUpAnswers: zod_1.z.string().describe("Detailed answers from follow-up investigations"),
|
|
52
|
+
confidence: zod_1.z.number().describe("Overall confidence from the primer phase"),
|
|
53
|
+
});
|
|
54
|
+
let SynthesisNodeService = class SynthesisNodeService {
|
|
55
|
+
constructor(llmService, logger, configService) {
|
|
56
|
+
this.llmService = llmService;
|
|
57
|
+
this.logger = logger;
|
|
58
|
+
this.configService = configService;
|
|
59
|
+
const prompts = this.configService.get("prompts");
|
|
60
|
+
this.systemPrompt = prompts?.driftSearch ?? exports.defaultSynthesisPrompt;
|
|
61
|
+
}
|
|
62
|
+
async execute(params) {
|
|
63
|
+
this.logger.debug(`Synthesis Node: synthesizing answer from ${params.state.followUpAnswers.length} follow-ups`, "SynthesisNodeService");
|
|
64
|
+
// Handle case where no communities were matched
|
|
65
|
+
if (params.state.matchedCommunities.length === 0) {
|
|
66
|
+
return {
|
|
67
|
+
hops: 1,
|
|
68
|
+
finalAnswer: params.state.initialAnswer || "No relevant information found in the knowledge base.",
|
|
69
|
+
nextStep: "end",
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
// Format follow-up answers for LLM
|
|
73
|
+
const followUpAnswers = params.state.followUpAnswers.length > 0
|
|
74
|
+
? params.state.followUpAnswers.map((f) => `**Q: ${f.question}**\n${f.answer}`).join("\n\n")
|
|
75
|
+
: "No follow-up investigations were conducted.";
|
|
76
|
+
const inputParams = {
|
|
77
|
+
question: params.state.question,
|
|
78
|
+
initialAnswer: params.state.initialAnswer,
|
|
79
|
+
followUpAnswers,
|
|
80
|
+
confidence: params.state.confidence,
|
|
81
|
+
};
|
|
82
|
+
const llmResponse = await this.llmService.call({
|
|
83
|
+
inputSchema: inputSchema,
|
|
84
|
+
inputParams: inputParams,
|
|
85
|
+
outputSchema: outputSchema,
|
|
86
|
+
systemPrompts: [this.systemPrompt],
|
|
87
|
+
temperature: 0.3,
|
|
88
|
+
});
|
|
89
|
+
this.logger.debug(`Synthesis Node complete: generated final answer`, "SynthesisNodeService");
|
|
90
|
+
return {
|
|
91
|
+
hops: 1,
|
|
92
|
+
finalAnswer: llmResponse.finalAnswer,
|
|
93
|
+
tokens: llmResponse.tokenUsage,
|
|
94
|
+
nextStep: "end",
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
exports.SynthesisNodeService = SynthesisNodeService;
|
|
99
|
+
exports.SynthesisNodeService = SynthesisNodeService = __decorate([
|
|
100
|
+
(0, common_1.Injectable)(),
|
|
101
|
+
__metadata("design:paramtypes", [llm_service_1.LLMService,
|
|
102
|
+
logging_service_1.AppLoggingService,
|
|
103
|
+
config_1.ConfigService])
|
|
104
|
+
], SynthesisNodeService);
|
|
105
|
+
//# sourceMappingURL=synthesis.node.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"synthesis.node.service.js","sourceRoot":"","sources":["../../../../src/agents/drift/nodes/synthesis.node.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,2CAA+C;AAC/C,6BAAwB;AAExB,wEAAoE;AACpE,oFAAmF;AAGtE,QAAA,sBAAsB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BrC,CAAC;AAEF,MAAM,YAAY,GAAG,OAAC,CAAC,MAAM,CAAC;IAC5B,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,kFAAkF,CAAC;CACrH,CAAC,CAAC;AAEH,MAAM,WAAW,GAAG,OAAC,CAAC,MAAM,CAAC;IAC3B,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,4BAA4B,CAAC;IAC3D,aAAa,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,6CAA6C,CAAC;IACjF,eAAe,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,gDAAgD,CAAC;IACtF,UAAU,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,0CAA0C,CAAC;CAC5E,CAAC,CAAC;AAGI,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAG/B,YACmB,UAAsB,E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