Analyze the codebase and automatically add Business-Use SDK instrumentation to track critical business flows.
Analyzes codebase and adds Business-Use SDK instrumentation to track critical business flows.
/plugin marketplace add desplega-ai/ai-toolbox/plugin install base@desplega-ai-toolboxAnalyze the codebase and automatically add Business-Use SDK instrumentation to track critical business flows.
pip install business-use
Initialization:
from business_use import initialize, ensure
# Initialize once at application startup
# Recommended: Use environment variables
# Set BUSINESS_USE_API_KEY and BUSINESS_USE_URL in your environment
initialize() # Automatically uses env vars
# Or with explicit parameters (overrides env vars)
initialize(api_key="your-api-key", url="http://localhost:13370")
# Track events with ensure()
ensure(
id="event_name",
flow="flow_name",
run_id="run_id",
data={"key": "value"},
dep_ids=["upstream_event"], # Optional
validator=lambda data, ctx: True # Optional, for assertions
)
Environment Variables (Recommended):
export BUSINESS_USE_API_KEY="your-api-key"
export BUSINESS_USE_URL="http://localhost:13370" # Optional, defaults to http://localhost:13370
npm i @desplega.ai/business-use
Initialization:
import { initialize, ensure } from '@desplega.ai/business-use';
// Initialize once at application startup
// Recommended: Use environment variables
// Set BUSINESS_USE_API_KEY and BUSINESS_USE_URL in your environment
initialize(); // Automatically uses env vars
// Or with explicit parameters (overrides env vars)
initialize({ apiKey: 'your-api-key', url: 'http://localhost:13370' });
// Track events with ensure()
ensure({
id: 'event_name',
flow: 'flow_name',
runId: 'run_id',
data: { key: 'value' },
depIds: ['upstream_event'], // Optional
validator: (data, ctx) => true // Optional, for assertions
});
Environment Variables (Recommended):
export BUSINESS_USE_API_KEY="your-api-key"
export BUSINESS_USE_URL="http://localhost:13370" # Optional, defaults to http://localhost:13370
You will analyze this codebase to identify business flows that would benefit from tracking and validation. Then you'll propose where to add Business-Use instrumentation.
First, ask the user:
Wait for the user to provide this context before proceeding.
Once you understand the business context, search for:
Look for:
services/, domain/, business/, use-cases/ directoriesIdentify functions that:
Find where:
For each identified flow, present it as:
Example:
Flow: user_journey_name
------------------------------------------------------------
[○] step_initiated
│
↓ (depends on: step_initiated)
[○] intermediate_action
│
↓ (depends on: intermediate_action)
[✓] validation_point (validator: business_rule_here)
│
↓ (depends on: validation_point)
[○] flow_completed
------------------------------------------------------------
Ask the user:
For each function you want to instrument, show:
def critical_business_operation(id: str, data: dict):
# Existing business logic
result = some_operation(data)
if result.is_valid:
update_state(id, result)
return result
from business_use import ensure
def critical_business_operation(id: str, data: dict):
# Existing business logic
result = some_operation(data)
# Track with Business-Use
ensure(
id="operation_completed",
flow="business_flow_name",
run_id=id,
data={
"result": result.to_dict(),
"is_valid": result.is_valid
},
dep_ids=["previous_step"], # If there's a dependency
validator=lambda data, ctx: data["is_valid"] == True, # If validation needed
description="Critical operation completed and validated"
)
if result.is_valid:
update_state(id, result)
return result
Ask the user:
Provide:
SDK Installation (reference the installation commands at the top of this file)
Initialization code with recommended location in codebase
main.py, app.py, or application entry pointindex.ts, main.ts, or app initialization fileBackend Setup (required - runs as separate service):
# Option 1: With uvx (no install required - recommended)
uvx business-use-core init # Interactive setup (generates API key, creates config, initializes DB)
uvx business-use-core serve # Start backend server
# Option 2: Install globally (cleaner commands)
pip install business-use-core
business-use init # Interactive setup
business-use serve # Start backend server (or `business-use prod` for production)
Note: The backend runs as a separate service that your application sends events to. It is NOT part of your application code.
List of files to modify with specific instrumentation points
Testing instructions using the validation commands
Ask the user:
You: "I've analyzed the codebase and found several potential business flows. Before I propose instrumentation, can you help me understand:
This will help me prioritize which flows to instrument first."
User: [Provides context]
You: "Thanks! Based on your input, I've identified these flows:
src/services/flow.py - [brief description]src/services/other.py - [brief description]Here's the proposed structure for Flow 1: [Show flow diagram]
Does this match your understanding? Should I add validators for [specific business rule]?"
User: [Confirms or provides feedback]
You: "Great! Here's how I'll instrument this flow: [Show before/after code]
Shall I proceed with implementing this across the codebase?"
After instrumentation, show users how to validate:
With uvx (no install required - recommended):
# Evaluate a specific flow run
uvx business-use-core eval-run <run_id> <flow_name> --verbose
# Visualize the flow structure with actual event data
uvx business-use-core eval-run <run_id> <flow_name> --show-graph
# Combine graph + verbose for complete picture
uvx business-use-core eval-run <run_id> <flow_name> -g -v
# Get JSON output for automation/CI pipelines
uvx business-use-core eval-run <run_id> <flow_name> --json-output
# View the flow definition (without evaluation)
uvx business-use-core show-graph <flow_name>
# List all runs for a specific flow
uvx business-use-core runs --flow <flow_name>
After global installation (shorter commands):
# Install backend globally
pip install business-use-core
# Now use the shorter command everywhere
business-use eval-run <run_id> <flow_name> --verbose
business-use eval-run <run_id> <flow_name> --show-graph
business-use show-graph <flow_name>
business-use runs --flow <flow_name>
Backend Setup Commands:
# First-time setup (interactive - recommended)
uvx business-use-core init # Generates API key, creates config, initializes DB
# OR if installed globally:
business-use init
# Start development server (with auto-reload)
uvx business-use-core serve --reload
# OR:
business-use serve --reload
# Start production server (4 workers)
uvx business-use-core prod
# OR:
business-use prod
Throughout the process, ask:
Ready! Please provide:
Then I'll analyze the codebase and propose instrumentation.