Live Salesforce Training & Pre-Recorded Videos Available | Admin • Development • LWC • Agentforce • Data 360 • Integration • Job-Ready Sessions | Contact us for more info +91 - 709 7777 111
Welcome to SfdcIndia

Agent Script

Gallery Feature

Agentforce Agent Script

Agentforce – Agent Script

Agent Script is used to define how an Agentforce agent behaves, responds, executes actions, and follows business logic.


1. What is Agent Script?

  • • Agent Script is the language used to build agents in Agentforce Builder.
  • • It defines how an Agentforce agent should behave.
  • • It controls agent instructions, logic, actions, variables, and responses.
  • • It works like a blueprint for an Agentforce agent.
  • • It supports both natural language instructions and rule-based logic.
Example: Agent Script can tell a service agent how to check case details, call actions, and reply to the customer.

Note: Think of Agent Script as the instruction file that controls the agent behavior.


2. Why Salesforce Introduced Agent Script?

  • • To make Agentforce agents more reliable.
  • • To reduce unpredictable AI behavior.
  • • To give more control over agent actions.
  • • To separate AI reasoning from fixed business rules.
  • • To support step-by-step business processes.
  • • To improve testing, versioning, and deployment.
  • • To help developers build agents using code-based tools.
Example: Instead of allowing AI to decide everything freely, Agent Script can force the agent to follow a fixed support process.

Note: Salesforce introduced Agent Script to make agents more controlled, reliable, and enterprise-ready.


3. When Salesforce Introduced Agent Script?

  • • Agent Script became important with the new Agentforce Builder.
  • • Salesforce highlighted it around February-March 2026.
  • • It is part of the next-generation Agentforce architecture.
  • • It is mainly used for building reliable and controlled AI agents.
Example: New Agentforce Builder supports Canvas View for low-code users and Script View for pro-code users.

Note: Agent Script is part of the new Agentforce development approach.


4. Where Agent Script is Used?

  • • Agentforce Builder
  • • Script View
  • • VS Code
  • • Salesforce DX projects
  • • AiAuthoringBundle
  • • .agent files
Example: Developers can edit the .agent file in VS Code and validate the agent before publishing.

Note: Agent Script is useful for both Agentforce Builder and Salesforce development tools.


5. Agent Script Setup

  • • Go to Setup → Quick Find: Agentforce Agents → Ensure Agentforce is toggled On.
  • • Open Agentforce Studio from App Launcher.
  • • Click New Agent or open an existing agent.
  • • Use Canvas View for low-code UI blocks.
  • • Switch to Script View to write or inspect Agent Script.
  • • Validate the script.
  • • Preview and test the agent.
  • • Publish the agent.
  • • Activate the agent.
Example: First create the agent in Agentforce Studio, then switch from Canvas View to Script View to review the generated Agent Script.

Note: Always validate and preview before publishing the agent.


6. Real-Time Uses of Agent Script

  • • Customer support agents.
  • • Case resolution.
  • • Order status checking.
  • • Refund or replacement process.
  • • Appointment booking.
  • • Lead qualification.
  • • Sales follow-up.
  • • Customer onboarding.
  • • HR helpdesk agents.
  • • IT support agents.
  • • Flow, Apex, and API-based agent actions.
Example: Customer asks order status → Agent checks order details → Gives response → Escalates if needed.

Note: Agent Script is best for controlled, step-by-step business processes.


7. Agent Script Syntax Guardrails

  • • Use proper indentation.
  • • Add colon : after block names and property names.
  • • Use -> for logic-based instructions.
  • • Use | for prompt or natural language instructions.
  • • Use @ to reference variables, actions, subagents, and outputs.
  • • Use {! } when inserting variables inside prompt text.
  • • Declare variables in the variables block before using them.
  • • Use run to execute an action.
  • • Use with to pass input values to an action.
  • • Use set to store action output into a variable.
  • • Use if / else for conditional logic.
  • • Use # for comments.
  • • Use subagent instead of old topic terminology.
  • • Validate the .agent file after every major change.
  • • Do not hard-code sensitive data inside Agent Script.
Example: Use {!@variables.customerName} when inserting a variable inside prompt text.

Note: Most syntax errors happen because of wrong indentation, missing colons, undeclared variables, or wrong references.


8. Common Agent Script Errors

  • • Wrong indentation.
  • • Missing colon : after block name.
  • • Extra colon in the wrong place.
  • • Using wrong block name.
  • • Using old topic instead of subagent.
  • • Referencing a variable without declaring it.
  • • Missing action input.
  • • Wrong output reference.
  • • Invalid if / else condition.
  • • Using = instead of ==.
  • • Unsupported expression.
  • • Missing required config.
Example: Writing config instead of config: can cause a validation error.

Note: Validate frequently while editing Agent Script.


9. Key Takeaway

  • • Agent Script is important for advanced Agentforce development.
  • • It helps build reliable, controlled, and business-ready AI agents.
  • • It gives structure to agent instructions, logic, actions, and responses.
Example: Prompt Builder creates AI prompts, but Agent Script controls the full agent behavior.

Note: Agent Script is like the control center of an Agentforce agent.


For More Details

Video: Agentforce Session Watch here
Website: www.sfdcindia.com