langchain-ai / langchainjs

πŸ¦œπŸ”— Build context-aware reasoning applications πŸ¦œπŸ”—

Home Page:https://js.langchain.com/docs/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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


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!