⚡ Key Points: 1-Minute Summary
- Traces over Replies: Never judge an AI's routing accuracy simply by reading its reply. Traces expose the real logic.
- Analytics vs. Optimizer: Agentforce Analytics answers the question, "Is it working overall?" while Agentforce Optimizer answers, "Why is it failing on specific tasks?"
- The Early Warning Sign: If your routing accuracy drops by about 5% week-over-week, that is your earliest signal that an agent's instructions or actions need tuning.
๐บ️ Module Map: Observability & Cost
MODULE 12 ROOT: 'What is it doing in production, and what does it cost?' ├─ 12.1 Traces: Debugging the Logic ├─ 12.2 Analytics vs Optimizer: Performance Monitoring └─ 12.3 Credits and Digital Wallet: Tracking AI Consumption
๐ Deep Dive: Tracing Agentforce Logic
To truly understand how an agent is behaving, you must look under the hood. Relying solely on the agent's output is dangerous because a "wrong" subagent can often hallucinate a plausible-sounding answer that completely masks a critical routing failure.
Imagine a customer asks a complex question about a recent outage credit. The agent provides a great, accurate-looking answer. However, the trace reveals that the AI actually routed the prompt to the Billing Subagent instead of the Outages Subagent. Because the Billing Subagent had vague instructions, it guessed the answer. Nothing in the final text response revealed this flaw—only the trace exposed the poor routing decision.
- Always turn on traces at the very start of your build process by enabling
enable_enhanced_event_logsin your configuration block or directly in the Agent Builder settings. - Traces are the absolute cheapest and most effective form of debugging available. Don't wait until something breaks to turn them on.
- Traces can be inspected from the command line during a preview session, allowing developers to debug outside of the visual interface.
- Read the trace linearly, exactly how the turn executes:
router→before-reasoning→instructions→model execution→tools→after-reasoning. - Thorough trace reviews transform vague complaints like "the agent is being weird" into highly specific, fixable code or prompt issues.
Rule: Turn on enhanced event logs before building anything, and debug strictly from traces, not outputs.
Gain: You identify specific root causes (e.g., overlapping action descriptions) instead of making blind guesses. You get tangible evidence to justify fixes.
Price: Deep conversation logging consumes storage. Always confirm that capturing this data complies with your organization’s data and privacy policies.
Limits: Tracing is off by default. You cannot retroactively recover a trace for a conversation that already happened.
Mirror (Just reading the reply): It’s fast, but it hides almost every underlying routing failure.
If asked how you debug an agent, do not say: "I adjust the prompt and re-test to see if it acts better." That is just guessing!
The expected answer is: "I open the trace logs and read the execution step-by-step to find exactly where the reasoning or routing broke down."
๐ฌ Core Q&A: Debugging Like a Pro
A: Debugging must start with hard evidence, not hypotheses. First, I ensure enable_enhanced_event_logs is toggled on. (I do this at the start of a project because you can't trace past events). I then read the trace chronologically: checking which subagent the router picked, analyzing the before-reasoning, reviewing which actions fired (and their inputs/outputs), and finally looking at the branch taken.
I always check routing first. A wrong specialist might generate a convincing answer that totally obscures the failure. Once I isolate the exact step that failed, the fix is usually obvious—like cleaning up an overlapping topic description, clarifying a vague action, or fixing a missing permission.
A: Think of Analytics as your dashboard—it gives you macro-level visibility into agent usage, session lengths, and overall deflection rates. It answers "Is the agent providing value?" Optimizer, on the other hand, is your diagnostic tool. It digs into the AI's decision-making patterns to help you refine instructions and routing logic. It answers "Why is the agent failing on these specific intents?"
A: AI consumption is tracked via the Salesforce Digital Wallet. Every time an agent reasons, executes a tool, or generates a response, it consumes AI credits (often tied to your Data Cloud credit pool). Monitoring traces and optimizing your agent's routing isn't just about accuracy—it prevents the agent from needlessly looping or calling expensive APIs, which directly saves your company credits.