Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 9 additions & 25 deletions seed/data/default/agents.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
"logicalCollection": "67200e060a342cc6ff42ddee",
"description": "Generates the information given the node visit history and graph",
"reasoning": null,
"capabilities": [
"68b6542f873e1debe91487bc"
],
"capabilities": ["68b6542f873e1debe91487bc"],
"memoryEnabled": false,
"subscriptionFilter": null,
"outputFilter": null,
Expand All @@ -21,9 +19,7 @@
"logicalCollection": "67200e060a342cc6ff42ddee",
"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.",
"reasoning": null,
"capabilities": [
"66fed2ad135939f6d3130fa6"
],
"capabilities": ["66fed2ad135939f6d3130fa6"],
"memoryEnabled": false,
"subscriptionFilter": null,
"outputFilter": null,
Expand Down Expand Up @@ -88,9 +84,7 @@
"logicalCollection": "67200e060a342cc6ff42ddee",
"description": "Chooses which node to go to next given the node visit history and graph",
"reasoning": null,
"capabilities": [
"66bf8c22a9430d3fa139143a"
],
"capabilities": ["66bf8c22a9430d3fa139143a"],
"memoryEnabled": false,
"subscriptionFilter": null,
"outputFilter": null,
Expand All @@ -104,9 +98,7 @@
"logicalCollection": "67200e060a342cc6ff42ddee",
"description": "Analyzes data received by the Inquiry and provides either a conversation summary or a summary for all possible answers to a particular question.",
"reasoning": null,
"capabilities": [
"669bee8d6773961cdf4604ae"
],
"capabilities": ["669bee8d6773961cdf4604ae"],
"memoryEnabled": false,
"subscriptionFilter": null,
"outputFilter": null,
Expand All @@ -120,9 +112,7 @@
"logicalCollection": "67200e060a342cc6ff42ddee",
"description": "Generates the question to ask next given the node visit history and graph",
"reasoning": null,
"capabilities": [
"66c8a9f8d28a5133dd801ab7"
],
"capabilities": ["66c8a9f8d28a5133dd801ab7"],
"memoryEnabled": false,
"subscriptionFilter": null,
"outputFilter": null,
Expand All @@ -136,9 +126,7 @@
"logicalCollection": "67200e060a342cc6ff42ddee",
"description": "For a given graph, creates synthetic node visit data",
"reasoning": null,
"capabilities": [
"66c0040e525628d5c5861ed8"
],
"capabilities": ["66c0040e525628d5c5861ed8"],
"memoryEnabled": false,
"subscriptionFilter": null,
"outputFilter": null,
Expand All @@ -157,9 +145,7 @@
"variablePassThrough": true,
"_id": "6858291e0b814e997e60176d"
},
"capabilities": [
"66c25d95cbd9c2075c1e5f4e"
],
"capabilities": ["66c25d95cbd9c2075c1e5f4e"],
"memoryEnabled": false,
"subscriptionFilter": null,
"outputFilter": null,
Expand All @@ -173,14 +159,12 @@
"logicalCollection": "67200e060a342cc6ff42ddee",
"description": "Generates the information given the node visit history and graph",
"reasoning": null,
"capabilities": [
"66c95576ae782803372bd9f8"
],
"capabilities": ["66c95576ae782803372bd9f8"],
"memoryEnabled": false,
"subscriptionFilter": null,
"outputFilter": null,
"createdAt": "2025-08-01T05:57:04.260Z",
"updatedAt": "2025-08-01T05:57:15.215Z",
"__v": 0
}
]
]
2 changes: 1 addition & 1 deletion seed/data/default/capabilities.json
Original file line number Diff line number Diff line change
Expand Up @@ -499,4 +499,4 @@
"updatedAt": "2025-09-02T02:19:27.488Z",
"__v": 0
}
]
]
2 changes: 1 addition & 1 deletion seed/data/default/collections.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
"updatedAt": "2024-10-28T22:19:50.860Z",
"__v": 0
}
]
]
2 changes: 1 addition & 1 deletion seed/data/default/prompts.json
Original file line number Diff line number Diff line change
Expand Up @@ -368,4 +368,4 @@
"updatedAt": "2025-08-23T22:52:30.746Z",
"__v": 0
}
]
]
10 changes: 7 additions & 3 deletions src/controllers/prediction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ export async function generatePrediction({
auth,
subscriptionId,
agentId,
inquiryId,
threadLookups,
variables,
attachments,
integrationId,
Expand All @@ -353,7 +353,7 @@ export async function generatePrediction({
auth?: { sub?: string };
subscriptionId: string;
agentId: string;
inquiryId?: string;
threadLookups?: Map<string, string>;
variables: Record<string, string>;
attachments: Array<Content>;
integrationId?: string;
Expand All @@ -372,7 +372,7 @@ export async function generatePrediction({
const agent = await getAgent(agentId);
if (!agent) throw new Error(`No agent found for ID: ${agentId}`);

const thread = await findOrCreateThread(subscriptionId, inquiryId);
const thread = await findOrCreateThread(subscriptionId, threadLookups);
await addToThread(thread, auth?.sub, variables, true);

log.debug({
Expand Down Expand Up @@ -942,5 +942,9 @@ export async function generatePredictionWithInquiry({
attachments,
integrationId,
correlationId,
threadLookups: new Map([
['inquiryId', inquiryId],
['userId', auth?.sub ?? ''],
]),
});
}
5 changes: 4 additions & 1 deletion src/database/procedures/quota.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ export async function calculateUserTokenUsage(userId: string): Promise<{

return tokenTotals;
} catch (error) {
log.error({ error, userId }, `Error calculating token usage for user ${userId}`);
log.error(
{ error, userId },
`Error calculating token usage for user ${userId}`,
);
throw new Error(
`Failed to calculate token usage for user ${userId}: ${error instanceof Error ? error.message : 'Unknown error'}`,
);
Expand Down
14 changes: 10 additions & 4 deletions src/utils/ai/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,21 @@ export async function getCapability(
return await Capability.findOne({ alias }).populate('prompts');
}

/**
* Finds or creates a thread for a subscription.
* @param subscriptionId {string} - The ID of the subscription.
* @param threadLookups {Map<string, string>} - A map of values that can be used to look up the thread (e.g., userId, inquiryId).
* @returns {Promise<IThread>} - The found or created thread.
*/
export async function findOrCreateThread(
subscriptionId: string,
inquiryId?: string,
threadLookups?: Map<string, string>,
) {
const updateData: { $setOnInsert: { messages: []; inquiryId?: string } } = {
const updateData = {
$setOnInsert: { messages: [] },
};
if (inquiryId) {
updateData.$setOnInsert.inquiryId = inquiryId;
for (const [key, value] of threadLookups?.entries() || []) {
updateData.$setOnInsert[key] = value;
}

return await Thread.findOneAndUpdate({ subscriptionId }, updateData, {
Expand Down