Sub topic 3
Finding everything the agent depends on
An Agentforce agent rarely deploys alone. Its topics and actions point at Apex classes, Flows, prompt templates, objects, fields, and permissions. If any of these is missing in the target org, the deployment fails or the agent deploys and then behaves differently. This chapter shows how to build a dependency inventory before you write a manifest.
This chapter assumes you know basic Salesforce administration (orgs, sandboxes, permission sets), the Agentforce concepts of agents, topics, and actions, how a Salesforce DX project is laid out, and how Apex classes and Flows work as agent actions.
Why an inventory comes first
The agent metadata (Bot, BotVersion, GenAiPlanner, GenAiPlugin, GenAiFunction) describes the agent's structure. It does not contain the logic that runs when an action fires. That logic lives in other components, which the agent metadata only references by name.
The metadata API checks these references during deployment. A GenAiFunction that names a Flow the target org does not have will fail validation. Some gaps are quieter. A field that is missing from the target org, or a permission set that never reaches the agent user, may not stop the deploy. The agent then returns wrong answers or errors at run time.
An inventory is a list of every component the agent needs, with a note on whether it already exists in the target org. You build it once per agent and reuse it as the checklist for the manifest in a later chapter.
Layers of dependencies
Group dependencies into layers. Each layer is found in a different place.
| Layer | Examples | Where the agent points to it |
|---|---|---|
| Agent structure | `Bot`, `BotVersion`, `GenAiPlanner`, `GenAiPlugin`, `GenAiFunction` | Planner lists plugins (topics). Plugins list functions (actions). |
| Action implementations | Apex classes with invocable methods, Flows, prompt templates | The `invocationTarget` of each `GenAiFunction` |
| Data model | Custom objects, custom fields, record types, picklist values | Referenced inside Apex, Flows, and prompt templates |
| Access | Permission sets, the agent user, sharing settings | Agent user assignments and object/field/class permissions |
| Supporting content | Custom labels, custom metadata types, named credentials, knowledge or data library setup | Referenced from Apex, Flows, or instructions |
The first layer is already in your retrieved files. The other four you must discover.
Step 1: Walk the agent structure
Start with the retrieved agent files and read them in order: planner, then plugins, then functions. Each level tells you what to look for in the next.
Suppose you retrieved the agent into a DX project. List the agent-related files:
find force-app -path "*genAiPlanners*" -o -path "*genAiPlugins*" -o -path "*genAiFunctions*" -o -path "*bots*"Open the planner file and note every plugin it references. Then open each plugin and note the functions it references. Finally open each GenAiFunction and find its invocationTarget and invocationTargetType. The type tells you which kind of component to look for:
apexpoints to an Apex class.flowpoints to a Flow.promptpoints to a prompt template.
You can speed this up with a search. This command prints the target of every action in the project:
grep -rE "<invocationTarget(Type)?>" force-app --include="*.genAiFunction-meta.xml"Record each result in a table. A simple one looks like this:
| Action (GenAiFunction) | Type | Target | Exists in target org? |
|---|---|---|---|
| Get_Order_Status | flow | Get_Order_Status_Flow | No |
| Create_Case_Summary | apex | CaseSummaryAction | No |
| Draft_Reply | prompt | Draft_Reply_Template | Unknown |
Step 2: Inspect each action implementation
The implementation is where hidden dependencies live. Read each one for references to other components.
For an Apex class, check for:
- Other classes it calls, including helper and utility classes, and test classes you may need for production deployment.
- Custom objects and fields in SOQL queries and DML.
- Custom labels (
System.Label.X), custom metadata types (Type__mdt), and named credentials (callout:Name). - Custom settings and any other schema it reads.
For a Flow, check for:
- Subflows it calls.
- Objects and fields in Get, Create, Update, and Delete elements.
- Apex actions it invokes.
- Custom labels, custom metadata, and global variables.
- Email alerts, record types, and picklist values it assumes.
For a prompt template, check for:
- Merge fields on objects, which need those fields to exist.
- Data sources such as Flows or Apex it grounds on.
- The model and Einstein Trust Layer settings the target org offers.
Here is an invocable Apex class an action could point to. It shows how many dependencies a small class can hide:
public with sharing class CaseSummaryAction {
public class Request {
@InvocableVariable(required=true)
public Id caseId;
}
public class Response {
@InvocableVariable
public String summary;
}
@InvocableMethod(label='Create Case Summary' description='Summarizes a case for the agent')
public static List<Response> run(List<Request> requests) {
List<Response> results = new List<Response>();
for (Request req : requests) {
Case c = [SELECT Subject, Description, Priority, Escalation_Reason__c
FROM Case WHERE Id = :req.caseId LIMIT 1];
Response r = new Response();
r.summary = System.Label.Case_Summary_Prefix + ' ' + c.Subject
+ ' (' + c.Priority + ')';
results.add(r);
}
return results;
}
}This one class depends on:
- The custom field
Case.Escalation_Reason__c. - The custom label
Case_Summary_Prefix. - Read access to
Casefor whoever runs the action.with sharingmeans record sharing also applies.
None of these appears in the agent metadata. If you only package the agent, the Apex class, and nothing else, the class fails to compile in the target org when the field is missing.
Step 3: Let the platform help
Reading by hand misses things. Use tools to cross-check.
Retrieve by dependency, then compare. Retrieve the actions you identified and see what else the project needs by trying a validation-only deploy to a scratch org or sandbox that lacks them. The errors list the missing components by name.
Use "Where is this used?" In Setup, open a custom field, label, or Apex class and use its "Where is this used?" button. This shows reverse dependencies. It is useful when you ask the opposite question: if I deploy this field, what depends on it?
Query the dependency tables. MetadataComponentDependency is a Tooling API object that lists which components reference which. You can query it with the CLI:
sf data query \
--use-tooling-api \
--target-org source-org \
--query "SELECT MetadataComponentName, MetadataComponentType, RefMetadataComponentName, RefMetadataComponentType FROM MetadataComponentDependency WHERE MetadataComponentName = 'CaseSummaryAction'"This returns the objects, fields, labels, and classes that CaseSummaryAction references. Run it for each Apex class and Flow in your inventory. Repeat for each result that is itself code (a helper class, a subflow) until no new components appear.
Dynamic references do not appear in any dependency table. Code that builds a field name from a string, Type.forName('SomeClass'), or a Flow that reads a name from a variable hides the dependency from static analysis. Search the code for these patterns by hand.
Step 4: Add access and configuration
Components that exist are not enough. The agent must be able to use them.
- Agent user. The agent runs actions as a specific user. Note which user the source agent uses, whether that user type exists in the target org, and which permission sets it has.
- Permission sets. Identify which permission sets grant access to the Apex classes, Flows, objects, and fields. Check the actions' dependencies against the permission set contents. A class can deploy cleanly and still return "insufficient access" when the agent calls it.
- Settings and features. Note which features the agent assumes are on in the source org, such as Einstein generative AI, data libraries, or Data Cloud connections. Later chapters cover enabling them. For now, put each one on the inventory.
- Environment values. List anything that differs between orgs by design, such as endpoints in named credentials, email addresses, record IDs hard-coded in a Flow, and user names in instructions. These need different values per environment.
A complete inventory
When you finish, you should have a document like this. Keep it next to the project, for example as docs/agent-dependencies.md:
| Component | Type | Needed by | In target org? | Action |
|---|---|---|---|---|
| Case.Escalation_Reason__c | CustomField | CaseSummaryAction | No | Add to manifest |
| Case_Summary_Prefix | CustomLabel | CaseSummaryAction | No | Add to manifest |
| CaseSummaryAction | ApexClass | Create_Case_Summary | No | Add to manifest |
| Get_Order_Status_Flow | Flow | Get_Order_Status | No | Add to manifest |
| Agent_Action_Access | PermissionSet | Agent user | No | Add and assign |
| Einstein generative AI | Feature | Whole agent | Check | Enable before deploy |
| Order API | NamedCredential | Get_Order_Status_Flow | Yes, different URL | Set per environment |
Common mistakes
- Stopping at the agent metadata. The five agent types are the smallest part of the inventory.
- Ignoring transitive dependencies. A Flow calls a subflow, which calls an Apex class, which reads a custom field. Follow the chain to the end.
- Trusting a wildcard. A
*in a manifest pulls in components you did not review, including ones that depend on features the target org lacks. List specific members once the inventory is complete. - Forgetting access. Deploying the class but not the permission set that grants it leaves the action unusable.
- Assuming matching orgs. A sandbox refreshed months ago may differ from the current production. Compare, don't assume.
Exercise
An action's GenAiFunction has invocationTargetType "flow" and target "GetOrderStatus_Flow". Name two kinds of dependency that this Flow might have that do not appear anywhere in the agent metadata, and name one way to find them.
Show answer
The Flow may depend on a subflow, an Apex action, custom objects and fields (for example in a Get Records element), custom labels, custom metadata, or a named credential through an Apex or external service action. To find them, open the Flow and read each element, query MetadataComponentDependency through the Tooling API with sf data query --use-tooling-api, or run a validation-only deployment to an org that lacks the components and read the errors.
Exercise
Your validation-only deployment succeeds, but in the target org the agent says it cannot run the CreateCaseSummary action. Which layer of the inventory most likely has a gap, and why would the deployment not have caught it?
Show answer
The access layer. Permission sets and agent user assignments are not checked when the Apex class is validated for deployment, so the class compiles and deploys. At run time the agent user lacks class access, field-level security on a field the class reads, or object access, and the action fails.