afv-library/skills/developing-agentforce/assets/patterns/multi-step-workflow.agent
Willie Ruemmele 261abd679a
chore: rename topic to subagent for Agent Script v2 @W-21955450@ (#193)
* @W-21955450@ Rename topic to subagent for Agent Script v2

Aligns with Agent Script v2 naming standards where `topic` is renamed
to `subagent` across all skill documentation and templates.

Changes:
- Agent Script templates: topic keyword → subagent keyword
- References: @topic.* → @subagent.*
- Documentation: Updated all skill references and guides
- Natural language references preserved in comments/descriptions

* Rename start_agent topic_selector to agent_router

Completes the topic → subagent terminology alignment by:

1. Renaming start_agent from topic_selector to agent_router (15 agent files)
2. Updating template topic declarations: topic {{placeholder}} → subagent {{placeholder}} (5 files)
3. Updating all @subagent.topic_selector references to @subagent.agent_router (35 occurrences)
4. Updating documentation: prose, examples, and diagrams (10 markdown files)
5. Updating comments to use agent_router terminology

Files affected:
- 22 agent template files
- 10 documentation/reference markdown files
- Template component files

The agent_router name is more descriptive of its actual function
(routing to different subagents) and completes the Agent Script v2
terminology standardization.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Rename files with "topic" to use "subagent" terminology

Completes the topic → subagent terminology alignment by renaming
files and updating all references:

**Files renamed (5):**
- multi-topic.agent → multi-subagent.agent
- template-single-topic.agent → template-single-subagent.agent
- template-multi-topic.agent → template-multi-subagent.agent
- topic-with-actions.agent → subagent-with-actions.agent
- agent-topic-map-diagrams.md → agent-subagent-map-diagrams.md

**References updated (6 docs):**
- Updated all filename references to point to new filenames
- Updated "Topic Map" → "Subagent Map" throughout documentation
- Updated "multi-topic"/"single-topic" → "multi-subagent"/"single-subagent"

Files modified:
- README.md, SKILL.md, agent-spec-template.md
- assets/agents/README.md, assets/README-legacy.md
- references/agent-design-and-spec-creation.md

This ensures consistent "subagent" terminology across filenames,
file content, and all documentation references.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Complete topic-to-subagent terminology update across skills

Comprehensive update replacing "topic" with "subagent" terminology throughout
the developing-agentforce and testing-agentforce skills to align with Agent
Script's `subagent` block naming.

Key changes:
- "Topic Selector" → "Subagent Router" in all agent templates and docs
- "Topic/action" → "Subagent/action" in documentation
- "Topic map" → "Subagent map" in diagram references
- Updated all architecture documentation to use "subagent" terminology
- Updated 19 .agent template files with new labels and comments
- Updated 8 reference documentation files with consistent terminology

API contract preservation:
- Test spec YAML files preserve "topic" terminology to match Testing Center API
- Added clarifying comments explaining topic/subagent equivalence in YAML files
- Field names like `expectedTopic` unchanged (Salesforce API requirement)

Preserved terms:
- "off-topic" (standard phrase for out-of-scope)
- "expectedTopic" field (Testing Center API)
- "platform topics" (Salesforce guardrail features)

32 files changed, 379 insertions(+), 366 deletions(-)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Complete comprehensive topic-to-subagent terminology update

Thorough update replacing all remaining "topic" references with "subagent"
terminology across developing-agentforce, testing-agentforce, and
observing-agentforce skills to fully align with Agent Script's `subagent`
block naming.

Key changes:
- Agent Script syntax: @topic.<name> → @subagent.<name>
- Agent Script syntax: topic.actions → subagent.actions
- Shell script patterns: ^topic → ^subagent
- Documentation: "topic instructions" → "subagent instructions"
- observing-agentforce skill: Updated all agent architecture references
- Template files: Updated all inline comments and descriptions
- Variable names in scripts: TOPIC → SUBAGENT

Specific updates:
- 45 files changed, 294 insertions, 294 deletions
- Updated all Agent Script code examples to use @subagent syntax
- Updated observing-agentforce issue classification guide
- Updated shell script patterns in diagnostic tools
- Updated Apex comments to clarify topic field maps to subagents

Preserved (as required):
- "off-topic" and "off_topic" (standard out-of-scope phrase)
- Testing Center API fields: expectedTopic, topic: in YAML
- API response fields: .topic, generatedData.topic, topic_assertion
- STDM field names: ssot__TopicApiName__c (with clarifying docs)
- Template placeholders in test specs (API values)
- "Topic hash drift" (API field behavior)
- "Email topic/purpose" (means email subject)
- Explanatory comments about API field mapping

All Agent Script syntax and documentation now consistently uses "subagent"
while preserving backward compatibility with platform API field names.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* a few more topic -> subagent replacements

---------

Co-authored-by: Steve Hetzel <shetzel@salesforce.com>
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-04-27 12:42:18 -06:00

283 lines
10 KiB
Plaintext

# Multi-Step Workflow Pattern
# Track progress through complex multi-stage processes using boolean flags
#
# ★ When To Use This Pattern:
# - User onboarding with multiple steps
# - Order/checkout processes
# - Application submissions (loan, support case, etc.)
# - Any workflow requiring completion tracking
#
# ★ Key Insights:
# - Use boolean flags to track step completion
# - Use number variable for step counter
# - Conditionally show instructions based on completion state
# - Chain actions with `run` for deterministic sequences
#
# ★ Why This Pattern:
# - Clear visibility into workflow progress
# - Resume interrupted workflows
# - Prevent skipping required steps
# - Show progress indicators to users
#
# This is a COMPLETE template - customize for your use case
#
# ★ Step Guard Pattern (Feb 2026 Community Best Practice):
# - The subagent router re-evaluates on EVERY user utterance
# - Without a step guard, follow-up messages ("my email is X") get re-routed
# - The `if @variables.current_step > 1:` guard in start_agent forces
# re-entry to the current workflow, bypassing LLM subagent selection
# - Reset current_step to 1 when the workflow completes
system:
instructions: "You are an onboarding assistant. Guide users through the account setup process step by step. Ensure all required steps are completed before finishing."
messages:
welcome: "Welcome! I'll help you set up your account. Let's go through this step by step."
error: "I encountered an issue. Let me try to continue from where we left off."
config:
agent_name: "Onboarding_Agent"
default_agent_user: "agent@company.salesforce.com"
agent_label: "Onboarding Assistant"
description: "Guides users through multi-step onboarding workflow"
variables:
# Standard linked variables
EndUserId: linked string
source: @MessagingSession.MessagingEndUserId
description: "Messaging End User ID"
RoutableId: linked string
source: @MessagingSession.Id
description: "Messaging Session ID"
# ★ WORKFLOW PROGRESS TRACKING - Boolean flags for each step
step_1_account_created: mutable boolean = False
description: "Step 1: Account has been created"
step_2_profile_completed: mutable boolean = False
description: "Step 2: Profile information has been collected"
step_3_preferences_set: mutable boolean = False
description: "Step 3: User preferences have been configured"
step_4_verification_done: mutable boolean = False
description: "Step 4: Email/phone verification completed"
onboarding_complete: mutable boolean = False
description: "All onboarding steps are complete"
# ★ STEP COUNTER - For progress indication
current_step: mutable number = 1
description: "Current step number (1-4)"
total_steps: mutable number = 4
description: "Total number of steps"
# Data collected during workflow
customer_id: mutable string = ""
description: "Created customer ID"
user_email: mutable string = ""
description: "User's email address"
user_name: mutable string = ""
description: "User's full name"
phone_number: mutable string = ""
description: "User's phone number"
notification_preference: mutable string = "email"
description: "Preferred notification method"
verification_code: mutable string = ""
description: "Verification code for confirmation"
language:
default_locale: "en_US"
start_agent onboarding:
description: "Multi-step account onboarding workflow"
actions:
# Step 1: Create account
create_account:
description: "Create a new customer account"
inputs:
email: string
description: "Customer email address"
is_required: True
name: string
description: "Customer full name"
is_required: True
outputs:
customer_id: string
description: "Newly created customer ID"
success: boolean
description: "Whether account creation succeeded"
target: "flow://Create_Customer_Account"
# Step 2: Update profile
update_profile:
description: "Update customer profile information"
inputs:
customer_id: string
description: "Customer ID to update"
is_required: True
phone: string
description: "Phone number"
is_required: False
outputs:
success: boolean
description: "Whether profile update succeeded"
target: "flow://Update_Customer_Profile"
# Step 3: Set preferences
set_preferences:
description: "Configure customer notification preferences"
inputs:
customer_id: string
description: "Customer ID"
is_required: True
notification_method: string
description: "Preferred notification method: email, sms, or both"
is_required: True
outputs:
success: boolean
description: "Whether preferences were saved"
target: "flow://Set_Customer_Preferences"
# Step 4: Send verification
send_verification:
description: "Send verification code to customer"
inputs:
customer_id: string
description: "Customer ID"
is_required: True
method: string
description: "Verification method: email or sms"
is_required: True
outputs:
success: boolean
description: "Whether verification was sent"
target: "flow://Send_Verification_Code"
# Verify code
verify_code:
description: "Verify the customer's code"
inputs:
customer_id: string
description: "Customer ID"
is_required: True
code: string
description: "Verification code entered by user"
is_required: True
outputs:
verified: boolean
description: "Whether code was correct"
target: "flow://Verify_Customer_Code"
reasoning:
instructions: ->
# ★ STEP GUARD — Force re-entry if workflow in progress
# This prevents the subagent router from re-routing the user
# mid-workflow when they provide follow-up information
if @variables.current_step > 1:
| Continuing your account setup...
# ★ PROGRESS DISPLAY - Show current status
| Welcome to account setup!
| Progress: Step {!@variables.current_step} of {!@variables.total_steps}
|
# ★ SHOW COMPLETED STEPS
if @variables.step_1_account_created == True:
| ✓ Step 1: Account Created
if @variables.step_1_account_created == False:
| ○ Step 1: Create Account (current)
if @variables.step_2_profile_completed == True:
| ✓ Step 2: Profile Complete
if @variables.step_2_profile_completed == False and @variables.step_1_account_created == True:
| ○ Step 2: Complete Profile (current)
if @variables.step_3_preferences_set == True:
| ✓ Step 3: Preferences Set
if @variables.step_3_preferences_set == False and @variables.step_2_profile_completed == True:
| ○ Step 3: Set Preferences (current)
if @variables.step_4_verification_done == True:
| ✓ Step 4: Verified
if @variables.step_4_verification_done == False and @variables.step_3_preferences_set == True:
| ○ Step 4: Verify Account (current)
|
# ★ STEP-SPECIFIC INSTRUCTIONS
if @variables.step_1_account_created == False:
| Let's start by creating your account.
| I'll need your email address and full name.
if @variables.step_1_account_created == True and @variables.step_2_profile_completed == False:
| Great! Account created. Now let's complete your profile.
| What's your phone number? (optional but recommended)
if @variables.step_2_profile_completed == True and @variables.step_3_preferences_set == False:
| Profile saved. Let's set your notification preferences.
| How would you like to receive notifications: email, sms, or both?
if @variables.step_3_preferences_set == True and @variables.step_4_verification_done == False:
| Almost done! I've sent a verification code.
| Please enter the code you received.
if @variables.onboarding_complete == True:
| 🎉 Congratulations! Your account is fully set up.
| Customer ID: {!@variables.customer_id}
| You're all ready to go!
actions:
# ★ STEP 1: Create Account
# Uses action chaining with `run` for automatic next step
do_step_1: @actions.create_account
with email=...
with name=...
set @variables.customer_id = @outputs.customer_id
set @variables.step_1_account_created = @outputs.success
set @variables.current_step = 2
available when @variables.step_1_account_created == False
# ★ STEP 2: Update Profile
do_step_2: @actions.update_profile
with customer_id=@variables.customer_id
with phone=...
set @variables.step_2_profile_completed = @outputs.success
set @variables.current_step = 3
available when @variables.step_1_account_created == True
available when @variables.step_2_profile_completed == False
# ★ STEP 3: Set Preferences
do_step_3: @actions.set_preferences
with customer_id=@variables.customer_id
with notification_method=...
set @variables.step_3_preferences_set = @outputs.success
set @variables.current_step = 4
# Automatically trigger verification after preferences
run @actions.send_verification
with customer_id=@variables.customer_id
with method=@variables.notification_preference
available when @variables.step_2_profile_completed == True
available when @variables.step_3_preferences_set == False
# ★ STEP 4: Verify
do_step_4: @actions.verify_code
with customer_id=@variables.customer_id
with code=...
set @variables.step_4_verification_done = @outputs.verified
set @variables.onboarding_complete = @outputs.verified
available when @variables.step_3_preferences_set == True
available when @variables.step_4_verification_done == False
# ★ Insight: Multi-Step Workflow Best Practices
#
# BOOLEAN FLAGS:
# - One flag per step for clear completion tracking
# - Use meaningful names: step_1_account_created, not flag1
# - Check flags to enable/disable actions
#
# STEP COUNTER:
# - Provides simple progress indication
# - Can be used in template expressions for display
#
# ACTION AVAILABILITY:
# - Use `available when` to prevent out-of-order execution
# - Multiple `available when` clauses work as AND conditions
#
# ACTION CHAINING:
# - Use `run` for automatic sequential actions
# - Good for: send confirmation after save, log after complete
#
# RESUME CAPABILITY:
# - Boolean flags persist across conversation turns
# - User can pick up where they left off