langsmith-sdk icon indicating copy to clipboard operation
langsmith-sdk copied to clipboard

Issue: getCurrentRunTree() Method Fails: "Could not get the current run tree"

Open TechWithTy opened this issue 1 year ago • 5 comments

Issue you'd like to raise.

Issue Description Description I am encountering an issue with the getCurrentRunTree method in the langsmith library. The error message indicates that the method cannot get the current run tree and suggests that the method is not being called within a traceable function. Despite following the documentation and ensuring that my function calls are within the traceable context, the error persists.

Error Message less


Error: Could not get the current run tree.
Please make sure you are calling this method within a traceable function.
    at getCurrentRunTree (C:\Users\Dell\Downloads\cyberOni\CyberOni-Bun-Server-Ai\node_modules\langsmith\dist\traceable.js:326:15)
    at C:\Users\Dell\Downloads\cyberOni\CyberOni-Bun-Server-Ai\src\lib\langchain\langsmith.ts:10:17
    at C:\Users\Dell\Downloads\cyberOni\CyberOni-Bun-Server-Ai\node_modules\langsmith\dist\traceable.js:139:31
    at run (node:async_hooks:70:11)
    at C:\Users\Dell\Downloads\cyberOni\CyberOni-Bun-Server-Ai\src\lib\langchain\langsmith.ts:48:26
    at run (C:\Users\Dell\Downloads\cyberOni\CyberOni-Bun-Server-Ai\src\lib\langchain\langsmith.ts:46:19)
    at C:\Users\Dell\Downloads\cyberOni\CyberOni-Bun-Server-Ai\src\lib\langchain\langsmith.ts:58:1

Steps to Reproduce Set up a project with the langsmith library. Implement the following code snippet to trace function calls: javascript


import { Client } from "langsmith";
import { traceable, getCurrentRunTree } from "langsmith/traceable";
import { wrapOpenAI } from "langsmith/wrappers";
import { chatOpenAi } from "./openai";
import { GptPrompt } from "@prisma/client";
import { IterableReadableStream } from "@langchain/core/utils/stream";
import { AIMessageChunk } from "@langchain/core/messages";

const formatPrompt = traceable(
  (subject: string) => {
    const run = getCurrentRunTree();
    console.log("formatPrompt Run ID", run?.id);
    console.log("formatPrompt Trace ID", run?.trace_id);
    console.log("formatPrompt Parent Run ID", run?.parent_run?.id);
    return [
      {
        role: "system",
        content: "You are a helpful assistant.",
      },
      {
        role: "user",
        content: `What's a good name for a store that sells ${subject}?`,
      },
    ];
  },
  { name: "formatPrompt" }
);

const traceableCallOpenAI = traceable(
  async (prompt) => {
    const run = getCurrentRunTree();
    console.log("traceableCallOpenAI Run ID", run?.id);
    const response = await chatOpenAi(prompt, {}, {}, "New_run_id", true, process.env.OPENAI_API_KEY);
    console.log(response);
    return response;
  },
  {
    run_type: "llm",
    name: "OpenAI Call Traceable",
  }
);

const run = traceable(
  async () => {
    const prompt = formatPrompt("reply OK");
    const response = await traceableCallOpenAI(prompt);
    console.log(response);
  },
  { name: "run" }
);

run();

Run the script. Expected Behavior The getCurrentRunTree method should return the current run tree without errors when called within a traceable function.

Actual Behavior The getCurrentRunTree method throws an error stating that it could not get the current run tree.

Environment OS: Windows 10 Node.js Version: 20.~ langsmith Version: x.y.z (Please specify the exact version you're using)

Suggestion:

No response

TechWithTy avatar May 14 '24 15:05 TechWithTy

Hello @TechWithTy! Sorry for the delay. We're only supporting Node.JS 18+, please let us know if the issue is solved by upgrading NodeJS version from 14 to 18.

dqbd avatar Jun 07 '24 17:06 dqbd

We were actually using node 20v Somehting sorry for the typo

TechWithTy avatar Jun 13 '24 14:06 TechWithTy

I have the same issue and I am on v18.

guidorietbroek avatar Jun 17 '24 05:06 guidorietbroek

Can we reopen this @dqbd

TechWithTy avatar Jun 19 '24 16:06 TechWithTy

I noticed that it doesn't generate this error inside every function wrapped inside the traceable() function. If I have more debugging information I'll let you know. Both functions had at least a chain consisting of a prompt, model, parser.

guidorietbroek avatar Jun 19 '24 17:06 guidorietbroek

@guidorietbroek Were you able to fix the issue?

TechWithTy avatar Sep 07 '24 17:09 TechWithTy

No sorry.

guidorietbroek avatar Sep 14 '24 04:09 guidorietbroek