> ## Documentation Index
> Fetch the complete documentation index at: https://braintrust.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Flue

> Trace Flue agent workflows in Braintrust to debug LLM turns, tool calls, subtasks, and context compaction

If you are a coding agent, prefer the Braintrust [`bt` CLI](/reference/cli/quickstart) for repeatable, scriptable work: running evals, instrumenting code, querying logs, syncing data, managing functions, and configuring coding agents. Use the MCP server for reasoning over Braintrust data in conversation, such as ad-hoc lookups and exploration from your IDE.

[Flue](https://flueframework.com/) is an open-source TypeScript agent harness framework. Braintrust traces Flue workflow runs, including LLM turns, tool calls, subtasks, and context compaction.

<View title="TypeScript" icon="https://img.logo.dev/typescriptlang.org?token=pk_BdcHD9e5SCW3j1rnJkNyMQ">
  <h2 id="setup-typescript">
    Setup
  </h2>

  Install Braintrust alongside the Flue runtime, CLI, then set your API keys. Install `@flue/runtime` and `@flue/cli` together so their versions stay aligned.

  <Steps>
    <Step title="Install packages">
      <CodeGroup>
        ```bash pnpm theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
        pnpm add braintrust @flue/runtime @flue/cli
        ```

        ```bash npm theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
        npm install braintrust @flue/runtime @flue/cli
        ```
      </CodeGroup>
    </Step>

    <Step title="Set environment variables">
      ```bash title=".env" theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
      BRAINTRUST_API_KEY=<your-braintrust-api-key>
      ```
    </Step>
  </Steps>

  <h2 id="observer-typescript">
    Register the Braintrust observer
  </h2>

  Initialize Braintrust in your Flue app entry, then pass `braintrustFlueObserver` to Flue's `observe(...)` API. The observer receives Flue runtime events and reports workflow events as traces to Braintrust.

  <Steps>
    <Step title="Configure your Flue project">
      Flue loads its app entry from `src/app.ts`, discovered through a `flue.config.ts` at the project root. Running `flue init --target node` generates this config:

      ```ts title="flue.config.ts" theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
      import { defineConfig } from "@flue/cli/config";

      export default defineConfig({ target: "node" });
      ```
    </Step>

    <Step title="Initialize Braintrust and observe Flue">
      Call `initLogger` and `observe(braintrustFlueObserver)` **at the entrypoint of your application**, so Braintrust is ready before any workflow runs:

      ```ts title="src/app.ts" theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
      import { observe } from "@flue/runtime";
      import { flue } from "@flue/runtime/routing";
      import { braintrustFlueObserver, initLogger } from "braintrust";
      import { Hono } from "hono";

      initLogger({
        projectName: "my-flue-app", // Replace with your project name
        apiKey: process.env.BRAINTRUST_API_KEY,
      });

      observe(braintrustFlueObserver);

      // This example uses Hono, but you could also be deploying Flue using other frameworks
      const app = new Hono();
      app.route("/", flue());

      export default app;
      ```
    </Step>

    <Step title="Run your app">
      Run Flue normally. The app entry subscribes Braintrust to Flue activity.
    </Step>
  </Steps>

  <h2 id="what-traced-typescript">
    What Braintrust traces
  </h2>

  Braintrust captures:

  * Workflow run spans (`workflow:<name>`), with the run input and result.
  * Operation spans (`flue.prompt`, `flue.skill`, and `flue.compact`) for agent operations.
  * LLM turn spans (`llm:<model>`), with messages as input, the model and request parameters as metadata, and the response as output.
  * Tool call spans (`tool:<name>`), with the tool arguments as input and the tool result as output.
  * Subtask spans (`task:<agent>`), with the subtask prompt as input and its result as output.
  * Context compaction spans (`compaction:<reason>`), with message counts before and after compaction.
  * Token usage and cost metrics (prompt, completion, total, cached, cache-creation, and estimated cost) on LLM turns.
  * Errors captured on every span.

  <h2 id="resources-typescript">
    Resources
  </h2>

  * [Flue's Braintrust integration guide](https://flueframework.com/docs/ecosystem/tooling/braintrust/)
  * [Flue's observability guide](https://flueframework.com/docs/guide/observability/#observe-application-activity)
  * [@flue/runtime on npm](https://www.npmjs.com/package/@flue/runtime)
</View>
