Files
anything-llm/server/utils/chats/agents.js
Timothy Carambat b3944eb50e Revert "Add automatic chat mode with native tool calling support (#5140)"
- Need to support documents in agents
- Need to support images in agent mode

This reverts commit 4c69960dca.
2026-03-04 15:29:41 -08:00

74 lines
1.8 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,
animate: false,
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,
animate: true,
});
return true;
}
return false;
}
module.exports = { grepAgents };