Building Agentforce custom agents on enterprise data
Custom Agentforce agents with Agent Script, Apex, Platform Events, callouts, and Data Library grounding for scheduling and order intelligence at Samsung Ads and NBCUniversal-style revenue stacks.
Agentforce shifts Salesforce from “AI features on a page” to agents that act inside your security model—if you ground them honestly and wire actions you can audit. In my current Samsung Ads architecture work (and continuing patterns from NBCUniversal revenue systems), I design custom agents that combine Agent Script, Apex (sync and async), Platform Events, callouts, and the Agentforce Data Library so answers cite enterprise data—not improvisation.
Agent Script as the contract
Agent Script defines what an agent may say and do: topics, instructions, action boundaries, and escalation paths. I treat scripts like API contracts—versioned, reviewed, and tested—because a polite tone does not compensate for an unbounded tool list.
Scripts reference actions that map to Apex, Flow, or packaged capabilities. Each action gets a narrow input schema and explicit success and failure messages the model must use verbatim where policy requires it.
Apex: synchronous discipline, asynchronous offload
Synchronous Apex backs low-latency reads and safe, idempotent updates the agent triggers during a live conversation—fetch order status, summarize an allowed field set, validate a customer identifier.
Asynchronous Apex (Queueable or Batch where appropriate) handles callout-heavy or bulk work: building retrieval indexes, refreshing vector chunks, or publishing Platform Events after a durable commit so downstream analytics see the same fact the agent acted on.
I never chain long callouts in the synchronous path an agent blocks on. The pattern is respond with status, enqueue work, notify via event if needed.
Platform Events and callouts
Platform Events decouple agents from integrations. When an agent action changes commercial state, an event carries the payload MuleSoft or internal services already subscribe to. Callouts stay inside service classes with timeouts, retry policy, and named credentials—agents invoke services, not raw HTTP.
Grounding with Agentforce Data Library
Grounding is the difference between demo and production. I use the Agentforce Data Library with deliberate search indexing and Data Actions:
- Index only fields and objects policy allows agents to see.
- Refresh indexes when upstream ETL or CRM updates change meanings—not on every chat turn.
- Data Actions expose create/read/update paths that mirror what a human operator could do in the same role.
For revenue operations, I focus grounding on scheduling summaries, order headers and lines, and entitlement facts—not entire unrelated archives.
Vectorizing scheduling and order data
Some questions need semantic retrieval, not just record lookup. I vectorize scheduling and order data into chunks suitable for AI tools—flight dates, inventory holds, amendment summaries—so retrieval returns top relevant chunks with ids that Apex can verify before the agent cites them.
Vectorization jobs run async; verification stays deterministic in code. The agent proposes an answer from retrieved chunks; Apex confirms record ids still match current state.
Safety habits
- Role-based visibility flows through the agent’s user context—no elevated system mode for convenience.
- Log tool invocations with correlation ids tied to conversation sessions.
- Human escalation paths for negative financial impact, policy exceptions, or low-confidence retrieval.
Closing
Custom Agentforce agents are integration projects with a conversational skin. Agent Script, sync/async Apex, Platform Events, disciplined callouts, and a curated Data Library turn scheduling and order questions into governed assistance—not a novelty chat box on top of Salesforce.