OpenInference JS
    Preparing search index...
    • Experimental

      Wraps a function with tracing capabilities, specifically marking it as an AGENT span.

      This is a convenience function that wraps withSpan with the OpenInference span kind pre-configured to AGENT. Agent spans represent autonomous decision-making entities in an LLM application, such as AI agents, chat bots, or intelligent assistants that can reason, plan, and execute actions.

      This API is experimental and may change in future versions

      Type Parameters

      • Fn extends AnyFn

        The function type being wrapped, preserving original signature

      Parameters

      • fn: Fn

        The function to wrap with AGENT span tracing

      • Optionaloptions: Omit<SpanTraceOptions<AnyFn>, "kind">

        Configuration options for tracing behavior (excluding kind)

        • tracer

          Custom OpenTelemetry tracer instance (defaults to global tracer)

        • name

          Custom span name (defaults to function name)

        • openTelemetrySpanKind

          OpenTelemetry span kind (defaults to INTERNAL)

        • processInput

          Custom function to process input arguments into attributes

        • processOutput

          Custom function to process output values into attributes

        • attributes

          Base attributes to be added to every span created

      Returns Fn

      A wrapped function with identical signature that creates AGENT spans during execution

      // Trace an AI agent's decision-making process
      const makeDecision = async (context: AgentContext) => {
      const analysis = await analyzeContext(context);
      const plan = await createPlan(analysis);
      return await executePlan(plan);
      };
      const tracedAgent = traceAgent(makeDecision, { name: "decision-agent" });

      // Trace a chatbot response generation
      const generateResponse = (userMessage: string, history: Message[]) => {
      const intent = classifyIntent(userMessage);
      const context = buildContext(history);
      return generateReply(intent, context);
      };
      const tracedChatbot = traceAgent(generateResponse);