Function traceable

  • Higher-order function that takes function as input and returns a "TraceableFunction" - a wrapped version of the input that automatically handles tracing. If the returned traceable function calls any traceable functions, those are automatically traced as well.

    The returned TraceableFunction can accept a run tree or run tree config as its first argument. If omitted, it will default to the caller's run tree, or will be treated as a root run.

    Type Parameters

    • Func extends (...args: any[]) => any

    Parameters

    • wrappedFunc: Func

      Targeted function to be traced

    • Optionalconfig: Partial<RunTreeConfig> & {
          aggregator?: (args: any[]) => any;
          argsConfigPath?: [number] | [number, string];
          extractAttachments?: (
              ...args: Parameters<Func>,
          ) => [undefined | Attachments, KVMap];
          getInvocationParams?: (
              ...args: Parameters<Func>,
          ) => undefined | InvocationParamsSchema;
          processInputs?: (inputs: Readonly<KVMap>) => KVMap;
          processOutputs?: (outputs: Readonly<KVMap>) => KVMap;
      }

      Additional metadata such as name, tags or providing a custom LangSmith client instance

      • Optionalaggregator?: (args: any[]) => any
      • OptionalargsConfigPath?: [number] | [number, string]
      • OptionalextractAttachments?: (...args: Parameters<Func>) => [undefined | Attachments, KVMap]

        Extract attachments from args and return remaining args.

      • OptionalgetInvocationParams?: (...args: Parameters<Func>) => undefined | InvocationParamsSchema

        Extract invocation parameters from the arguments of the traced function. This is useful for LangSmith to properly track common metadata like provider, model name and temperature.

      • OptionalprocessInputs?: (inputs: Readonly<KVMap>) => KVMap

        Apply transformations to the inputs before logging. This function should NOT mutate the inputs. processInputs is not inherited by nested traceable functions.

      • OptionalprocessOutputs?: (outputs: Readonly<KVMap>) => KVMap

        Apply transformations to the outputs before logging. This function should NOT mutate the outputs. processOutputs is not inherited by nested traceable functions.

    Returns TraceableFunction<Func>