Skip to content

Commit 85c7fc0

Browse files
committed
feat: canonical loop definitions — Prompt 6
Signed-off-by: Todd Palmer <todd@betterdata.co>
1 parent 29c32b7 commit 85c7fc0

7 files changed

Lines changed: 583 additions & 1 deletion

File tree

loops/crm/lead-qualification.yaml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
id: crm.lead_qualification
2+
version: 1.0.0
3+
domain: crm
4+
description: >
5+
Lead qualification from creation through SQL conversion.
6+
Tracks ICP assessment, outreach, and handoff to sales.
7+
8+
states:
9+
- id: CREATED
10+
- id: ICP_ASSESSED
11+
- id: OUTREACH_SENT
12+
- id: MEETING_SCHEDULED
13+
- id: QUALIFIED
14+
isTerminal: true
15+
- id: DISQUALIFIED
16+
isTerminal: true
17+
18+
initialState: CREATED
19+
20+
transitions:
21+
- id: assess_icp
22+
from: CREATED
23+
to: ICP_ASSESSED
24+
allowedActors: [human, automation, ai-agent]
25+
26+
- id: send_outreach
27+
from: ICP_ASSESSED
28+
to: OUTREACH_SENT
29+
allowedActors: [human, automation, ai-agent]
30+
31+
- id: schedule_meeting
32+
from: OUTREACH_SENT
33+
to: MEETING_SCHEDULED
34+
allowedActors: [human, webhook]
35+
36+
- id: qualify
37+
from: MEETING_SCHEDULED
38+
to: QUALIFIED
39+
allowedActors: [human]
40+
41+
- id: disqualify_from_created
42+
from: CREATED
43+
to: DISQUALIFIED
44+
allowedActors: [human]
45+
46+
- id: disqualify_from_icp
47+
from: ICP_ASSESSED
48+
to: DISQUALIFIED
49+
allowedActors: [human]
50+
51+
- id: disqualify_from_outreach
52+
from: OUTREACH_SENT
53+
to: DISQUALIFIED
54+
allowedActors: [human]
55+
56+
- id: disqualify_from_meeting
57+
from: MEETING_SCHEDULED
58+
to: DISQUALIFIED
59+
allowedActors: [human]
60+
61+
outcome:
62+
id: lead_qualified
63+
description: Lead converted to SQL and handed to sales
64+
valueUnit: lead_qualified
65+
measurable: true
66+
businessMetrics:
67+
- id: qualification_cycle_time
68+
label: Lead qualification cycle time (days)
69+
unit: days
70+
improvableByAI: true
71+
- id: outreach_to_meeting_rate
72+
label: Outreach to meeting conversion rate
73+
unit: percentage
74+
improvableByAI: true

loops/erp/purchase-approval.yaml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
id: erp.purchase_approval
2+
version: 1.0.0
3+
domain: erp
4+
description: >
5+
Purchase approval workflow from request through approval, rejection, or cancellation.
6+
Supports policy guards for permissions and duplicate request checks.
7+
8+
states:
9+
- id: REQUESTED
10+
- id: UNDER_REVIEW
11+
- id: APPROVED
12+
isTerminal: true
13+
- id: REJECTED
14+
isTerminal: true
15+
- id: CANCELLED
16+
isTerminal: true
17+
18+
initialState: REQUESTED
19+
20+
transitions:
21+
- id: submit_for_review
22+
from: REQUESTED
23+
to: UNDER_REVIEW
24+
allowedActors: [human, automation]
25+
guards:
26+
- id: duplicate_check_passed
27+
severity: hard
28+
evaluatedBy: runtime
29+
description: Duplicate purchase request check
30+
failureMessage: Duplicate purchase request detected
31+
32+
- id: approve
33+
from: UNDER_REVIEW
34+
to: APPROVED
35+
allowedActors: [human]
36+
guards:
37+
- id: actor_has_permission
38+
severity: hard
39+
evaluatedBy: runtime
40+
description: Approver must have purchase approval permission
41+
failureMessage: Approver lacks required permission
42+
43+
- id: reject
44+
from: UNDER_REVIEW
45+
to: REJECTED
46+
allowedActors: [human]
47+
48+
- id: cancel
49+
from: REQUESTED
50+
to: CANCELLED
51+
allowedActors: [human]
52+
53+
outcome:
54+
id: purchase_approved
55+
description: Purchase request processed to approved, rejected, or cancelled state
56+
valueUnit: purchase_approved
57+
measurable: true
58+
businessMetrics:
59+
- id: approval_turnaround_days
60+
label: Approval turnaround time in days
61+
unit: days
62+
improvableByAI: true
63+
- id: auto_approval_rate
64+
label: Automation-assisted approval rate
65+
unit: percentage
66+
improvableByAI: true
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
id: finance.invoice_collection
2+
version: 1.0.0
3+
domain: finance
4+
description: >
5+
Invoice collection process from issuance through collection or write-off.
6+
Tracks reminders, overdue handling, and escalation outcomes.
7+
8+
states:
9+
- id: INVOICE_CREATED
10+
- id: PAYMENT_REQUESTED
11+
- id: OVERDUE
12+
- id: ESCALATED
13+
- id: COLLECTED
14+
isTerminal: true
15+
- id: WRITTEN_OFF
16+
isTerminal: true
17+
isError: true
18+
19+
initialState: INVOICE_CREATED
20+
21+
transitions:
22+
- id: request_payment
23+
from: INVOICE_CREATED
24+
to: PAYMENT_REQUESTED
25+
allowedActors: [automation, human]
26+
27+
- id: mark_overdue
28+
from: PAYMENT_REQUESTED
29+
to: OVERDUE
30+
allowedActors: [automation, system]
31+
guards:
32+
- id: deadline_not_exceeded
33+
severity: soft
34+
evaluatedBy: external
35+
description: Grace window should be respected before marking overdue
36+
failureMessage: Grace window not yet exceeded
37+
38+
- id: escalate_overdue
39+
from: OVERDUE
40+
to: ESCALATED
41+
allowedActors: [automation, human]
42+
guards:
43+
- id: actor_has_permission
44+
severity: hard
45+
evaluatedBy: runtime
46+
description: Escalation requires finance collections permission
47+
failureMessage: Missing escalation permission
48+
49+
- id: collect_from_overdue
50+
from: OVERDUE
51+
to: COLLECTED
52+
allowedActors: [human, automation]
53+
54+
- id: collect_from_escalated
55+
from: ESCALATED
56+
to: COLLECTED
57+
allowedActors: [human]
58+
59+
- id: write_off
60+
from: ESCALATED
61+
to: WRITTEN_OFF
62+
allowedActors: [human]
63+
guards:
64+
- id: approval_obtained
65+
severity: hard
66+
evaluatedBy: external
67+
description: Write-off requires explicit approval
68+
failureMessage: Write-off approval missing
69+
70+
outcome:
71+
id: invoice_collected
72+
description: Invoice either collected or closed via approved write-off
73+
valueUnit: invoice_collected
74+
measurable: true
75+
businessMetrics:
76+
- id: collection_cycle_time_days
77+
label: Collection cycle time in days
78+
unit: days
79+
improvableByAI: true
80+
- id: writeoff_rate
81+
label: Write-off rate
82+
unit: percentage
83+
improvableByAI: true

loops/scm/procurement.yaml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
id: scm.procurement
2+
version: 1.0.0
3+
domain: scm
4+
description: >
5+
Purchase order lifecycle from requisition through receipt and settlement.
6+
Tracks approval, supplier confirmation, receipt scheduling, and 3-way match.
7+
8+
states:
9+
- id: OPEN
10+
- id: PO_CONFIRMED
11+
- id: RECEIPT_SCHEDULED
12+
- id: RECEIVED
13+
- id: INVOICE_MATCHED
14+
- id: SETTLED
15+
isTerminal: true
16+
- id: CANCELLED
17+
isTerminal: true
18+
isError: false
19+
- id: DISPUTED
20+
isError: true
21+
22+
initialState: OPEN
23+
24+
transitions:
25+
- id: confirm_po
26+
from: OPEN
27+
to: PO_CONFIRMED
28+
allowedActors: [human, automation, ai-agent]
29+
guards:
30+
- id: approval_obtained
31+
severity: hard
32+
evaluatedBy: external
33+
description: PO must be approved before confirmation
34+
failureMessage: PO confirmation requires explicit approval
35+
- id: actor_has_permission
36+
severity: hard
37+
evaluatedBy: runtime
38+
description: Actor must have purchase-order confirm permission
39+
failureMessage: Insufficient permissions to confirm PO
40+
41+
- id: schedule_receipt
42+
from: PO_CONFIRMED
43+
to: RECEIPT_SCHEDULED
44+
allowedActors: [human, automation]
45+
guards:
46+
- id: deadline_not_exceeded
47+
severity: soft
48+
evaluatedBy: external
49+
description: Supplier delivery deadline check
50+
failureMessage: Delivery deadline approaching or exceeded
51+
52+
- id: receive_goods
53+
from: RECEIPT_SCHEDULED
54+
to: RECEIVED
55+
allowedActors: [human]
56+
57+
- id: match_invoice
58+
from: RECEIVED
59+
to: INVOICE_MATCHED
60+
allowedActors: [human, automation, ai-agent]
61+
guards:
62+
- id: approval_obtained
63+
severity: hard
64+
evaluatedBy: external
65+
description: Three-way match must be confirmed
66+
failureMessage: Invoice match requires 3-way match confirmation
67+
68+
- id: settle
69+
from: INVOICE_MATCHED
70+
to: SETTLED
71+
allowedActors: [automation, system]
72+
73+
- id: cancel
74+
from: OPEN
75+
to: CANCELLED
76+
allowedActors: [human]
77+
78+
- id: dispute_from_received
79+
from: RECEIVED
80+
to: DISPUTED
81+
allowedActors: [human]
82+
83+
- id: dispute_from_invoice_matched
84+
from: INVOICE_MATCHED
85+
to: DISPUTED
86+
allowedActors: [human]
87+
88+
outcome:
89+
id: po_settled
90+
description: Purchase order fully settled with matched invoice and inventory updated
91+
valueUnit: po_settled
92+
measurable: true
93+
businessMetrics:
94+
- id: cycle_time_days
95+
label: PO cycle time (days)
96+
unit: days
97+
improvableByAI: true
98+
- id: three_way_match_first_attempt
99+
label: 3-way match on first attempt
100+
unit: boolean
101+
improvableByAI: false
102+
- id: supplier_lead_time_accuracy
103+
label: Supplier lead time accuracy
104+
unit: percentage
105+
improvableByAI: true
106+
107+
spawnableLoops:
108+
- scm.replenishment

loops/scm/replenishment.yaml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
id: scm.replenishment
2+
version: 1.0.0
3+
domain: scm
4+
description: >
5+
Stock replenishment loop from low-stock signal through PO creation.
6+
Closes when replenishment is confirmed and a procurement loop is spawned.
7+
8+
states:
9+
- id: SIGNAL_RECEIVED
10+
- id: THRESHOLD_ASSESSED
11+
- id: REPLENISHMENT_RECOMMENDED
12+
- id: PO_TRIGGERED
13+
isTerminal: true
14+
- id: DISMISSED
15+
isTerminal: true
16+
17+
initialState: SIGNAL_RECEIVED
18+
19+
transitions:
20+
- id: assess_threshold
21+
from: SIGNAL_RECEIVED
22+
to: THRESHOLD_ASSESSED
23+
allowedActors: [system, automation]
24+
25+
- id: recommend_replenishment
26+
from: THRESHOLD_ASSESSED
27+
to: REPLENISHMENT_RECOMMENDED
28+
allowedActors: [system, automation, ai-agent]
29+
30+
- id: trigger_po
31+
from: REPLENISHMENT_RECOMMENDED
32+
to: PO_TRIGGERED
33+
allowedActors: [human, automation, ai-agent]
34+
guards:
35+
- id: approval_obtained
36+
severity: hard
37+
evaluatedBy: external
38+
description: Replenishment must be approved before PO creation
39+
failureMessage: PO trigger requires approval
40+
41+
- id: dismiss
42+
from: REPLENISHMENT_RECOMMENDED
43+
to: DISMISSED
44+
allowedActors: [human]
45+
46+
outcome:
47+
id: replenishment_triggered
48+
description: Replenishment PO created and scm.procurement loop spawned
49+
valueUnit: replenishment_completed
50+
measurable: true
51+
businessMetrics:
52+
- id: signal_to_po_minutes
53+
label: Time from signal to PO trigger (minutes)
54+
unit: days
55+
improvableByAI: true
56+
- id: stockout_prevented
57+
label: Stockout prevented
58+
unit: boolean
59+
improvableByAI: true
60+
61+
spawnableLoops:
62+
- scm.procurement

0 commit comments

Comments
 (0)