
Observing Agentforce
Query Salesforce Data Cloud STDM traces to debug Agentforce sessions, LLM steps, and aggregated agent metrics in production orgs.
Overview
observing-agentforce is an agent skill most often used in Operate (also Build agent-tooling, Grow analytics) that queries Salesforce STDM in Data Cloud to analyze Agentforce sessions, steps, and metrics.
Install
npx skills add https://github.com/forcedotcom/afv-library --skill observing-agentforceWhat is this skill?
- STDM queries in Data Cloud: sessions, conversation details, LLM step details, moment insights
- AgentforceOptimizeService Apex with dataSpaceName—no hardcoded Data Space
- findSessions and getAggregatedMetrics with time windows and optional agentName filter
- Invocable runObservabilityQuery for Flow-orchestrated observability batches
Adoption & trust: 1.3k installs on skills.sh; 513 GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
Your Agentforce agent fails or drifts in production and you lack structured session, turn, and LLM-step visibility inside Salesforce.
Who is it for?
Salesforce indie builders running Agentforce in Data Cloud who need STDM-backed debugging and ops dashboards.
Skip if: Non-Salesforce stacks or teams without Data Cloud and Agentforce already enabled.
When should I use this skill?
Analyzing Agentforce sessions, STDM traces, LLM steps, or aggregated metrics in Salesforce Data Cloud.
What do I get? / Deliverables
You deploy or invoke STDM query helpers to pull session summaries, conversation JSON, and aggregated metrics so you can pinpoint bad tool calls or prompt regressions.
- Apex query calls or Invocable observability flows
- JSON session and conversation diagnostics for triage
Recommended Skills
Journey fit
Spans multiple journey phases - primary shelf plus alternate fits below.
Observability against live Agentforce traffic is primarily an operate concern once agents are deployed. STDM session traces, conversation turns, and aggregated metrics are monitoring and incident-analysis workflows.
Where it fits
Deploy AgentforceOptimizeService once so future agent releases emit queryable STDM signals.
Pull getConversationDetails for a failed sessionId after a user reports a wrong Agentforce answer.
Run getAggregatedMetrics across a launch window to compare agentName performance trends.
How it compares
Operational STDM query layer for deployed agents—not a generic LLM observability SaaS outside Salesforce.
Common Questions / FAQ
Who is observing-agentforce for?
Builders maintaining Agentforce in Salesforce orgs who need Data Cloud STDM access for session- and step-level analysis.
When should I use observing-agentforce?
In Operate when monitoring live agents; in Build when wiring observability services; in Grow when reviewing aggregated agent performance over time windows.
Is observing-agentforce safe to install?
Treat Apex and Data Cloud access as privileged; review Security Audits on this page and your org’s sharing model before deployment.
SKILL.md
READMESKILL.md - Observing Agentforce
/** * @description STDM query service for the agentforce-optimize Claude Code skill. * Queries the Session Trace Data Model (STDM) in Data Cloud to retrieve * session traces, conversation turns, messages, and steps for issue analysis. * * Deployed once per org by the agentforce-optimize skill (Phase 1 setup). * All public methods accept dataSpaceName so no Data Space is hardcoded. * * Methods: * findSessions(dataSpaceName, startIso, endIso, maxRows) → JSON List<SessionSummary> * findSessions(dataSpaceName, startIso, endIso, maxRows, agentName) → JSON List<SessionSummary> * getConversationDetails(dataSpaceName, sessionId) → JSON ConversationData * getMultipleConversationDetails(dataSpaceName, sessionIds) → JSON List<ConversationData> * getLlmStepDetails(dataSpaceName, stepIds) → JSON List<LlmStepDetail> * getMomentInsights(dataSpaceName, sessionIds) → JSON List<SessionInsights> * getAggregatedMetrics(dataSpaceName, startIso, endIso, maxRows, agentName) → JSON AggregatedMetrics * runObservabilityQuery(List<ObservabilityInput>) → List<ObservabilityOutput> (@InvocableMethod) */ public with sharing class AgentforceOptimizeService { // ========================================================================= // Output wrappers // ========================================================================= /** Lightweight session record returned by findSessions(). */ public class SessionSummary { public String session_id; public String start_time; public String end_time; public String channel; public Long duration_ms; /** How the session ended: e.g. USER_ENDED, AGENT_ENDED (null = in progress or not recorded) */ public String end_type; } /** A single user/agent message within a turn. */ public class MessageData { public String message_id; /** 'Input' (user) or 'Output' (agent) — raw STDM value */ public String message_type; public String text; public String sent_at; } /** * A single internal step within a turn. * All issue-detection fields are included: * - error → non-null means ACTION_STEP failure (P1) * - pre_vars / post_vars → null delta means variable not captured (P2) * - duration_ms > 10 000 → slow action (P3) * - generation_id → non-null on LLM_STEP; use getLlmStepDetails() to get the prompt */ public class StepData { public String step_id; /** TOPIC_STEP | LLM_STEP | ACTION_STEP | SESSION_END | TRUST_GUARDRAILS_STEP */ public String step_type; public String name; public String start_time; public String end_time; public Long duration_ms; /** Raw input to the step (JSON for ACTION_STEP; Python dict string for LLM_STEP) */ public String input; /** Raw output from the step (JSON for ACTION_STEP; Python dict string for LLM_STEP) */ public String output; /** Non-null indicates the step threw an error (only ACTION_STEP counts toward action_error_count) */ public String error; /** Variable snapshot before this step (null when NOT_SET) */ public String pre_vars; /** Variable snapshot after this step (null when NOT_SET) */ public String post_vars; /** GenAiGeneration ID — non-null on LLM_STEP; pass to getLlmStepDetails() for full prompt/response */ public String generation_id; /** GenAiGatewayRequest ID — non-null on LLM_STEP; links to raw gateway request */ public String gateway_request_id; } /** * One conversational turn (AiAgentInteraction of type TURN). * Contains all messages and steps for that turn. */ public class TurnData { public String in