Your First Workflow
This tutorial walks you through building a multi-step DAG workflow that extracts data, analyzes it, and produces a report. You will learn how tasks chain together through dependencies.
What We Are Building
A Contract Review Pipeline that:
- Extracts key clauses from a legal contract
- Analyzes risk factors in parallel with compliance checking
- Generates a final executive summary
[Extract Clauses]
|
+---+---+
| |
[Analyze] [Compliance]
| |
+---+---+
|
[Generate Report]Prerequisites
- Completed the Quick Start guide
- A configured
DevTeamClientinstance
Define the Plan
A Plan is a DAG (directed acyclic graph) of steps. Each step specifies a prompt, model, and optional dependencies.
import { DevTeamClient } from 'devteam-sdk';
const client = new DevTeamClient({
apiUrl: process.env.DEVTEAM_API_URL,
apiKey: process.env.DEVTEAM_API_KEY,
});
const plan = await client.createPlan({
name: 'contract-review-pipeline',
description: 'Multi-step contract review with risk analysis',
steps: [
{
id: 'extract',
prompt: `Extract all key clauses from the following contract.
Return them as a structured JSON array with fields:
clause_id, title, text, category.`,
model: 'sonnet',
queue: 'default',
},
{
id: 'analyze-risk',
prompt: `Given the extracted clauses, identify all risk factors.
Rate each risk as LOW, MEDIUM, or HIGH.
Explain the reasoning for each rating.`,
model: 'opus',
dependsOn: ['extract'],
},
{
id: 'check-compliance',
prompt: `Review the extracted clauses for compliance with:
- GDPR data handling requirements
- Standard commercial contract terms
- Industry-specific regulations
Flag any non-compliant clauses.`,
model: 'sonnet',
dependsOn: ['extract'],
},
{
id: 'generate-report',
prompt: `Using the risk analysis and compliance check results,
generate an executive summary report with:
1. Overall risk score (1-10)
2. Top 3 risks with mitigation recommendations
3. Compliance status summary
4. Recommended next steps`,
model: 'sonnet',
dependsOn: ['analyze-risk', 'check-compliance'],
},
],
});
console.log('Plan created:', plan.id);
// Plan created: dt_plan_xyz789Execute the Plan
Pass your input data and execute:
const contractText = `
MASTER SERVICE AGREEMENT
This Agreement is entered into as of February 20, 2026...
Section 3.1 - Data Processing
The Provider shall process personal data in accordance with...
Section 5.2 - Limitation of Liability
In no event shall either party's total liability exceed...
Section 8.4 - Termination
Either party may terminate this Agreement with 30 days written notice...
`;
const execution = await client.executePlan(plan.id, {
input: {
contract: contractText,
},
options: {
timeoutMs: 120_000,
onStepComplete: (step) => {
console.log(`Step ${step.id} completed in ${step.durationMs}ms`);
},
},
});
console.log('Execution ID:', execution.id);Monitor Progress
Track the execution in real time:
// Option 1: Poll for status
const status = await client.getPlanStatus(execution.id);
console.log(status);
// {
// id: 'dt_exec_abc123',
// planId: 'dt_plan_xyz789',
// status: 'running',
// progress: {
// total: 4,
// completed: 2,
// running: 2,
// pending: 0,
// },
// steps: {
// extract: { status: 'completed', durationMs: 3200 },
// 'analyze-risk': { status: 'running', startedAt: '...' },
// 'check-compliance': { status: 'running', startedAt: '...' },
// 'generate-report': { status: 'pending' },
// },
// }
// Option 2: Wait for completion
const result = await client.waitForPlan(execution.id, {
timeoutMs: 120_000,
pollIntervalMs: 2_000,
});Read the Results
Access the output of each step:
// Full result
console.log('Final Report:', result.steps['generate-report'].output);
// Access individual step outputs
const risks = result.steps['analyze-risk'].output;
const compliance = result.steps['check-compliance'].output;
// Token usage across all steps
console.log('Total tokens:', result.usage);
// { input: 1847, output: 2563, totalCost: 0.0234 }Adding Human-in-the-Loop
For high-stakes decisions, add a HITL approval gate:
const execution = await client.executePlan(plan.id, {
input: { contract: contractText },
hitl: {
requiredFor: ['analyze-risk'],
confidenceThreshold: 0.85,
timeoutMs: 3600_000, // 1 hour
notifyChannels: ['email', 'dashboard'],
escalation: {
afterMs: 1800_000, // 30 minutes
to: 'senior-reviewer',
},
},
});When the analyze-risk step completes with confidence below 0.85, execution pauses and waits for human approval. See the HITL Guide for full details.
CLI Equivalent
You can run the same workflow from the command line:
# Create the plan from a YAML file
devteam plan create --file contract-review.yaml
# Execute it
devteam plan run dt_plan_xyz789 \
--input contract=@./contract.txt \
--wait \
--verbose
# Check status
devteam status dt_exec_abc123Plan definitions can be stored as YAML or JSON files and version-controlled alongside your code. See DAG Workflows for the schema reference.
What You Learned
- How to define a multi-step DAG plan with dependencies
- How parallel steps (
analyze-riskandcheck-compliance) run concurrently - How to monitor progress and retrieve results
- How to add human-in-the-loop approval gates
Next Steps
- SDK Reference -- Full API documentation
- DAG Workflow Patterns -- Advanced DAG patterns
- Template System -- Use pre-built workflow templates