AgentExcecutor Chains Are Deleting the Run Name
spencermize opened this issue Β· comments
Checked other resources
- I added a very descriptive title to this issue.
- I searched the LangChain.js documentation with the integrated search.
- I used the GitHub search to find a similar question and didn't find it.
- I am sure that this is a bug in LangChain.js rather than my code.
- The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
Example Code
const agentExecutor = new AgentExecutor({
agent,
tools,
}).withConfig({ runName: 'Hi test!' })
const eventStream = agentExecutor.streamEvents(params, {
version: 'v1',
})
Error Message and Stack Trace (if applicable)
No response
Description
I've dug a bit though the source, and have found the following:
In the patchConfig.js
file, we have
/**
* If we're replacing callbacks we need to unset runName
* since that should apply only to the same run as the original callbacks
*/
delete newConfig.runName;
which is where my Hi test
goes to die!
Interestingly, the name
parameter is right in the actual stream events. I've tried to hit the Langsmith endpoint directly to set the run name, but that messes up other things (the output never gets filled out...?)
The name that ultimately gets logged to Langsmith is AgentExecutor
.
System Info
ββ langchain@npm:0.1.36
ββ Instances: 1
ββ Version: 0.1.36
β
ββ Dependencies
ββ @anthropic-ai/sdk@npm:^0.9.1 β npm:0.9.1
ββ @langchain/community@npm:~0.0.47 β npm:0.0.49
ββ @langchain/core@npm:~0.1.60 β npm:0.1.62
ββ @langchain/openai@npm:~0.0.28 β npm:0.0.28
ββ @langchain/textsplitters@npm:~0.0.0 β npm:0.0.0
ββ binary-extensions@npm:^2.2.0 β npm:2.2.0
ββ js-tiktoken@npm:^1.0.7 β npm:1.0.10
ββ js-yaml@npm:^4.1.0 β npm:4.1.0
ββ jsonpointer@npm:^5.0.1 β npm:5.0.1
ββ langchainhub@npm:~0.0.8 β npm:0.0.8
ββ langsmith@npm:~0.1.7 β npm:0.1.22
ββ ml-distance@npm:^4.0.0 β npm:4.0.1
ββ openapi-types@npm:^12.1.3 β npm:12.1.3
ββ p-retry@npm:4 β npm:4.6.2
ββ uuid@npm:^9.0.0 β npm:9.0.1
ββ yaml@npm:^2.2.1 β npm:2.4.1
ββ zod-to-json-schema@npm:^3.22.3 β npm:3.23.0
ββ zod@npm:^3.22.4 β npm:3.23.7
To address the issue where runName
is being deleted in the patchConfig.js
file, you can modify the patchConfig
function to conditionally delete runName
only if it's not explicitly provided in the function arguments. This ensures that runName
is preserved when explicitly set, allowing it to be correctly utilized in your configuration.
Here's a suggested modification for the patchConfig
function:
export function patchConfig<CallOptions extends RunnableConfig>(
config: Partial<CallOptions> = {},
{
callbacks,
maxConcurrency,
recursionLimit,
runName,
configurable,
runId,
}: RunnableConfig = {}
): Partial<CallOptions> {
const newConfig = ensureConfig(config);
// Only delete runName if it's not provided in the function arguments.
if (runName === undefined) {
delete newConfig.runName;
} else {
newConfig.runName = runName;
}
// Additional configuration adjustments
if (callbacks !== undefined) {
newConfig.callbacks = callbacks;
}
if (recursionLimit !== undefined) {
newConfig.recursionLimit = recursionLimit;
}
if (maxConcurrency !== undefined) {
newConfig.maxConcurrency = maxConcurrency;
}
if (configurable !== undefined) {
newConfig.configurable = { ...newConfig.configurable, ...configurable };
}
if (runId !== undefined) {
delete newConfig.runId;
}
return newConfig;
}
This adjustment ensures that runName
is only removed if not explicitly being set in the current operation, allowing for its preservation and correct usage when provided.
Regarding your workaround with the Langsmith endpoint and the issues it caused, it's important to understand that runName
is used internally for identifying or labeling execution runs, which is crucial for logging, debugging, or tracking purposes. Incorrectly setting or manipulating runName
could disrupt normal data flow and processing, leading to incomplete or incorrect output data.
If you have further questions or need additional clarification, feel free to ask.
Details
Sources
- langchain-core/src/runnables/config.ts
- langchain/src/agents/executor.ts
- langchain-core/src/runnables/base.ts
- langchain-core/src/tracers/base.ts
- langchain/src/smith/runner_utils.ts
- examples/src/agents/stream_events.ts
- langchain-core/src/runnables/tests/runnable_stream_events.test.ts
About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a π if this is helpful and π if it is irrelevant.
To continue the conversation, mention @dosu.
Thanks for flagging this! Very strange error, it looks like it only happens when calling .stream
or .streamEvents
I'll look into this and push a fix asap!