Generate Salesforce Agent Script YAML from Agentforce planner configurations
npm install @sf-explorer/agentscript-migration-toolGenerate Salesforce Agent Script YAML from Agentforce planner configurations. This tool helps accelerate migration from UI-based Agentforce configurations to code-based AgentScript format.
- ✅ 85% Automated Migration - Generate complete agent scripts automatically
- ✅ Spec Compliant - Follows official Salesforce Agent Script Recipes
- ✅ Type Safe - Full TypeScript support with comprehensive interfaces
- ✅ Zero Dependencies - Only requires js-yaml for YAML generation
- ✅ Framework Agnostic - Works with any data structure matching the planner interface
``bash`
npm install @sf-explorer/agentscript-migration-tool
- Node.js >= 18.x
- TypeScript >= 5.3 (for TypeScript projects)
`typescript
import { generateAgentScript } from '@sf-explorer/agentscript-migration-tool'
import type { PlannerDefinition } from '@sf-explorer/agentscript-migration-tool'
const planner: PlannerDefinition = {
DeveloperName: "my_agent",
MasterLabel: "My Agent",
topics: [/ ... /]
}
const yaml = generateAgentScript(planner)
console.log(yaml)
`
`typescript
import { generateAgentScript } from '@sf-explorer/agentscript-migration-tool'
import type { PlannerDefinition } from '@sf-explorer/agentscript-migration-tool'
// Define your planner data
const planner: PlannerDefinition = {
DeveloperName: "customer_service_agent",
MasterLabel: "Customer Service Agent",
Metadata: {
description: "Assists customers with their service requests"
},
topics: [
{
DeveloperName: "Orders",
MasterLabel: "Orders",
Description: "Handle order-related inquiries",
actions: [
{
DeveloperName: "LookupOrder",
MasterLabel: "Lookup Order",
Description: "Look up order by ID",
InvocationTarget: "GetOrderDetails",
InvocationTargetType: "Flow",
Metadata: {
inputs: {
order_id: "string"
},
outputs: {
order_summary: "string"
}
}
}
]
}
],
variables: [
{
DeveloperName: "customer_verified",
parameterName: "customer_verified",
mappingType: "Boolean",
description: "Whether customer is verified"
}
]
}
// Generate Agent Script YAML
const yaml = generateAgentScript(planner, {
includeComments: true,
includeLanguageConfig: true
})
console.log(yaml)
`
Convenience function to generate Agent Script YAML.
Parameters:
- planner: PlannerDefinition - The planner definition objectoptions?: AgentScriptGenerationOptions
- - Optional generation options
Returns: string - Generated YAML content
Class-based generator for more control.
`typescript
import { AgentScriptGenerator } from '@sf-explorer/agentscript-migration-tool'
const generator = new AgentScriptGenerator(planner, {
includeComments: true,
yamlIndent: 4,
includeLanguageConfig: true
})
const yaml = generator.generate()
`
`typescript`
interface AgentScriptGenerationOptions {
includeComments?: boolean // Add header comments (default: true)
includeExamples?: boolean // Include example code (default: false)
yamlIndent?: number // YAML indentation (default: 4)
generateVariables?: boolean // Generate variables section (default: false)
includeLanguageConfig?: boolean // Include language block (default: true)
}
The tool generates complete Agent Script YAML following Salesforce patterns:
- Config Block: Agent metadata and configuration
- System Block: Global instructions and messages
- Language Block: Locale configuration (optional)
- Variables: State management variables (if provided)
- Start Agent: Topic selector with transitions
- Topics: Individual topics with reasoning and actions
- Actions: External integrations (Flow, Apex, API)
`yamlAgent Script
Generated from GenAI Planner: Customer Service Agent
Developer Name: customer_service_agent
config:
developer_name: "customer_service_agent"
default_agent_user: "agentforce@salesforce.com"
description: "Assists customers with their service requests"
system:
instructions: "You are a helpful assistant..."
messages:
welcome: "Hi, I'm your Customer Service Agent assistant..."
error: "Sorry, something went wrong..."
variables:
customer_verified: mutable boolean
description: "Whether customer is verified"
start_agent topic_selector:
description: "Welcome the user and determine the appropriate topic"
reasoning:
instructions: ->
| You are a topic selector assistant...
actions:
go_to_orders: @utils.transition to @topic.Orders
description: "Handle order-related inquiries"
topic Orders:
description: "Handle order-related inquiries"
reasoning:
instructions: ->
| Handle order-related inquiries.
Available actions:
- Use @actions.LookupOrder to Look up order by ID
actions:
LookupOrder: @actions.LookupOrder
description: "Look up order by ID"
actions:
LookupOrder:
description: "Look up order by ID"
inputs:
order_id: string
outputs:
order_summary: string
target: "flow://GetOrderDetails"
`
The package exports comprehensive TypeScript types:
- PlannerDefinition - Main input interfacePlannerTopic
- - Topic definitionPlannerAction
- - Action definitionPlannerVariable
- - Variable definitionAgentScriptStructure
- - Generated YAML structureAgentScriptGenerationOptions
- - Generation options
See the types.ts file for complete definitions.
The tool automatically formats action targets based on type:
- Flow: flow://FlowNameapex://ClassName
- Apex: standardInvocableAction://ActionName
- Standard Invocable Action: generatePromptResponse://TemplateName
- Generate Prompt Response: externalService://ServiceName
- External Service:
- Custom Protocols: Preserved as-is
1. Extract Planner Data - Get your planner configuration from Salesforce
2. Transform to Interface - Map your data to PlannerDefinition interfacegenerateAgentScript()
3. Generate YAML - Use to create YAML
4. Review & Customize - Add business logic and detailed instructions
5. Deploy - Deploy to Salesforce using Salesforce CLI
This implementation follows the official Salesforce Agent Script Recipes including:
- Language Essentials: HelloWorld, VariableManagement, TemplateExpressions
- Action Configuration: ActionDefinitions, ActionCallbacks, AdvancedInputBindings
- Architectural Patterns: MultiTopicNavigation, SimpleQA, BidirectionalNavigation
- Reasoning Mechanics: ReasoningInstructions, BeforeAfterReasoning
Contributions are welcome! Please:
1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests
5. Submit a pull request
MIT
- Salesforce Agent Script Recipes
- Agentforce Documentation
- Agent Script Syntax Guide
The package includes comprehensive error handling:
`typescript
import { generateAgentScript, ValidationError } from '@sf-explorer/agentscript-migration-tool'
try {
const yaml = generateAgentScript(planner)
} catch (error) {
if (error instanceof ValidationError) {
console.error('Validation error:', error.message)
console.error('Field:', error.field)
} else {
console.error('Generation error:', error)
}
}
`
Run the test suite:
`bash`
npm test
Run tests with coverage:
`bash`
npm run test:coverage
For issues or questions:
1. Check the official recipes
2. Review the examples directory
3. Review type definitions in types.tsgenerator.ts
4. Examine generator implementation in
5. Open an issue on GitHub
Contributions are welcome! Please see our contributing guidelines:
1. Fork the repository
2. Create a feature branch (git checkout -b feature/amazing-feature)npm test
3. Make your changes
4. Add tests for new functionality
5. Ensure all tests pass ()git commit -m 'Add amazing feature'
6. Commit your changes ()git push origin feature/amazing-feature`)
7. Push to the branch (
8. Open a Pull Request