Skip to main content

End-to-End Workflow

This guide shows a generic regulated workflow pattern using the SDKs and API surfaces without requiring provider-specific credentials.

Workflow Overview

End-to-end workflow from SDK instrumentation to replay and human escalation

Capture decision context, persist traces, replay evidence, and escalate uncertain outcomes.

Step 1: Capture a Decision with Python SDK

import briefcase_ai

briefcase_ai.init()

decision = briefcase_ai.DecisionSnapshot("payment_routing")
decision.with_module("risk_orchestrator")
decision.add_input(briefcase_ai.Input("event_id", "evt_123", "string"))
decision.add_input(briefcase_ai.Input("amount", 1250.0, "number"))
decision.add_output(briefcase_ai.Output("route", "approve", "string").with_confidence(0.91))
decision.add_tag("workflow", "payments")
decision.add_tag("region", "us")

db = briefcase_ai.SqliteBackend.in_memory()
decision_id = db.save_decision(decision)
print(decision_id)

Step 2: Attach Versioned Artifact Context

from briefcase_ai import versioned_context

# briefcase_client represents your initialized telemetry/capture client.
with versioned_context(briefcase_client, "example-policy-repo", "main") as lakefs:
policy_blob = lakefs.read_object("policies/payment_routing.json")

Use this pattern when routing logic depends on mutable policy or knowledge artifacts and you need traceable version references.

Step 3: Correlate Multi-Step Workflow Execution

from briefcase_ai import briefcase_workflow

with briefcase_workflow("payment_routing", briefcase_client):
# Step A: feature extraction
# Step B: model score
# Step C: decision route
pass

Correlation preserves workflow identifiers across steps and service boundaries.

Step 4: Consume and Analyze with Node SDK

const briefcase = require("briefcase-node");

briefcase.init();

const decision = new briefcase.SimpleDecisionSnapshot("payment_routing");
decision.addInput(new briefcase.SimpleInput("event_id", "evt_123", "string"));
decision.addOutput(new briefcase.SimpleOutput("route", "approve", "string").withConfidence(0.91));
decision.withExecutionTime(42.0);
decision.addTag("workflow", "payments");

const drift = new briefcase.SimpleDriftCalculator();
const driftMetrics = JSON.parse(drift.calculateDrift(["approve", "approve", "review"]));

const cost = new briefcase.SimpleCostCalculator();
const estimate = JSON.parse(cost.estimateCost("gpt-4", 1600, 220));

console.log(decision.toJson());
console.log(driftMetrics);
console.log(estimate);

Step 5: Retrieve and Replay Evidence via HTTP API

# Fetch a decision trace
curl -s "https://api.example.com/api/v1/decisions/${DECISION_ID}"

# Replay a decision
curl -s -X POST "https://api.example.com/api/v1/replay/${DECISION_ID}" \
-H "Content-Type: application/json" \
-d '{"mode": "strict"}'

Step 6: Route Low-Confidence Outcomes to Human Review

def route_outcome(output):
threshold = 0.88
if output.confidence is None or output.confidence < threshold:
return "manual_review"
return "auto_continue"

Next Steps