mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-11-11 01:10:11 +01:00
a5bb77f97a
V1 of agent support via built-in `@agent` that can be invoked alongside normal workspace RAG chat.
72 lines
1.7 KiB
JavaScript
72 lines
1.7 KiB
JavaScript
const pluralize = require("pluralize");
|
|
const {
|
|
WorkspaceAgentInvocation,
|
|
} = require("../../models/workspaceAgentInvocation");
|
|
const { writeResponseChunk } = require("../helpers/chat/responses");
|
|
|
|
async function grepAgents({
|
|
uuid,
|
|
response,
|
|
message,
|
|
workspace,
|
|
user = null,
|
|
thread = null,
|
|
}) {
|
|
const agentHandles = WorkspaceAgentInvocation.parseAgents(message);
|
|
if (agentHandles.length > 0) {
|
|
const { invocation: newInvocation } = await WorkspaceAgentInvocation.new({
|
|
prompt: message,
|
|
workspace: workspace,
|
|
user: user,
|
|
thread: thread,
|
|
});
|
|
|
|
if (!newInvocation) {
|
|
writeResponseChunk(response, {
|
|
id: uuid,
|
|
type: "statusResponse",
|
|
textResponse: `${pluralize(
|
|
"Agent",
|
|
agentHandles.length
|
|
)} ${agentHandles.join(
|
|
", "
|
|
)} could not be called. Chat will be handled as default chat.`,
|
|
sources: [],
|
|
close: true,
|
|
error: null,
|
|
});
|
|
return;
|
|
}
|
|
|
|
writeResponseChunk(response, {
|
|
id: uuid,
|
|
type: "agentInitWebsocketConnection",
|
|
textResponse: null,
|
|
sources: [],
|
|
close: false,
|
|
error: null,
|
|
websocketUUID: newInvocation.uuid,
|
|
});
|
|
|
|
// Close HTTP stream-able chunk response method because we will swap to agents now.
|
|
writeResponseChunk(response, {
|
|
id: uuid,
|
|
type: "statusResponse",
|
|
textResponse: `${pluralize(
|
|
"Agent",
|
|
agentHandles.length
|
|
)} ${agentHandles.join(
|
|
", "
|
|
)} invoked.\nSwapping over to agent chat. Type /exit to exit agent execution loop early.`,
|
|
sources: [],
|
|
close: true,
|
|
error: null,
|
|
});
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
module.exports = { grepAgents };
|