Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/delete-data.apex
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ delete [SELECT Id FROM ASR_Shopping_Cart__c];
delete [SELECT Id FROM ASR_Survey_Log__c];
delete [SELECT Id FROM ASR_Task__c];
delete [SELECT Id FROM ASR_Transaction_Log__c];
delete [SELECT Id FROM ASR_Order__c];
27 changes: 27 additions & 0 deletions data/advanced-reasoning-account.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"records": [
{
"attributes": {
"type": "Account",
"referenceId": "acc_adv_reasoning"
},
"Name": "Pinnacle Solutions Inc",
"Churn_Risk_Score__c": 0.5,
"Contacts": {
"records": [
{
"attributes": {
"type": "Contact",
"referenceId": "con_adv_reasoning"
},
"FirstName": "Sarah",
"LastName": "Mitchell",
"User_ID__c": "USER-12345",
"Loyalty_Status__c": "Gold",
"Lifetime_Value__c": 1500.0
}
]
}
}
]
}
22 changes: 22 additions & 0 deletions data/advanced-reasoning-case.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"records": [
{
"attributes": {
"type": "Case",
"referenceId": "case_adv1"
},
"Subject": "Unable to access premium features",
"Status": "Open",
"ContactId": "@con_adv_reasoning"
},
{
"attributes": {
"type": "Case",
"referenceId": "case_adv2"
},
"Subject": "Subscription renewal inquiry",
"Status": "Closed",
"ContactId": "@con_adv_reasoning"
}
]
}
22 changes: 22 additions & 0 deletions data/advanced-reasoning-order.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"records": [
{
"attributes": {
"type": "ASR_Order__c",
"referenceId": "order_adv1"
},
"AccountId__c": "@acc_adv_reasoning",
"TotalAmount__c": 500.0,
"EffectiveDate__c": "2024-12-15"
},
{
"attributes": {
"type": "ASR_Order__c",
"referenceId": "order_adv2"
},
"AccountId__c": "@acc_adv_reasoning",
"TotalAmount__c": 750.0,
"EffectiveDate__c": "2024-11-15"
}
]
}
18 changes: 18 additions & 0 deletions data/data-plan.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
"resolveRefs": false,
"files": ["commerce-account.json"]
},
{
"sobject": "Account",
"saveRefs": true,
"resolveRefs": false,
"files": ["advanced-reasoning-account.json"]
},
{
"sobject": "ASR_Product__c",
"saveRefs": true,
Expand Down Expand Up @@ -83,6 +89,18 @@
"resolveRefs": false,
"files": ["service-case.json"]
},
{
"sobject": "ASR_Order__c",
"saveRefs": true,
"resolveRefs": true,
"files": ["advanced-reasoning-order.json"]
},
{
"sobject": "Case",
"saveRefs": true,
"resolveRefs": true,
"files": ["advanced-reasoning-case.json"]
},
{
"sobject": "ASR_Agent_Event_Log__c",
"saveRefs": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,9 @@ This lets the LLM extract the user_id from conversation and store it.
### Example: Customer Intelligence

```text
User: Show insights for my customer U001
User: Show insights for my customer USER-12345

[LLM calls set_user_id with user_id="U001"]
[LLM calls set_user_id with user_id="USER-12345"]

[before_reasoning triggers data loading:]
- fetch_user_profile → profile data
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# AdvancedReasoningPatterns
# Demonstrates complex dynamic reasoning with multiple data sources
system:
messages:
welcome: "Welcome! I provide personalized insights based on your complete customer profile."
error: "I had trouble performing the action. Please try again."
instructions: "You are an advanced agent that synthesizes multiple data sources for intelligent recommendations."

config:
agent_name: "AdvancedReasoningPatterns"
agent_label: "AdvancedReasoningPatterns"
description: "Demonstrates advanced reasoning with dynamic instructions and complex logic"
agent_name: "AdvancedReasoningPatterns"
agent_label: "AdvancedReasoningPatterns"
description: "Demonstrates advanced reasoning with dynamic instructions and complex logic"

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

system:
messages:
welcome: "Welcome! I provide personalized insights based on your complete customer profile."
error: "I had trouble performing the action. Please try again."
instructions: "You are an advanced agent that synthesizes multiple data sources for intelligent recommendations."

start_agent topic_selector:
description: "Welcome users and begin providing intelligent insights"

Expand All @@ -49,6 +47,88 @@ start_agent topic_selector:
topic intelligent_insights:
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."

before_reasoning:
# Fetch profile if we have user_id
if @variables.user_id!="":
run @actions.fetch_user_profile
with user_id=@variables.user_id
set @variables.user_profile = @outputs.profile
# Chain additional data fetches
run @actions.fetch_account_data
with user_id=@variables.user_id
set @variables.account_data = @outputs.account
run @actions.fetch_order_history
with user_id=@variables.user_id
with limit=10
set @variables.recent_orders = @outputs.orders
run @actions.fetch_support_history
with user_id=@variables.user_id
set @variables.support_history = @outputs.tickets
# Compute insights
run @actions.calculate_customer_value
with user_id=@variables.user_id
with orders=@variables.recent_orders
set @variables.customer_lifetime_value = @outputs.clv
set @variables.loyalty_status = @outputs.loyalty_tier
run @actions.assess_churn_risk
with account=@variables.account_data
with orders=@variables.recent_orders
with support_tickets=@variables.support_history
set @variables.churn_risk_score = @outputs.risk_score
run @actions.generate_recommendations
with profile=@variables.user_profile
with clv=@variables.customer_lifetime_value
with churn_risk=@variables.churn_risk_score
set @variables.recommended_actions = @outputs.recommendations

reasoning:
# Build dynamic instructions based on loaded data
instructions: ->
| Customer Intelligence Dashboard

if @variables.user_id=="":
| Ask the user for customer ID to view personalized insights. Do not proceed until you have the customer ID.
Use {!@actions.set_user_id} to update the user_id variable and set context. Once you have the user Id use {!@actions.load_customer_data} to refresh the dashboard.

if @variables.user_id!="" and @variables.user_profile:
| Customer Profile:
if @variables.user_profile:
| Name: {!@variables.user_profile.name}
- Loyalty Status: {!@variables.loyalty_status}
- Lifetime Value: ${!@variables.customer_lifetime_value}
else:
| Name: "N/A"

| Account Health:
if @variables.churn_risk_score < 0.3:
| ✅ Low churn risk ({!@variables.churn_risk_score}%)
if @variables.churn_risk_score >= 0.3 and @variables.churn_risk_score < 0.7:
| ⚠️ Moderate churn risk ({!@variables.churn_risk_score}%)
if @variables.churn_risk_score >= 0.7:
| 🚨 High churn risk ({!@variables.churn_risk_score}%)

| Recent Activity:
if @variables.recent_orders:
| Orders (last 30 days):
{!@variables.recent_orders}
if @variables.support_history:
| Support Tickets:
{!@variables.support_history}

if @variables.recommended_actions:
| Recommended Actions:
{!@variables.recommended_actions}

| What would you like to know more about?

actions:
# Load all data sources before reasoning
load_customer_data: @actions.fetch_user_profile
with user_id=...

set_user_id: @utils.setVariables
description: "Set the user ID to load customer data"
with user_id=...
actions:
fetch_user_profile:
description: "Fetch complete user profile"
Expand Down Expand Up @@ -136,85 +216,4 @@ topic intelligent_insights:
description: "List of personalized action recommendations for engaging and retaining the customer"
target: "flow://GenerateRecommendations"

# Load all data sources before reasoning
before_reasoning:
# Fetch profile if we have user_id
if @variables.user_id!="":
run @actions.fetch_user_profile
with user_id=@variables.user_id
set @variables.user_profile = @outputs.profile
# Chain additional data fetches
run @actions.fetch_account_data
with user_id=@variables.user_id
set @variables.account_data = @outputs.account
run @actions.fetch_order_history
with user_id=@variables.user_id
with limit=10
set @variables.recent_orders = @outputs.orders
run @actions.fetch_support_history
with user_id=@variables.user_id
set @variables.support_history = @outputs.tickets
# Compute insights
run @actions.calculate_customer_value
with user_id=@variables.user_id
with orders=@variables.recent_orders
set @variables.customer_lifetime_value = @outputs.clv
set @variables.loyalty_status = @outputs.loyalty_tier
run @actions.assess_churn_risk
with account=@variables.account_data
with orders=@variables.recent_orders
with support_tickets=@variables.support_history
set @variables.churn_risk_score = @outputs.risk_score
run @actions.generate_recommendations
with profile=@variables.user_profile
with clv=@variables.customer_lifetime_value
with churn_risk=@variables.churn_risk_score
set @variables.recommended_actions = @outputs.recommendations

reasoning:
# Build dynamic instructions based on loaded data
instructions:->
| Customer Intelligence Dashboard

if @variables.user_id=="":
| Ask the user for customer ID to view personalized insights. Do not proceed until you have the customer ID.
Use {!@actions.set_user_id} to update the context and {!@actions.load_customer_data} to refresh the dashboard.

if @variables.user_id!="" and @variables.user_profile:
| Customer Profile:
if @variables.user_profile:
| Name: {!@variables.user_profile.name}
- Loyalty Status: {!@variables.loyalty_status}
- Lifetime Value: ${!@variables.customer_lifetime_value}
else:
| Name: "N/A"

| Account Health:
if @variables.churn_risk_score < 0.3:
| ✅ Low churn risk ({!@variables.churn_risk_score}%)
if @variables.churn_risk_score >= 0.3 and @variables.churn_risk_score < 0.7:
| ⚠️ Moderate churn risk ({!@variables.churn_risk_score}%)
if @variables.churn_risk_score >= 0.7:
| 🚨 High churn risk ({!@variables.churn_risk_score}%)

| Recent Activity:
if @variables.recent_orders:
| Orders (last 30 days):
{!@variables.recent_orders}
if @variables.support_history:
| Support Tickets:
{!@variables.support_history}

if @variables.recommended_actions:
| Recommended Actions:
{!@variables.recommended_actions}

| What would you like to know more about?

actions:
load_customer_data: @actions.fetch_user_profile
with user_id=...

set_user_id: @utils.setVariables
description: "Set the user ID to load customer data"
with user_id=...

Loading