mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-21 21:50:49 +02:00
feat: deprecate Agent Chain functionality and update related methods for improved clarity
This commit is contained in:
parent
611411e712
commit
f87bc231c5
4 changed files with 37 additions and 5 deletions
|
@ -95,6 +95,19 @@ class ModelEndHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Agent Chain helper
|
||||||
|
* @param {string | undefined} [last_agent_id]
|
||||||
|
* @param {string | undefined} [langgraph_node]
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
function checkIfLastAgent(last_agent_id, langgraph_node) {
|
||||||
|
if (!last_agent_id || !langgraph_node) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return langgraph_node?.endsWith(last_agent_id);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get default handlers for stream events.
|
* Get default handlers for stream events.
|
||||||
* @param {Object} options - The options object.
|
* @param {Object} options - The options object.
|
||||||
|
@ -125,7 +138,7 @@ function getDefaultHandlers({ res, aggregateContent, toolEndCallback, collectedU
|
||||||
handle: (event, data, metadata) => {
|
handle: (event, data, metadata) => {
|
||||||
if (data?.stepDetails.type === StepTypes.TOOL_CALLS) {
|
if (data?.stepDetails.type === StepTypes.TOOL_CALLS) {
|
||||||
sendEvent(res, { event, data });
|
sendEvent(res, { event, data });
|
||||||
} else if (metadata?.last_agent_index === metadata?.agent_index) {
|
} else if (checkIfLastAgent(metadata?.last_agent_id, metadata?.langgraph_node)) {
|
||||||
sendEvent(res, { event, data });
|
sendEvent(res, { event, data });
|
||||||
} else if (!metadata?.hide_sequential_outputs) {
|
} else if (!metadata?.hide_sequential_outputs) {
|
||||||
sendEvent(res, { event, data });
|
sendEvent(res, { event, data });
|
||||||
|
@ -154,7 +167,7 @@ function getDefaultHandlers({ res, aggregateContent, toolEndCallback, collectedU
|
||||||
handle: (event, data, metadata) => {
|
handle: (event, data, metadata) => {
|
||||||
if (data?.delta.type === StepTypes.TOOL_CALLS) {
|
if (data?.delta.type === StepTypes.TOOL_CALLS) {
|
||||||
sendEvent(res, { event, data });
|
sendEvent(res, { event, data });
|
||||||
} else if (metadata?.last_agent_index === metadata?.agent_index) {
|
} else if (checkIfLastAgent(metadata?.last_agent_id, metadata?.langgraph_node)) {
|
||||||
sendEvent(res, { event, data });
|
sendEvent(res, { event, data });
|
||||||
} else if (!metadata?.hide_sequential_outputs) {
|
} else if (!metadata?.hide_sequential_outputs) {
|
||||||
sendEvent(res, { event, data });
|
sendEvent(res, { event, data });
|
||||||
|
@ -172,7 +185,7 @@ function getDefaultHandlers({ res, aggregateContent, toolEndCallback, collectedU
|
||||||
handle: (event, data, metadata) => {
|
handle: (event, data, metadata) => {
|
||||||
if (data?.result != null) {
|
if (data?.result != null) {
|
||||||
sendEvent(res, { event, data });
|
sendEvent(res, { event, data });
|
||||||
} else if (metadata?.last_agent_index === metadata?.agent_index) {
|
} else if (checkIfLastAgent(metadata?.last_agent_id, metadata?.langgraph_node)) {
|
||||||
sendEvent(res, { event, data });
|
sendEvent(res, { event, data });
|
||||||
} else if (!metadata?.hide_sequential_outputs) {
|
} else if (!metadata?.hide_sequential_outputs) {
|
||||||
sendEvent(res, { event, data });
|
sendEvent(res, { event, data });
|
||||||
|
@ -188,7 +201,7 @@ function getDefaultHandlers({ res, aggregateContent, toolEndCallback, collectedU
|
||||||
* @param {GraphRunnableConfig['configurable']} [metadata] The runnable metadata.
|
* @param {GraphRunnableConfig['configurable']} [metadata] The runnable metadata.
|
||||||
*/
|
*/
|
||||||
handle: (event, data, metadata) => {
|
handle: (event, data, metadata) => {
|
||||||
if (metadata?.last_agent_index === metadata?.agent_index) {
|
if (checkIfLastAgent(metadata?.last_agent_id, metadata?.langgraph_node)) {
|
||||||
sendEvent(res, { event, data });
|
sendEvent(res, { event, data });
|
||||||
} else if (!metadata?.hide_sequential_outputs) {
|
} else if (!metadata?.hide_sequential_outputs) {
|
||||||
sendEvent(res, { event, data });
|
sendEvent(res, { event, data });
|
||||||
|
@ -204,7 +217,7 @@ function getDefaultHandlers({ res, aggregateContent, toolEndCallback, collectedU
|
||||||
* @param {GraphRunnableConfig['configurable']} [metadata] The runnable metadata.
|
* @param {GraphRunnableConfig['configurable']} [metadata] The runnable metadata.
|
||||||
*/
|
*/
|
||||||
handle: (event, data, metadata) => {
|
handle: (event, data, metadata) => {
|
||||||
if (metadata?.last_agent_index === metadata?.agent_index) {
|
if (checkIfLastAgent(metadata?.last_agent_id, metadata?.langgraph_node)) {
|
||||||
sendEvent(res, { event, data });
|
sendEvent(res, { event, data });
|
||||||
} else if (!metadata?.hide_sequential_outputs) {
|
} else if (!metadata?.hide_sequential_outputs) {
|
||||||
sendEvent(res, { event, data });
|
sendEvent(res, { event, data });
|
||||||
|
|
|
@ -867,6 +867,9 @@ class AgentClient extends BaseClient {
|
||||||
if (userMCPAuthMap != null) {
|
if (userMCPAuthMap != null) {
|
||||||
config.configurable.userMCPAuthMap = userMCPAuthMap;
|
config.configurable.userMCPAuthMap = userMCPAuthMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @deprecated Agent Chain */
|
||||||
|
config.configurable.last_agent_id = agents[agents.length - 1].id;
|
||||||
await run.processStream({ messages }, config, {
|
await run.processStream({ messages }, config, {
|
||||||
callbacks: {
|
callbacks: {
|
||||||
[Callback.TOOL_ERROR]: logToolError,
|
[Callback.TOOL_ERROR]: logToolError,
|
||||||
|
@ -877,6 +880,20 @@ class AgentClient extends BaseClient {
|
||||||
};
|
};
|
||||||
|
|
||||||
await runAgents(initialMessages);
|
await runAgents(initialMessages);
|
||||||
|
/** @deprecated Agent Chain */
|
||||||
|
if (config.configurable.hide_sequential_outputs) {
|
||||||
|
this.contentParts = this.contentParts.filter((part, index) => {
|
||||||
|
// Include parts that are either:
|
||||||
|
// 1. At or after the finalContentStart index
|
||||||
|
// 2. Of type tool_call
|
||||||
|
// 3. Have tool_call_ids property
|
||||||
|
return (
|
||||||
|
index >= this.contentParts.length - 1 ||
|
||||||
|
part.type === ContentTypes.TOOL_CALL ||
|
||||||
|
part.tool_call_ids
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const attachments = await this.awaitMemoryWithTimeout(memoryPromise);
|
const attachments = await this.awaitMemoryWithTimeout(memoryPromise);
|
||||||
|
|
|
@ -192,6 +192,7 @@ const initializeClient = async ({ req, res, signal, endpointOption }) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @deprecated Agent Chain */
|
||||||
if (agent_ids?.length) {
|
if (agent_ids?.length) {
|
||||||
for (const agentId of agent_ids) {
|
for (const agentId of agent_ids) {
|
||||||
if (checkAgentInit(agentId)) {
|
if (checkAgentInit(agentId)) {
|
||||||
|
|
|
@ -7,6 +7,7 @@ const DEFAULT_PROMPT_TEMPLATE = `Based on the following conversation and analysi
|
||||||
/**
|
/**
|
||||||
* Helper function to create sequential chain edges with buffer string prompts
|
* Helper function to create sequential chain edges with buffer string prompts
|
||||||
*
|
*
|
||||||
|
* @deprecated Agent Chain helper
|
||||||
* @param agentIds - Array of agent IDs in order of execution
|
* @param agentIds - Array of agent IDs in order of execution
|
||||||
* @param promptTemplate - Optional prompt template string; defaults to a predefined template if not provided
|
* @param promptTemplate - Optional prompt template string; defaults to a predefined template if not provided
|
||||||
* @returns Array of edges configured for sequential chain with buffer prompts
|
* @returns Array of edges configured for sequential chain with buffer prompts
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue