Circle V2 API Docs
    Preparing search index...

    Function withTraceCallbacks

    • Bridges the active langsmith traceable run tree into LangChain callbacks.

      LangChain v1 objects (ChatOpenAI, createAgent, RunnableSequence) do NOT reliably inherit the surrounding traceable context on their own, so without this their .invoke() calls open their own top-level traces instead of nesting under the active run. Passing these callbacks into the invoke config attaches each LangChain run to the current span.

      When there is no active run tree (tracing disabled, or called outside a traceable — e.g. unit tests), returns the config untouched. getCurrentRunTree must be checked first because getLangchainCallbacks THROWS rather than no-ops when the run tree is absent.

      The callback resolution is guarded by a timeout so a slow/unreachable LangSmith API never blocks the LLM call — trace nesting degrades gracefully while the underlying work keeps running.

      Type Parameters

      • T extends Record<string, unknown>

      Parameters

      • Optionalconfig: T

      Returns Promise<{ metadata: { [key: string]: unknown } } | { [key: string]: unknown }>