Workflows

Track complete multi-step operations end-to-end.


You will learn: - How to tag operations with workflow IDs - How to track costs per feature and per customer - Common workflow patterns


Why Workflows

Without workflows, you see disconnected logs:

[13:45:23] gpt-4: $0.15
[13:45:24] claude-opus: $0.25

With workflows, you see the full picture:

research_pipeline - 4.1s, $0.50
  search_agent:    1.2s, $0.15
  analysis_agent:  2.1s, $0.25
  writer_agent:    0.8s, $0.10

Basic Usage

import kalibr
import os

os.environ["KALIBR_WORKFLOW_ID"] = "content_generation"

def generate_content(topic):
    outline = outline_agent(topic)
    draft = writer_agent(outline)
    return editor_agent(draft)

Adding Customer Context

os.environ["KALIBR_WORKFLOW_ID"] = "research_pipeline"
os.environ["KALIBR_TENANT_ID"] = customer_id

Now you can see cost per customer in the dashboard.


With FastAPI

from kalibr import trace
from fastapi import FastAPI
import os

app = FastAPI()

@app.post("/api/research")
@trace(operation="research", provider="openai", model="gpt-4o")
async def research(query: str, customer_id: str):
    os.environ["KALIBR_WORKFLOW_ID"] = "research_pipeline"
    os.environ["KALIBR_TENANT_ID"] = customer_id
    return research_agent(query)

What You See in the Dashboard

By workflow: | Workflow | Calls | Cost | Avg Cost | |----------|-------|------|----------| | research_pipeline | 1,234 | $234.56 | $0.19 | | content_generation | 5,678 | $145.23 | $0.03 |

By customer: | Customer | Spend | Calls | |----------|-------|-------| | acme_corp | $456.78 | 2,345 | | initech | $234.56 | 1,234 |


Best Practices

Do: - Use descriptive names: customer_onboarding, document_analysis - One workflow per business operation - Always set tenant_id for SaaS apps

Don't: - Create workflows for every function - Put PII in workflow names - Use generic names like workflow1


Next Steps

  • Traces — Debug individual executions
  • Monitor — Set up alerts