Skip to content

Commit 4c01611

Browse files
authored
feat: add advanced reasoning to main
* feat: add advanced reasoning to main * add objects to delete script * make arrows consistent
1 parent 28506b0 commit 4c01611

26 files changed

+228
-94
lines changed

bin/delete-data.apex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ delete [SELECT Id FROM ASR_Shopping_Cart__c];
1717
delete [SELECT Id FROM ASR_Survey_Log__c];
1818
delete [SELECT Id FROM ASR_Task__c];
1919
delete [SELECT Id FROM ASR_Transaction_Log__c];
20+
delete [SELECT Id FROM ASR_Order__c];
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"records": [
3+
{
4+
"attributes": {
5+
"type": "Account",
6+
"referenceId": "acc_adv_reasoning"
7+
},
8+
"Name": "Pinnacle Solutions Inc",
9+
"Churn_Risk_Score__c": 0.5,
10+
"Contacts": {
11+
"records": [
12+
{
13+
"attributes": {
14+
"type": "Contact",
15+
"referenceId": "con_adv_reasoning"
16+
},
17+
"FirstName": "Sarah",
18+
"LastName": "Mitchell",
19+
"User_ID__c": "USER-12345",
20+
"Loyalty_Status__c": "Gold",
21+
"Lifetime_Value__c": 1500.0
22+
}
23+
]
24+
}
25+
}
26+
]
27+
}

data/advanced-reasoning-case.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"records": [
3+
{
4+
"attributes": {
5+
"type": "Case",
6+
"referenceId": "case_adv1"
7+
},
8+
"Subject": "Unable to access premium features",
9+
"Status": "Open",
10+
"ContactId": "@con_adv_reasoning"
11+
},
12+
{
13+
"attributes": {
14+
"type": "Case",
15+
"referenceId": "case_adv2"
16+
},
17+
"Subject": "Subscription renewal inquiry",
18+
"Status": "Closed",
19+
"ContactId": "@con_adv_reasoning"
20+
}
21+
]
22+
}

data/advanced-reasoning-order.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"records": [
3+
{
4+
"attributes": {
5+
"type": "ASR_Order__c",
6+
"referenceId": "order_adv1"
7+
},
8+
"AccountId__c": "@acc_adv_reasoning",
9+
"TotalAmount__c": 500.0,
10+
"EffectiveDate__c": "2024-12-15"
11+
},
12+
{
13+
"attributes": {
14+
"type": "ASR_Order__c",
15+
"referenceId": "order_adv2"
16+
},
17+
"AccountId__c": "@acc_adv_reasoning",
18+
"TotalAmount__c": 750.0,
19+
"EffectiveDate__c": "2024-11-15"
20+
}
21+
]
22+
}

data/data-plan.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
"resolveRefs": false,
1212
"files": ["commerce-account.json"]
1313
},
14+
{
15+
"sobject": "Account",
16+
"saveRefs": true,
17+
"resolveRefs": false,
18+
"files": ["advanced-reasoning-account.json"]
19+
},
1420
{
1521
"sobject": "ASR_Product__c",
1622
"saveRefs": true,
@@ -83,6 +89,18 @@
8389
"resolveRefs": false,
8490
"files": ["service-case.json"]
8591
},
92+
{
93+
"sobject": "ASR_Order__c",
94+
"saveRefs": true,
95+
"resolveRefs": true,
96+
"files": ["advanced-reasoning-order.json"]
97+
},
98+
{
99+
"sobject": "Case",
100+
"saveRefs": true,
101+
"resolveRefs": true,
102+
"files": ["advanced-reasoning-case.json"]
103+
},
86104
{
87105
"sobject": "ASR_Agent_Event_Log__c",
88106
"saveRefs": false,

force-app/future_recipes/advancedReasoningPatterns/README.md renamed to force-app/main/04_architecturalPatterns/advancedReasoningPatterns/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,9 @@ This lets the LLM extract the user_id from conversation and store it.
320320
### Example: Customer Intelligence
321321

322322
```text
323-
User: Show insights for my customer U001
323+
User: Show insights for my customer USER-12345
324324
325-
[LLM calls set_user_id with user_id="U001"]
325+
[LLM calls set_user_id with user_id="USER-12345"]
326326
327327
[before_reasoning triggers data loading:]
328328
- fetch_user_profile → profile data

force-app/future_recipes/advancedReasoningPatterns/aiAuthoringBundles/AdvancedReasoningPatterns/AdvancedReasoningPatterns.agent renamed to force-app/main/04_architecturalPatterns/advancedReasoningPatterns/aiAuthoringBundles/AdvancedReasoningPatterns/AdvancedReasoningPatterns.agent

Lines changed: 91 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
# AdvancedReasoningPatterns
21
# Demonstrates complex dynamic reasoning with multiple data sources
2+
system:
3+
messages:
4+
welcome: "Welcome! I provide personalized insights based on your complete customer profile."
5+
error: "I had trouble performing the action. Please try again."
6+
instructions: "You are an advanced agent that synthesizes multiple data sources for intelligent recommendations."
37

48
config:
5-
agent_name: "AdvancedReasoningPatterns"
6-
agent_label: "AdvancedReasoningPatterns"
7-
description: "Demonstrates advanced reasoning with dynamic instructions and complex logic"
9+
agent_name: "AdvancedReasoningPatterns"
10+
agent_label: "AdvancedReasoningPatterns"
11+
description: "Demonstrates advanced reasoning with dynamic instructions and complex logic"
812

913
variables:
1014
# User context
@@ -31,12 +35,6 @@ variables:
3135
recommended_actions: mutable object = {}
3236
description: "AI-generated list of recommended next actions for the customer"
3337

34-
system:
35-
messages:
36-
welcome: "Welcome! I provide personalized insights based on your complete customer profile."
37-
error: "I had trouble performing the action. Please try again."
38-
instructions: "You are an advanced agent that synthesizes multiple data sources for intelligent recommendations."
39-
4038
start_agent topic_selector:
4139
description: "Welcome users and begin providing intelligent insights"
4240

@@ -49,6 +47,88 @@ start_agent topic_selector:
4947
topic intelligent_insights:
5048
description: "Provides intelligent insights by synthesizing multiple data sources including your profile, account data, order history, and support tickets. Let me know your customer ID to load your complete customer intelligence dashboard."
5149

50+
before_reasoning:
51+
# Fetch profile if we have user_id
52+
if @variables.user_id!="":
53+
run @actions.fetch_user_profile
54+
55+
set @variables.user_profile = @outputs.profile
56+
# Chain additional data fetches
57+
run @actions.fetch_account_data
58+
59+
set @variables.account_data = @outputs.account
60+
run @actions.fetch_order_history
61+
62+
with limit=10
63+
set @variables.recent_orders = @outputs.orders
64+
run @actions.fetch_support_history
65+
66+
set @variables.support_history = @outputs.tickets
67+
# Compute insights
68+
run @actions.calculate_customer_value
69+
70+
with [email protected]_orders
71+
set @variables.customer_lifetime_value = @outputs.clv
72+
set @variables.loyalty_status = @outputs.loyalty_tier
73+
run @actions.assess_churn_risk
74+
75+
with [email protected]_orders
76+
with [email protected]_history
77+
set @variables.churn_risk_score = @outputs.risk_score
78+
run @actions.generate_recommendations
79+
with [email protected]_profile
80+
with [email protected]_lifetime_value
81+
with [email protected]_risk_score
82+
set @variables.recommended_actions = @outputs.recommendations
83+
84+
reasoning:
85+
# Build dynamic instructions based on loaded data
86+
instructions: ->
87+
| Customer Intelligence Dashboard
88+
89+
if @variables.user_id=="":
90+
| Ask the user for customer ID to view personalized insights. Do not proceed until you have the customer ID.
91+
Use {[email protected]_user_id} to update the user_id variable and set context. Once you have the user Id use {[email protected]_customer_data} to refresh the dashboard.
92+
93+
if @variables.user_id!="" and @variables.user_profile:
94+
| Customer Profile:
95+
if @variables.user_profile:
96+
| Name: {[email protected]_profile.name}
97+
- Loyalty Status: {[email protected]_status}
98+
- Lifetime Value: ${[email protected]_lifetime_value}
99+
else:
100+
| Name: "N/A"
101+
102+
| Account Health:
103+
if @variables.churn_risk_score < 0.3:
104+
| ✅ Low churn risk ({[email protected]_risk_score}%)
105+
if @variables.churn_risk_score >= 0.3 and @variables.churn_risk_score < 0.7:
106+
| ⚠️ Moderate churn risk ({[email protected]_risk_score}%)
107+
if @variables.churn_risk_score >= 0.7:
108+
| 🚨 High churn risk ({[email protected]_risk_score}%)
109+
110+
| Recent Activity:
111+
if @variables.recent_orders:
112+
| Orders (last 30 days):
113+
114+
if @variables.support_history:
115+
| Support Tickets:
116+
117+
118+
if @variables.recommended_actions:
119+
| Recommended Actions:
120+
121+
122+
| What would you like to know more about?
123+
124+
actions:
125+
# Load all data sources before reasoning
126+
load_customer_data: @actions.fetch_user_profile
127+
with user_id=...
128+
129+
set_user_id: @utils.setVariables
130+
description: "Set the user ID to load customer data"
131+
with user_id=...
52132
actions:
53133
fetch_user_profile:
54134
description: "Fetch complete user profile"
@@ -136,85 +216,4 @@ topic intelligent_insights:
136216
description: "List of personalized action recommendations for engaging and retaining the customer"
137217
target: "flow://GenerateRecommendations"
138218

139-
# Load all data sources before reasoning
140-
before_reasoning:
141-
# Fetch profile if we have user_id
142-
if @variables.user_id!="":
143-
run @actions.fetch_user_profile
144-
145-
set @variables.user_profile = @outputs.profile
146-
# Chain additional data fetches
147-
run @actions.fetch_account_data
148-
149-
set @variables.account_data = @outputs.account
150-
run @actions.fetch_order_history
151-
152-
with limit=10
153-
set @variables.recent_orders = @outputs.orders
154-
run @actions.fetch_support_history
155-
156-
set @variables.support_history = @outputs.tickets
157-
# Compute insights
158-
run @actions.calculate_customer_value
159-
160-
with [email protected]_orders
161-
set @variables.customer_lifetime_value = @outputs.clv
162-
set @variables.loyalty_status = @outputs.loyalty_tier
163-
run @actions.assess_churn_risk
164-
165-
with [email protected]_orders
166-
with [email protected]_history
167-
set @variables.churn_risk_score = @outputs.risk_score
168-
run @actions.generate_recommendations
169-
with [email protected]_profile
170-
with [email protected]_lifetime_value
171-
with [email protected]_risk_score
172-
set @variables.recommended_actions = @outputs.recommendations
173-
174-
reasoning:
175-
# Build dynamic instructions based on loaded data
176-
instructions:->
177-
| Customer Intelligence Dashboard
178-
179-
if @variables.user_id=="":
180-
| Ask the user for customer ID to view personalized insights. Do not proceed until you have the customer ID.
181-
Use {[email protected]_user_id} to update the context and {[email protected]_customer_data} to refresh the dashboard.
182-
183-
if @variables.user_id!="" and @variables.user_profile:
184-
| Customer Profile:
185-
if @variables.user_profile:
186-
| Name: {[email protected]_profile.name}
187-
- Loyalty Status: {[email protected]_status}
188-
- Lifetime Value: ${[email protected]_lifetime_value}
189-
else:
190-
| Name: "N/A"
191-
192-
| Account Health:
193-
if @variables.churn_risk_score < 0.3:
194-
| ✅ Low churn risk ({[email protected]_risk_score}%)
195-
if @variables.churn_risk_score >= 0.3 and @variables.churn_risk_score < 0.7:
196-
| ⚠️ Moderate churn risk ({[email protected]_risk_score}%)
197-
if @variables.churn_risk_score >= 0.7:
198-
| 🚨 High churn risk ({[email protected]_risk_score}%)
199-
200-
| Recent Activity:
201-
if @variables.recent_orders:
202-
| Orders (last 30 days):
203-
204-
if @variables.support_history:
205-
| Support Tickets:
206-
207-
208-
if @variables.recommended_actions:
209-
| Recommended Actions:
210-
211-
212-
| What would you like to know more about?
213-
214-
actions:
215-
load_customer_data: @actions.fetch_user_profile
216-
with user_id=...
217-
218-
set_user_id: @utils.setVariables
219-
description: "Set the user ID to load customer data"
220-
with user_id=...
219+

force-app/future_recipes/advancedReasoningPatterns/aiAuthoringBundles/AdvancedReasoningPatterns/AdvancedReasoningPatterns.bundle-meta.xml renamed to force-app/main/04_architecturalPatterns/advancedReasoningPatterns/aiAuthoringBundles/AdvancedReasoningPatterns/AdvancedReasoningPatterns.bundle-meta.xml

File renamed without changes.

force-app/future_recipes/advancedReasoningPatterns/classes/AdvancedReasoningPatternsFlowTest.cls renamed to force-app/main/04_architecturalPatterns/advancedReasoningPatterns/classes/AdvancedReasoningPatternsFlowTest.cls

File renamed without changes.

force-app/future_recipes/advancedReasoningPatterns/classes/AdvancedReasoningPatternsFlowTest.cls-meta.xml renamed to force-app/main/04_architecturalPatterns/advancedReasoningPatterns/classes/AdvancedReasoningPatternsFlowTest.cls-meta.xml

File renamed without changes.

0 commit comments

Comments
 (0)