sf-forcekit 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/License +21 -0
  2. package/README.md +106 -0
  3. package/bin/cli.js +85 -0
  4. package/package.json +44 -0
  5. package/templates/ai-dir/README.md +155 -0
  6. package/templates/ai-dir/agentforce.md +213 -0
  7. package/templates/ai-dir/architecture.md +123 -0
  8. package/templates/ai-dir/commands.md +276 -0
  9. package/templates/ai-dir/context-snapshots/TEMPLATE.md +64 -0
  10. package/templates/ai-dir/conventions.md +242 -0
  11. package/templates/ai-dir/current-state.md +113 -0
  12. package/templates/ai-dir/debugging-notes.md +165 -0
  13. package/templates/ai-dir/deployment.md +161 -0
  14. package/templates/ai-dir/integrations.md +199 -0
  15. package/templates/ai-dir/inventory.md +209 -0
  16. package/templates/ai-dir/known-issues.md +124 -0
  17. package/templates/ai-dir/org-context.md +110 -0
  18. package/templates/ai-dir/performance.md +312 -0
  19. package/templates/ai-dir/prompts/agentforce.md +163 -0
  20. package/templates/ai-dir/prompts/apex.md +165 -0
  21. package/templates/ai-dir/prompts/flows.md +125 -0
  22. package/templates/ai-dir/prompts/lwc.md +230 -0
  23. package/templates/ai-dir/prompts/security.md +181 -0
  24. package/templates/ai-dir/prompts/testing.md +269 -0
  25. package/templates/ai-dir/rules.md +238 -0
  26. package/templates/ai-dir/scripts/update_state.py +1406 -0
  27. package/templates/ai-dir/source-of-truth.md +180 -0
  28. package/templates/ai-dir/templates/Selector.cls +113 -0
  29. package/templates/ai-dir/templates/Service.cls +132 -0
  30. package/templates/ai-dir/templates/TestClass.cls +143 -0
  31. package/templates/ai-dir/templates/TriggerHandler.cls +67 -0
  32. package/templates/ai-dir/testing-strategy.md +342 -0
package/License ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rohit Vaghela
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # ForceKit ⚑
2
+
3
+ > **Salesforce enterprise-grade AI context layer and agent skill for Salesforce DX projects.**
4
+
5
+ ForceKit provides a structured, token-efficient `.ai/` context system that shields AI agents from hallucinations, enforces strict layered architecture patterns, and manages session state. It also bundles a complete **agent skill** configuration that you can drop directly into your agent's config folder.
6
+
7
+ ---
8
+
9
+ ## πŸš€ Key Features
10
+
11
+ * **Anti-Hallucination Protocol (Non-Negotiable)**: Strictly enforces verification rules so agents don't guess API names, custom fields, or Apex methods.
12
+ * **Tiered Reading Architecture**: Organizes context files into tiers (T0 to T3) to save token budget while maintaining situational awareness.
13
+ * **Enterprise-Grade Apex Standards**: Automates rules for bulkification, user mode queries (`WITH USER_MODE`), and trigger bypass patterns.
14
+ * **Automated State Scannner**: Includes an inventory script that scans and indexes objects, classes, LWCs, and flows.
15
+ * **Next-Session Handoff**: Keeps a rolling session log so agents can hand off work to each other across sessions without loss of context.
16
+
17
+ ---
18
+
19
+ ## πŸ“¦ Directory Structure
20
+
21
+ ```
22
+ forcekit/
23
+ β”œβ”€β”€ SKILL.md # Agent-facing skill description & triggers
24
+ β”œβ”€β”€ README.md # This user guide
25
+ β”œβ”€β”€ scripts/
26
+ β”‚ └── scaffold.sh # Installer script to generate .ai/ in target projects
27
+ β”œβ”€β”€ references/ # Context guides read by the active agent skill
28
+ β”‚ β”œβ”€β”€ conventions.md
29
+ β”‚ β”œβ”€β”€ testing-strategy.md
30
+ β”‚ └── ...
31
+ └── templates/
32
+ └── ai-dir/ # Source files for bootstrapping new projects
33
+ ```
34
+
35
+ ---
36
+
37
+ ## βš™οΈ How to Use / Install
38
+
39
+ ### Option A: Zero Install (npx, bunx, pnpm dlx)
40
+ You don't need to install anything! Run this command directly inside your Salesforce DX project root to scaffold the `.ai/` directory:
41
+
42
+ ```bash
43
+ # Using npm
44
+ npx sf-forcekit
45
+
46
+ # Using bun
47
+ bunx sf-forcekit
48
+
49
+ # Using pnpm
50
+ pnpm dlx sf-forcekit
51
+ ```
52
+
53
+ ---
54
+
55
+ ### Option B: Local AI Agent Skill
56
+ If you want to use ForceKit as a registered local skill inside your AI agent (like Google Antigravity, Claude Code, Windsurf, Codex, etc.) so it can auto-trigger on command:
57
+
58
+ 1. Clone this repository into your agent's skills directory:
59
+ ```bash
60
+ git clone https://github.com/<your-username>/forcekit.git ~/.gemini/config/skills/forcekit
61
+ ```
62
+ 2. Restart your agent or start a new session. The agent will automatically register the `forcekit` skill!
63
+
64
+ Once the skill is active, you can tell the agent:
65
+ > *"scaffold a salesforce context layer"*
66
+ > OR
67
+ > *"initialize forcekit in this project"*
68
+
69
+ ---
70
+
71
+ ## πŸ› οΈ Scaffolding Output
72
+
73
+ The scaffold process generates the following structure in your project root:
74
+ ```
75
+ my-sfdx-project/
76
+ └── .ai/
77
+ β”œβ”€β”€ README.md
78
+ β”œβ”€β”€ rules.md # Rules for agent behavior
79
+ β”œβ”€β”€ org-context.md # Target org details
80
+ β”œβ”€β”€ current-state.md # Active session log & tech debt
81
+ β”œβ”€β”€ inventory.md # Auto-scanned metadata index
82
+ β”œβ”€β”€ scripts/
83
+ β”‚ └── update_state.py # Automation tool
84
+ └── ...
85
+ ```
86
+
87
+ ---
88
+
89
+ ## πŸ€– AI Agent Compatibility
90
+
91
+ ForceKit is designed to work with all major AI developer agents and IDE extensions:
92
+ * **Google Antigravity & Gemini**: Full custom skill registration and guideline enforcement.
93
+ * **Claude Code**: Supports standard `agentskills` trigger formatting.
94
+ * **Codex & Windsurf**: Integrates with local workspace context rules and custom commands.
95
+ * **GitHub Copilot**: Automatically reads project state from the `.ai/` folder.
96
+ * **Cursor**: Seamlessly references `.ai/` files via `@` context inclusion.
97
+
98
+ ---
99
+
100
+ ## 🀝 Contributing
101
+
102
+ Contributions to improve Salesforce AI development patterns are welcome! Feel free to open issues or submit pull requests.
103
+
104
+ ## πŸ“„ License
105
+
106
+ MIT
package/bin/cli.js ADDED
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const readline = require('readline');
6
+
7
+ // Colors helper
8
+ const GREEN = '\x1b[32m';
9
+ const BLUE = '\x1b[34m';
10
+ const YELLOW = '\x1b[33m';
11
+ const RED = '\x1b[31m';
12
+ const NC = '\x1b[0m';
13
+
14
+ console.log(`${BLUE}=== ForceKit: Salesforce AI Context Scaffolder ===${NC}`);
15
+
16
+ // Verify sfdx-project.json exists
17
+ if (!fs.existsSync(path.join(process.cwd(), 'sfdx-project.json'))) {
18
+ console.log(`${YELLOW}Warning: sfdx-project.json not found in current directory.${NC}`);
19
+ console.log('Are you running this from the root of your Salesforce DX project?\n');
20
+ }
21
+
22
+ const targetDir = path.join(process.cwd(), '.ai');
23
+ const templateDir = path.join(__dirname, '..', 'templates', 'ai-dir');
24
+
25
+ function copyRecursiveSync(src, dest) {
26
+ const exists = fs.existsSync(src);
27
+ const stats = exists && fs.statSync(src);
28
+ const isDirectory = exists && stats.isDirectory();
29
+ if (isDirectory) {
30
+ if (!fs.existsSync(dest)) {
31
+ fs.mkdirSync(dest, { recursive: true });
32
+ }
33
+ fs.readdirSync(src).forEach((childItemName) => {
34
+ copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName));
35
+ });
36
+ } else {
37
+ fs.copyFileSync(src, dest);
38
+ }
39
+ }
40
+
41
+ function doScaffold() {
42
+ if (fs.existsSync(targetDir)) {
43
+ console.log(`${YELLOW}Warning: Target directory .ai/ already exists.${NC}`);
44
+ const rl = readline.createInterface({
45
+ input: process.stdin,
46
+ output: process.stdout
47
+ });
48
+ rl.question('Do you want to overwrite it? (y/n) ', (answer) => {
49
+ rl.close();
50
+ if (answer.toLowerCase() === 'y') {
51
+ console.log('Cleaning up existing .ai/ directory...');
52
+ fs.rmSync(targetDir, { recursive: true, force: true });
53
+ runCopy();
54
+ } else {
55
+ console.log(`${RED}Scaffold aborted.${NC}`);
56
+ process.exit(1);
57
+ }
58
+ });
59
+ } else {
60
+ runCopy();
61
+ }
62
+ }
63
+
64
+ function runCopy() {
65
+ console.log('Bootstrapping .ai/ directory structure...');
66
+ try {
67
+ copyRecursiveSync(templateDir, targetDir);
68
+ // Make python script executable if on Unix
69
+ const pythonScript = path.join(targetDir, 'scripts', 'update_state.py');
70
+ if (fs.existsSync(pythonScript) && process.platform !== 'win32') {
71
+ fs.chmodSync(pythonScript, '755');
72
+ }
73
+ console.log(`${GREEN}βœ“ Success! ForceKit context layer generated at ./.ai/${NC}\n`);
74
+ console.log('Next steps:');
75
+ console.log(` 1. Edit ${BLUE}.ai/org-context.md${NC} with your Salesforce org details.`);
76
+ console.log(` 2. Run ${BLUE}python3 .ai/scripts/update_state.py scan${NC} to initialize project inventory.`);
77
+ console.log(` 3. Start code generation using the tiered reading instructions in ${BLUE}.ai/README.md${NC}.\n`);
78
+ console.log('Happy Coding! ⚑');
79
+ } catch (err) {
80
+ console.error(`${RED}Error scaffolding project: ${err.message}${NC}`);
81
+ process.exit(1);
82
+ }
83
+ }
84
+
85
+ doScaffold();
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "sf-forcekit",
3
+ "version": "1.0.0",
4
+ "description": "Scaffold a structured .ai/ context layer for Salesforce DX projects β€” anti-hallucination, layered architecture, session memory, and governor limit awareness for AI agents.",
5
+ "main": "bin/cli.js",
6
+ "bin": {
7
+ "sf-forcekit": "./bin/cli.js",
8
+ "forcekit": "./bin/cli.js"
9
+ },
10
+ "files": [
11
+ "bin",
12
+ "templates/ai-dir",
13
+ "License"
14
+ ],
15
+ "engines": {
16
+ "node": ">=16.0.0"
17
+ },
18
+ "keywords": [
19
+ "salesforce",
20
+ "sfdx",
21
+ "ai",
22
+ "context",
23
+ "agents",
24
+ "claude-code",
25
+ "antigravity",
26
+ "copilot",
27
+ "cursor",
28
+ "apex",
29
+ "lwc",
30
+ "devops",
31
+ "dx",
32
+ "forcekit"
33
+ ],
34
+ "author": "Rohit Vaghela",
35
+ "license": "MIT",
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "git+https://github.com/rvaghela20/forcekit.git"
39
+ },
40
+ "homepage": "https://github.com/rvaghela20/forcekit#readme",
41
+ "bugs": {
42
+ "url": "https://github.com/rvaghela20/forcekit/issues"
43
+ }
44
+ }
@@ -0,0 +1,155 @@
1
+ # .ai/ β€” Salesforce Project AI Context
2
+
3
+ > A structured context layer for AI-assisted Salesforce development.
4
+ > Drop this `.ai/` directory into the root of any SFDX project to give agents full situational awareness.
5
+
6
+ ## Quick Start for Agents
7
+
8
+ > [!IMPORTANT]
9
+ > **Agents: Read `rules.md` FIRST.** It defines your read order, auto-update obligations, and code generation rules.
10
+
11
+ ```
12
+ 1. Read rules.md β†’ Your behavior rules
13
+ 2. Read org-context.md β†’ Org details and CLI config
14
+ 3. Read current-state.md β†’ What's happening NOW + session history
15
+ 4. Read conventions.md β†’ Coding standards
16
+ 5. Start working β€” and UPDATE current-state.md as you go
17
+ ```
18
+
19
+ ## Directory Structure
20
+
21
+ ```
22
+ .ai/
23
+ β”œβ”€β”€ rules.md ← πŸ€– AGENT START HERE β€” behavior rules, auto-update protocol
24
+ β”œβ”€β”€ README.md ← You are here
25
+ β”‚
26
+ β”œβ”€β”€ ── CORE (Always Read) ──────────────────────────────────
27
+ β”œβ”€β”€ source-of-truth.md ← 🚫 ANTI-HALLUCINATION β€” verification commands, standard library
28
+ β”œβ”€β”€ inventory.md ← πŸ€– AUTO-UPDATED β€” registry of everything in the project
29
+ β”œβ”€β”€ org-context.md ← Org type, edition, limits, installed packages
30
+ β”œβ”€β”€ current-state.md ← πŸ€– AUTO-UPDATED β€” live status, session log, tech debt, next steps
31
+ β”‚
32
+ β”œβ”€β”€ ── STANDARDS (Read Per Task) ───────────────────────────
33
+ β”œβ”€β”€ conventions.md ← Coding standards (Apex, LWC, Flows, naming)
34
+ β”œβ”€β”€ architecture.md ← System design, data model, integration map
35
+ β”œβ”€β”€ testing-strategy.md ← Test philosophy, patterns, TestDataFactory, coverage rules
36
+ β”œβ”€β”€ performance.md ← Governor limits, SOQL optimization, heap, async patterns
37
+ β”‚
38
+ β”œβ”€β”€ ── REFERENCE (Read As Needed) ──────────────────────────
39
+ β”œβ”€β”€ commands.md ← sf CLI cookbook β€” every command organized by workflow
40
+ β”œβ”€β”€ deployment.md ← Deploy/retrieve workflows, CI/CD config
41
+ β”œβ”€β”€ integrations.md ← External systems, Named Credentials, callout patterns
42
+ β”œβ”€β”€ agentforce.md ← Agentforce Topics, Actions, Prompt Templates
43
+ β”œβ”€β”€ debugging-notes.md ← Debug techniques, log categories, common errors
44
+ β”œβ”€β”€ known-issues.md ← Platform bugs, workarounds, tech debt
45
+ β”‚
46
+ β”œβ”€β”€ ── GENERATION RULES ────────────────────────────────────
47
+ β”œβ”€β”€ prompts/ ← Agent-specific instruction sets
48
+ β”‚ β”œβ”€β”€ apex.md ← Apex generation rules
49
+ β”‚ β”œβ”€β”€ lwc.md ← LWC generation rules
50
+ β”‚ β”œβ”€β”€ testing.md ← Test class generation rules
51
+ β”‚ β”œβ”€β”€ flows.md ← Flow building guidance
52
+ β”‚ β”œβ”€β”€ security.md ← Security review & CRUD/FLS rules
53
+ β”‚ └── agentforce.md ← Agentforce/Einstein development rules
54
+ β”‚
55
+ β”œβ”€β”€ ── TEMPLATES & TOOLS ───────────────────────────────────
56
+ β”œβ”€β”€ templates/ ← Copy-paste boilerplate starters
57
+ β”‚ β”œβ”€β”€ TriggerHandler.cls ← Base class with routing + bypass control
58
+ β”‚ β”œβ”€β”€ Service.cls ← Service layer template
59
+ β”‚ β”œβ”€β”€ Selector.cls ← Selector/repository template
60
+ β”‚ └── TestClass.cls ← Test class template
61
+ β”œβ”€β”€ scripts/ ← Automation scripts
62
+ β”‚ └── update_state.py ← Scan, sync, verify, lint, session management
63
+ └── context-snapshots/ ← Point-in-time project snapshots
64
+ └── TEMPLATE.md ← Copy per session for deep context preservation
65
+ ```
66
+
67
+ ## File Priority Tiers
68
+
69
+ Agents should optimize context window usage by reading files in priority order:
70
+
71
+ | Tier | Files | When to Read | ~Size |
72
+ |------|-------|-------------|-------|
73
+ | **T0 β€” Always** | `rules.md`, `org-context.md`, `current-state.md`, `inventory.md` | Every session start | ~20 KB |
74
+ | **T1 β€” Per Task** | `conventions.md`, `source-of-truth.md`, + relevant `prompts/*.md` | Before writing code | ~20 KB |
75
+ | **T2 β€” Situational** | `architecture.md`, `testing-strategy.md`, `performance.md` | When task involves design, tests, or optimization | ~15 KB |
76
+ | **T3 β€” Reference** | `commands.md`, `deployment.md`, `integrations.md`, `debugging-notes.md`, `known-issues.md`, `agentforce.md` | When specifically needed | ~35 KB |
77
+
78
+ > [!TIP]
79
+ > **Total .ai/ context β‰ˆ 90 KB.** For tight context windows, read only T0 + T1. For full sessions, read T0–T2.
80
+
81
+ ## How It Works
82
+
83
+ ### For Humans
84
+
85
+ 1. **Copy** this `.ai/` folder into any new SFDX project root.
86
+ 2. **Fill in** `org-context.md` with your target org details (or run `python3 .ai/scripts/update_state.py sync-org`).
87
+ 3. **Review** `current-state.md` to see what the AI has been doing β€” session logs, decisions, files changed.
88
+ 4. **Correct** anything in `current-state.md` if the agent got it wrong.
89
+
90
+ ### For AI Agents
91
+
92
+ 1. **Read** `rules.md` first β€” it's your operating manual.
93
+ 2. **Auto-update** `current-state.md` as you work:
94
+ - Log your session (date, goal, what you did)
95
+ - Track active work (in progress / completed)
96
+ - Record blockers and decisions
97
+ - List every file you create or change
98
+ 3. **Snapshot** context into `context-snapshots/YYYY-MM-DD.md` at end of long sessions.
99
+
100
+ ### Auto-Update Flow
101
+
102
+ ```
103
+ Agent starts session
104
+ β”‚
105
+ β”œβ”€β”€β†’ Reads rules.md + current-state.md
106
+ β”‚
107
+ β”œβ”€β”€β†’ Adds session entry to Session Log
108
+ β”‚
109
+ β”œβ”€β”€β†’ Works on task
110
+ β”‚ β”œβ”€β”€ Updates "In Progress" items
111
+ β”‚ β”œβ”€β”€ Appends to "Files Changed"
112
+ β”‚ └── Logs blockers/decisions as they arise
113
+ β”‚
114
+ └──→ Session ends
115
+ β”œβ”€β”€ Marks items completed
116
+ β”œβ”€β”€ Writes session summary
117
+ └── Creates context snapshot (if major session)
118
+ ```
119
+
120
+ ## Multi-Agent Compatibility
121
+
122
+ This structure is designed to work with:
123
+ - **Claude Code / Antigravity** β€” reads `rules.md` as project rules
124
+ - **GitHub Copilot** β€” reads `.ai/` as project context
125
+ - **Cursor** β€” `.ai/` files surface in context window
126
+ - **Agentforce for Developers** β€” mirror `prompts/` into `.sfdx/a4d/rules/`
127
+ - **Any LLM agent** β€” markdown is universally parseable
128
+
129
+ ## Maintenance
130
+
131
+ | File | Updated By | Frequency |
132
+ |------|-----------|-----------|
133
+ | `rules.md` | Human | Rarely (on process change) |
134
+ | `org-context.md` | Human / Script | Once per org (or `sync-org`) |
135
+ | `conventions.md` | Human | Rarely (on standards update) |
136
+ | `architecture.md` | Human + Agent | Per major feature / data model change |
137
+ | `testing-strategy.md` | Human | Rarely (on test philosophy change) |
138
+ | `performance.md` | Human | Per API version / new patterns |
139
+ | `commands.md` | Human | On CLI updates |
140
+ | `current-state.md` | **πŸ€– Agent (auto)** | **Every session, continuously** |
141
+ | `inventory.md` | **πŸ€– Agent (auto)** | **After creating/deleting metadata** |
142
+ | `deployment.md` | Human | On CI/CD pipeline changes |
143
+ | `known-issues.md` | Human + Agent | As discovered |
144
+ | `context-snapshots/` | **πŸ€– Agent (auto)** | Per session or milestone |
145
+
146
+ ## Helper Script Reference
147
+
148
+ ```bash
149
+ python3 .ai/scripts/update_state.py scan # Scan project β†’ update inventory.md
150
+ python3 .ai/scripts/update_state.py sync-org # Fetch org details β†’ update org-context.local.md
151
+ python3 .ai/scripts/update_state.py cache-schema # Cache objects/fields for offline verification
152
+ python3 .ai/scripts/update_state.py check # Static analysis / code style lint
153
+ python3 .ai/scripts/update_state.py verify --type class --name AccountService # Verify metadata exists
154
+ python3 .ai/scripts/update_state.py clean # Strip local data for open-source distribution
155
+ ```
@@ -0,0 +1,213 @@
1
+ # Agentforce
2
+
3
+ > Einstein Bots, Copilot Actions, Prompt Templates, and autonomous agent development.
4
+
5
+ ---
6
+
7
+ ## Overview
8
+
9
+ Agentforce is Salesforce's autonomous AI agent platform (successor to Einstein Copilot). Agents can interact with users, trigger autonomously on events, and take actions grounded in live CRM data.
10
+
11
+ ### Core Concepts
12
+
13
+ | Concept | Description |
14
+ |---------|-------------|
15
+ | **Agent** | AI entity (Service Agent, Sales Agent, Custom Agent) |
16
+ | **Topic** | Category of tasks/intents the agent handles (e.g., "Order Management") |
17
+ | **Action** | Tool the agent invokes β€” Standard, Flow, Apex, or Prompt Template |
18
+ | **Atlas Reasoning Engine** | The AI planner that decides which actions to invoke based on natural language |
19
+ | **Einstein Trust Layer** | Masks sensitive PII before sending data to LLM, audits all interactions |
20
+
21
+ ---
22
+
23
+ ## Architecture
24
+
25
+ ```
26
+ User / Event Trigger
27
+ β”‚
28
+ β–Ό
29
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
30
+ β”‚ Agentforce Agent β”‚
31
+ β”‚ (Supervisor / Child)β”‚
32
+ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
33
+ β”‚ Atlas Reasoning β”‚ ← Uses Topic descriptions + Action descriptions
34
+ β”‚ Engine β”‚ to decide what to do
35
+ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
36
+ β”‚ Trust Layer β”‚ ← PII masking, audit logging, guardrails
37
+ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
38
+ β”‚ Actions β”‚
39
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
40
+ β”‚ β”‚ Standard Actionβ”‚ β”‚ ← Out-of-the-box (e.g., Query Records)
41
+ β”‚ β”‚ Flow Action β”‚ β”‚ ← Triggered Flows / Screen Flows
42
+ β”‚ β”‚ Apex Action β”‚ β”‚ ← @InvocableMethod classes
43
+ β”‚ β”‚ Prompt Templateβ”‚ β”‚ ← Prompt Builder templates
44
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
45
+ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
46
+ β”‚ Data Cloud β”‚ ← Grounding data, context
47
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
48
+ ```
49
+
50
+ ---
51
+
52
+ ## Development Rules
53
+
54
+ ### 1. Declarative First
55
+
56
+ Always check if a standard action or Flow can solve the problem before writing custom Apex.
57
+
58
+ ```
59
+ Decision Tree:
60
+ Can a Standard Action do it? β†’ Use Standard Action
61
+ Can a Flow do it? β†’ Use Flow Action
62
+ Need complex logic? β†’ Use @InvocableMethod Apex Action
63
+ Need AI-generated text? β†’ Use Prompt Template Action
64
+ ```
65
+
66
+ ### 2. Action Descriptions Are Critical
67
+
68
+ The Atlas Reasoning Engine uses **natural language descriptions** to decide when to invoke actions. Poor descriptions = wrong action selection.
69
+
70
+ ```apex
71
+ // βœ… GOOD β€” Clear, specific description
72
+ @InvocableMethod(
73
+ label='Get Account Health Score'
74
+ description='Calculates a health score (0-100) for an Account based on recent activity, open cases, and engagement metrics. Use when the user asks about account health, risk, or engagement.'
75
+ )
76
+ public static List<Integer> getHealthScore(List<Id> accountIds) { ... }
77
+
78
+ // ❌ BAD β€” Vague description
79
+ @InvocableMethod(
80
+ label='Process Account'
81
+ description='Does account stuff'
82
+ )
83
+ ```
84
+
85
+ ### 3. Apex Actions for Agentforce
86
+
87
+ ```apex
88
+ /**
89
+ * @description Apex action for Agentforce to retrieve order status.
90
+ * Action: Invocable from Agentforce Topics.
91
+ */
92
+ public with sharing class OrderStatusAction {
93
+
94
+ public class OrderStatusRequest {
95
+ @InvocableVariable(label='Order Number' description='The order number to look up' required=true)
96
+ public String orderNumber;
97
+ }
98
+
99
+ public class OrderStatusResponse {
100
+ @InvocableVariable(label='Status' description='Current order status')
101
+ public String status;
102
+
103
+ @InvocableVariable(label='Expected Delivery' description='Expected delivery date')
104
+ public Date expectedDelivery;
105
+
106
+ @InvocableVariable(label='Message' description='Human-readable status summary')
107
+ public String message;
108
+ }
109
+
110
+ @InvocableMethod(
111
+ label='Get Order Status'
112
+ description='Retrieves the current status and expected delivery date for a given order number. Use when customers ask about their order, shipment, or delivery.'
113
+ )
114
+ public static List<OrderStatusResponse> getOrderStatus(List<OrderStatusRequest> requests) {
115
+ // Bulkified implementation
116
+ List<OrderStatusResponse> responses = new List<OrderStatusResponse>();
117
+ Set<String> orderNumbers = new Set<String>();
118
+
119
+ for (OrderStatusRequest req : requests) {
120
+ orderNumbers.add(req.orderNumber);
121
+ }
122
+
123
+ Map<String, Order> orderMap = new Map<String, Order>();
124
+ for (Order o : [
125
+ SELECT Id, OrderNumber, Status, ExpectedDeliveryDate__c
126
+ FROM Order
127
+ WHERE OrderNumber IN :orderNumbers
128
+ WITH USER_MODE
129
+ ]) {
130
+ orderMap.put(o.OrderNumber, o);
131
+ }
132
+
133
+ for (OrderStatusRequest req : requests) {
134
+ OrderStatusResponse resp = new OrderStatusResponse();
135
+ Order o = orderMap.get(req.orderNumber);
136
+ if (o != null) {
137
+ resp.status = o.Status;
138
+ resp.expectedDelivery = o.ExpectedDeliveryDate__c;
139
+ resp.message = 'Order ' + o.OrderNumber + ' is ' + o.Status;
140
+ } else {
141
+ resp.message = 'Order not found: ' + req.orderNumber;
142
+ }
143
+ responses.add(resp);
144
+ }
145
+ return responses;
146
+ }
147
+ }
148
+ ```
149
+
150
+ ### 4. Prompt Templates
151
+
152
+ - Use **Prompt Builder** in Setup to create reusable prompt templates
153
+ - Ground templates with **Data Cloud** merge fields for accurate, hallucination-resistant output
154
+ - Test templates with different personas and edge cases
155
+
156
+ ### 5. Guardrails
157
+
158
+ - Use **Agent Script** for mission-critical tasks (enforces if/then deterministic workflows)
159
+ - Configure **Content Safety Policies** for output filtering
160
+ - Enable **Audit Trails** in Command Center for monitoring
161
+
162
+ ---
163
+
164
+ ## Multi-Agent Orchestration
165
+
166
+ ```
167
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
168
+ β”‚ Supervisor Agent β”‚ ← Single front door
169
+ β”‚ (routes to children) β”‚
170
+ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
171
+ β”‚ β”‚
172
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”‚
173
+ β”‚ β”‚ Sales β”‚ β”‚ Service β”‚β”‚
174
+ β”‚ β”‚ Agent β”‚ β”‚ Agent β”‚β”‚
175
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β”‚
176
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”‚
177
+ β”‚ β”‚ Customβ”‚ β”‚ Analyticsβ”‚β”‚
178
+ β”‚ β”‚ Agent β”‚ β”‚ Agent β”‚β”‚
179
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β”‚
180
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
181
+ ```
182
+
183
+ - Use a **Supervisor Agent** as the entry point
184
+ - Route to **specialist agents** based on Topic matching
185
+ - Each child agent has its own Topics and Actions
186
+ - Monitor via **Command Center**
187
+
188
+ ---
189
+
190
+ ## Testing Agentforce
191
+
192
+ 1. **Unit test** all `@InvocableMethod` classes like standard Apex
193
+ 2. **Test in Agent Builder** preview panel with sample conversations
194
+ 3. **Validate** action descriptions by checking if Atlas picks the correct action
195
+ 4. **Edge cases**: What happens when the action returns no data? Empty input? Error?
196
+
197
+ ---
198
+
199
+ ## Agentforce for Developers (A4D) Rules
200
+
201
+ Salesforce recognizes `.sfdx/a4d/rules/*.md` files for AI coding assistant rules:
202
+
203
+ ```
204
+ .sfdx/
205
+ a4d/
206
+ rules/
207
+ apex.md ← Apex generation rules
208
+ html.md ← LWC HTML template rules
209
+ css.md ← Component CSS rules
210
+ js.md ← LWC JavaScript rules
211
+ ```
212
+
213
+ These are auto-detected by Agentforce for Developers during code generation. Consider mirroring your `.ai/prompts/` content here for A4D compatibility.