Skip to content

Flow Mapping

Flow Mapping automatically builds an interactive topology of your AI system, showing how components connect, where costs accumulate, and where to optimize.

What is Flow Mapping?

When you instrument your AI workloads with the Ladger SDK, the platform automatically:

  1. Traces relationships between spans (parent-child)
  2. Groups spans by flow name
  3. Builds a visual map of your AI pipeline
  4. Highlights cost hotspots with color intensity

Dashboard Visualization

The Flow Map in the Ladger dashboard provides:

┌────────────────────────────────────────────────────────────────┐
│ FLOW MAP │
├────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────┐ │
│ │ Intake │ │
│ │ $0.02/req │ │
│ └──────┬──────┘ │
│ │ │
│ ▼ │
│ ┌─────────────┐ ┌─────────────┐ │
│ │ Classify │─────►│ Router │ │
│ │ $0.01/req │ │ $0.00/req │ │
│ └─────────────┘ └──────┬──────┘ │
│ │ │
│ ┌──────────┼──────────┐ │
│ ▼ ▼ ▼ │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ Answer │ │ Summarize│ │ Search │ │
│ │ $0.15/req│ │ $0.05/req│ │ $0.08/req│ │
│ └──────────┘ └──────────┘ └──────────┘ │
│ │
│ Legend: █ High Cost ▓ Medium Cost ░ Low Cost │
│ │
└────────────────────────────────────────────────────────────────┘

Creating Flows

Flows are defined by the flowName in your tracer configuration:

const tracer = new LadgerTracer({
apiKey: process.env.LADGER_API_KEY!,
flowName: 'customer-support-agent', // This creates/uses the flow
});

All spans created by this tracer are automatically grouped under the flow.

Flow Naming Best Practices

PatternExampleUse Case
feature-agentsupport-agentSingle-purpose agent
service-actionapi-chatService endpoints
pipeline-namerag-pipelineMulti-step pipelines
environment-featureprod-classifierEnvironment-specific
// Good flow names
'customer-support-agent'
'document-qa-pipeline'
'content-generator'
'intent-classifier'
// Avoid generic names
'main'
'default'
'test'

Trace Hierarchies

Create meaningful trace hierarchies using nested spans:

async function handleSupport(query: string) {
// Root span for the entire operation
return tracer.trace('handle-support-request', async (rootSpan) => {
// Child: Intent classification
const intent = await tracer.trace('classify-intent', async (span) => {
span.setAttributes({ 'query.length': query.length });
const result = await classifyIntent(query);
span.recordCost({ provider: 'openai', model: 'gpt-4o-mini', ... });
return result;
}, { parent: rootSpan });
// Child: Route and respond
const response = await tracer.trace('generate-response', async (span) => {
span.setAttributes({ intent });
const result = await generateResponse(query, intent);
span.recordCost({ provider: 'openai', model: 'gpt-4o', ... });
return result;
}, { parent: rootSpan });
return response;
});
}

This creates a trace tree:

handle-support-request
├── classify-intent
└── generate-response

Flow Metrics

Each flow tracks:

MetricDescription
Total CostSum of all costs in the flow
Request CountNumber of sessions/requests
Avg Cost/RequestTotal cost ÷ request count
Avg LatencyMean end-to-end time
P95 Latency95th percentile latency
Error RatePercentage of failed spans

Identifying Hotspots

The flow map uses color intensity to highlight expensive components:

  • Red/Orange: High cost (more than 50% of flow cost)
  • Yellow: Medium cost (20-50%)
  • Green: Low cost (less than 20%)

Multi-Model Flows

For flows using multiple models, the map shows model usage:

// First call: fast classification
await tracer.trace('classify', async (span) => {
span.recordCost({ model: 'gpt-4o-mini', ... });
}, { parent: rootSpan });
// Second call: detailed response
await tracer.trace('respond', async (span) => {
span.recordCost({ model: 'gpt-4o', ... });
}, { parent: rootSpan });

Dashboard shows:

  • classify → GPT-4o-mini (low cost)
  • respond → GPT-4o (high cost)

Comparing Flows

Compare flow performance over time:

FlowLast 7 DaysPrevious 7 DaysChange
support-agent$234.50$289.20-19% ✓
content-gen$156.80$142.30+10% ↑
qa-pipeline$89.20$91.50-3% ✓

Exporting Flow Data

Export flow data for external analysis:

  1. Navigate to Flows in the dashboard
  2. Select a flow
  3. Click Export → Choose format (JSON, CSV)

Next Steps