Skip to content

Commit c56042c

Browse files
committed
Changed how thread lookups are provided.
1 parent 3a33174 commit c56042c

7 files changed

Lines changed: 33 additions & 36 deletions

File tree

seed/data/default/agents.json

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
"logicalCollection": "67200e060a342cc6ff42ddee",
66
"description": "Generates the information given the node visit history and graph",
77
"reasoning": null,
8-
"capabilities": [
9-
"66c95576ae782803372bd9f8"
10-
],
8+
"capabilities": ["66c95576ae782803372bd9f8"],
119
"memoryEnabled": false,
1210
"subscriptionFilter": null,
1311
"outputFilter": null,
@@ -21,9 +19,7 @@
2119
"logicalCollection": "67200e060a342cc6ff42ddee",
2220
"description": "This agent takes in an existing graph and a request to modify it and returns a list of nodes to upsert, a list of nodes to delete, a list of edges to add, and a list of edges to delete. Good for making complex modifications to existing graphs.",
2321
"reasoning": null,
24-
"capabilities": [
25-
"66fed2ad135939f6d3130fa6"
26-
],
22+
"capabilities": ["66fed2ad135939f6d3130fa6"],
2723
"memoryEnabled": false,
2824
"subscriptionFilter": null,
2925
"outputFilter": null,
@@ -88,9 +84,7 @@
8884
"logicalCollection": "67200e060a342cc6ff42ddee",
8985
"description": "Chooses which node to go to next given the node visit history and graph",
9086
"reasoning": null,
91-
"capabilities": [
92-
"66bf8c22a9430d3fa139143a"
93-
],
87+
"capabilities": ["66bf8c22a9430d3fa139143a"],
9488
"memoryEnabled": false,
9589
"subscriptionFilter": null,
9690
"outputFilter": null,
@@ -104,9 +98,7 @@
10498
"logicalCollection": "67200e060a342cc6ff42ddee",
10599
"description": "Analyzes data received by the Inquiry and provides either a conversation summary or a summary for all possible answers to a particular question.",
106100
"reasoning": null,
107-
"capabilities": [
108-
"669bee8d6773961cdf4604ae"
109-
],
101+
"capabilities": ["669bee8d6773961cdf4604ae"],
110102
"memoryEnabled": false,
111103
"subscriptionFilter": null,
112104
"outputFilter": null,
@@ -120,9 +112,7 @@
120112
"logicalCollection": "67200e060a342cc6ff42ddee",
121113
"description": "Generates the question to ask next given the node visit history and graph",
122114
"reasoning": null,
123-
"capabilities": [
124-
"66c8a9f8d28a5133dd801ab7"
125-
],
115+
"capabilities": ["66c8a9f8d28a5133dd801ab7"],
126116
"memoryEnabled": false,
127117
"subscriptionFilter": null,
128118
"outputFilter": null,
@@ -136,9 +126,7 @@
136126
"logicalCollection": "67200e060a342cc6ff42ddee",
137127
"description": "For a given graph, creates synthetic node visit data",
138128
"reasoning": null,
139-
"capabilities": [
140-
"66c0040e525628d5c5861ed8"
141-
],
129+
"capabilities": ["66c0040e525628d5c5861ed8"],
142130
"memoryEnabled": false,
143131
"subscriptionFilter": null,
144132
"outputFilter": null,
@@ -157,9 +145,7 @@
157145
"variablePassThrough": true,
158146
"_id": "6858291e0b814e997e60176d"
159147
},
160-
"capabilities": [
161-
"66c25d95cbd9c2075c1e5f4e"
162-
],
148+
"capabilities": ["66c25d95cbd9c2075c1e5f4e"],
163149
"memoryEnabled": false,
164150
"subscriptionFilter": null,
165151
"outputFilter": null,
@@ -173,14 +159,12 @@
173159
"logicalCollection": "67200e060a342cc6ff42ddee",
174160
"description": "Generates the information given the node visit history and graph",
175161
"reasoning": null,
176-
"capabilities": [
177-
"66c95576ae782803372bd9f8"
178-
],
162+
"capabilities": ["66c95576ae782803372bd9f8"],
179163
"memoryEnabled": false,
180164
"subscriptionFilter": null,
181165
"outputFilter": null,
182166
"createdAt": "2025-08-01T05:57:04.260Z",
183167
"updatedAt": "2025-08-01T05:57:15.215Z",
184168
"__v": 0
185169
}
186-
]
170+
]

seed/data/default/capabilities.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,4 +475,4 @@
475475
"updatedAt": "2025-06-22T16:05:46.463Z",
476476
"__v": 0
477477
}
478-
]
478+
]

seed/data/default/collections.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
"updatedAt": "2024-10-28T22:19:50.860Z",
1414
"__v": 0
1515
}
16-
]
16+
]

seed/data/default/prompts.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,4 +368,4 @@
368368
"updatedAt": "2025-08-23T22:52:30.746Z",
369369
"__v": 0
370370
}
371-
]
371+
]

src/controllers/prediction.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ export async function generatePrediction({
344344
auth,
345345
subscriptionId,
346346
agentId,
347-
inquiryId,
347+
threadLookups,
348348
variables,
349349
attachments,
350350
integrationId,
@@ -353,7 +353,7 @@ export async function generatePrediction({
353353
auth?: { sub?: string };
354354
subscriptionId: string;
355355
agentId: string;
356-
inquiryId?: string;
356+
threadLookups?: Map<string, string>;
357357
variables: Record<string, string>;
358358
attachments: Array<Content>;
359359
integrationId?: string;
@@ -372,7 +372,7 @@ export async function generatePrediction({
372372
const agent = await getAgent(agentId);
373373
if (!agent) throw new Error(`No agent found for ID: ${agentId}`);
374374

375-
const thread = await findOrCreateThread(subscriptionId, inquiryId);
375+
const thread = await findOrCreateThread(subscriptionId, threadLookups);
376376
await addToThread(thread, auth?.sub, variables, true);
377377

378378
log.debug({
@@ -942,5 +942,9 @@ export async function generatePredictionWithInquiry({
942942
attachments,
943943
integrationId,
944944
correlationId,
945+
threadLookups: new Map([
946+
['inquiryId', inquiryId],
947+
['userId', auth?.sub ?? ''],
948+
]),
945949
});
946950
}

src/database/procedures/quota.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ export async function calculateUserTokenUsage(userId: string): Promise<{
6565

6666
return tokenTotals;
6767
} catch (error) {
68-
log.error({ error, userId }, `Error calculating token usage for user ${userId}`);
68+
log.error(
69+
{ error, userId },
70+
`Error calculating token usage for user ${userId}`,
71+
);
6972
throw new Error(
7073
`Failed to calculate token usage for user ${userId}: ${error instanceof Error ? error.message : 'Unknown error'}`,
7174
);

src/utils/ai/system.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,21 @@ export async function getCapability(
5050
return await Capability.findOne({ alias }).populate('prompts');
5151
}
5252

53+
/**
54+
* Finds or creates a thread for a subscription.
55+
* @param subscriptionId {string} - The ID of the subscription.
56+
* @param threadLookups {Map<string, string>} - A map of values that can be used to look up the thread (e.g., userId, inquiryId).
57+
* @returns {Promise<IThread>} - The found or created thread.
58+
*/
5359
export async function findOrCreateThread(
5460
subscriptionId: string,
55-
inquiryId?: string,
61+
threadLookups?: Map<string, string>,
5662
) {
57-
const updateData: { $setOnInsert: { messages: []; inquiryId?: string } } = {
63+
const updateData = {
5864
$setOnInsert: { messages: [] },
5965
};
60-
if (inquiryId) {
61-
updateData.$setOnInsert.inquiryId = inquiryId;
66+
for (const [key, value] of threadLookups?.entries() || []) {
67+
updateData.$setOnInsert[key] = value;
6268
}
6369

6470
return await Thread.findOneAndUpdate({ subscriptionId }, updateData, {

0 commit comments

Comments
 (0)