@lelemondev/sdk - v0.9.9
    Preparing search index...

    Function trace

    • Execute a function within a trace context. Creates a root "agent" span that contains all LLM calls and tool executions.

      Output Auto-Extraction: If the function returns an object with common text fields (text, content, message, output, response, result, answer), the SDK automatically extracts that field for cleaner display. Use outputKey to specify a custom field, or outputKey: false to disable.

      Type Parameters

      • T

      Parameters

      Returns Promise<T>

      await trace('sales-agent', async () => {
      return { text: 'Hello!', tokens: 100 };
      // Output shown: "Hello!" (auto-extracted from 'text')
      });
      await trace({ name: 'agent', outputKey: 'reply' }, async () => {
      return { reply: 'Hello!', cost: 0.01 };
      // Output shown: "Hello!"
      });
      await trace({ name: 'agent', outputKey: false }, async () => {
      return { a: 1, b: 2 };
      // Output shown: { a: 1, b: 2 }
      });