Skip to content

@W-22167805@ add sf agent trace read command#411

Merged
WillieRuemmele merged 49 commits intowr/deleteTracesfrom
wr/readTraces
May 8, 2026
Merged

@W-22167805@ add sf agent trace read command#411
WillieRuemmele merged 49 commits intowr/deleteTracesfrom
wr/readTraces

Conversation

@WillieRuemmele
Copy link
Copy Markdown
Contributor

Work Item

@W-22167805@

Summary

Adds the sf agent trace read command for reading and analyzing trace files from an agent preview session. No org connection required.

Changes

  • New command: sf agent trace read
  • Flags: --session-id (required), --format (summary|detail|raw, default: summary), --dimension (actions|grounding|routing|errors, required with --format detail), --turn (scope to a single turn)
  • --format summary: per-turn table showing topic, user input, agent response, actions executed, latency, errors
  • --format detail: dimension-specific drill-down (actions, grounding, routing, errors)
  • --format raw: prints unprocessed trace JSON
  • --turn N: scopes any format to a single conversation turn via turn-index.json
  • Falls back to listSessionTraces file order when no turn index exists
  • Messages: messages/agent.trace.read.md
  • Schema and snapshot updated

Files Changed

  • src/commands/agent/trace/read.ts
  • messages/agent.trace.read.md
  • schemas/agent-trace-read.json
  • command-snapshot.json
  • test/commands/agent/trace/read.test.ts

Test Plan

  • 24 unit tests passing
  • npm run build and npm test pass cleanly
  • Schema and deprecation snapshot regenerated

Dependencies

sreckomileta and others added 13 commits April 27, 2026 11:48
W-22203672

Adds a hidden --agent-json flag that accepts a file path to a
pre-compiled AgentJSON, bypassing the compile step in ScriptAgent.
Intended for internal developer testing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Juliet Shackell <63259011+jshackell-sfdc@users.noreply.github.com>
W-22203672

- Apply jshackell's wording suggestion for flag summary
- Add dependsOn authoring-bundle to --agent-json flag
- Add telemetry for AgentJsonReadError
- Add --agent-json flag to interactive agent preview command
- Add NUT tests for --agent-json flag

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
W-22203672

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
W-22203672

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@WillieRuemmele WillieRuemmele requested a review from a team as a code owner April 30, 2026 20:53
WillieRuemmele and others added 16 commits April 30, 2026 15:14
…PI call

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…and instanceof narrowing

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The static fixture had an empty defaultAgentUser, causing bypassUser to
resolve to false and the preview sessions API to reject the request.
Patch it at runtime with the real agent user from the shared test session,
matching what the compile-then-start path does via string replacement.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The preview sessions API rejected "AgentforceAgent" with HTTP 400
"Define a valid value for ''agent_type''". Updated to "customer" which
matches the AgentType union type in @salesforce/agents.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
"customer" was also rejected by the preview sessions API. The unit test
for --agent-json uses "AgentforceServiceAgent", which matches the value
the compile API returns for service-type agents.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…agents to 1.4.0

The preview sessions API rejected all prior agentType values. The
bot-meta.xml for the test project's service agent uses "EinsteinServiceAgent",
which matches what the compile API returns for this agent type.

Also bumps @salesforce/agents to 1.4.0.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Setting defaultAgentUser to a valid org user made bypassUser=true, which
caused the preview sessions API to validate permission sets that aren't
assigned, resulting in a 500. An empty defaultAgentUser keeps bypassUser=false
and skips that check entirely.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
A static fixture's agentVersion is rejected by the preview sessions API
with a 500. Compile the agent at test time via Agent.init+compile(), write
the real compiledArtifact to a temp file, and pass that as --agent-json.
This tests the flag plumbing while ensuring the body is API-compatible.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Bumps [yaml](https://github.com/eemeli/yaml) from 2.8.3 to 2.8.4.
- [Release notes](https://github.com/eemeli/yaml/releases)
- [Commits](eemeli/yaml@v2.8.3...v2.8.4)

---
updated-dependencies:
- dependency-name: yaml
  dependency-version: 2.8.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
…ml-2.8.4

fix(deps): bump yaml from 2.8.3 to 2.8.4
…lag-preview-start

W-22203672: add hidden --agent-json flag to agent preview start
npiccolo and others added 14 commits May 4, 2026 12:56
@W-22203670 feat: add --verbose and --concise flags to agent publish authoring-bundle
…o @salesforce/agents

W-22203426

Removes local copies of evalNormalizer, evalFormatter, and yamlSpecTranslator
now that they live in the shared library. Rewrites run-eval.ts as a thin CLI
shell that imports normalizePayload, translateTestSpec, resolveAgent,
executeBatches, buildResultSummary, and formatResults from @salesforce/agents.
Promotes the command from state='beta'/hidden to state='ga'.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Remove state='ga' (GA commands omit state to avoid oclif help regression)
- Remove unused --wait flag
- Wrap parseTestSpec/translateTestSpec in try/catch for named SfError
- Validate test.steps is an array before injection loop
- Hoist isYamlTestSpec to avoid double-call
- Extract resolveAndInjectAgent helper to stay within complexity limit
- Fix test stubs to use $$.SANDBOX, remove sinon.restore(), fix describe label

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…emoval

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Wr/ngt @W-22143479@ @W-22143478@
Six NUT cases asserted ensureExitCode: 1 but the commands fail at
oclif flag-parse time (Flags.file({ exists: true }), parse callbacks
that throw, validate callbacks, and missing required flags), which
exits with code 2. Update the assertions to match.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
The exit code for these oclif parse failures differs by sf-plugins-core
version: 12.2.6 (bundled in CLI 2.135.0) emits 2, while 12.2.13 (used
in plugin-agent's own CI) catches the parse error and re-emits exit 1.
Use 'nonZero' so the assertion is correct in both environments.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
fix: expect oclif parse exit code 2 for invalid-input NUTs @W-22403352
…or-to-library

W-22203426: feat: promote agent test run-eval to GA and delegate logic to @salesforce/agents
@sreckomileta
Copy link
Copy Markdown
Contributor

QA Release Notes: Agent Trace Read Command

The functionality of the new sf agent trace read command was verified across all supported parameters and flags. All test cases passed successfully.

🧪 Test Scenarios

Test Case Command Result
Session Filter sf agent trace read --session-id <id> ✅ Pass
Summary Format sf agent trace read --format summary ✅ Pass
Raw Format sf agent trace read --format raw ✅ Pass
Detail Format w/ routing dim sf agent trace read --format detail --dimension routing ✅ Pass
Detail Format w/ errors dim sf agent trace read --format detail --dimension errors ✅ Pass
Turn Filter sf agent trace read --turn <number> ✅ Pass

⚠️ Observation: Misleading Error Message

During negative testing (providing an invalid --session-id), a discrepancy was found in the error suggestion:

  • Action: Ran sf agent trace read --session-id <invalid_id>
  • Actual Error Message: ...Run "sf agent trace list" to see available sessions.
  • Issue: The suggested command sf agent trace list is incorrect. The actual command is sf agent preview trace list.
  • Recommendation: Update the error message output to reference the correct command.

Final Verdict: PASS WITH OBSERVATIONS (Logic is correct, but UI/UX needs a fix).

@sreckomileta sreckomileta self-requested a review May 8, 2026 13:03
Copy link
Copy Markdown
Contributor

@sreckomileta sreckomileta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sreckomileta
Copy link
Copy Markdown
Contributor

@WillieRuemmele I've noticed a small typo in the error message. When the session ID is incorrect, the command-line interface suggests running sf agent trace list, but the current command is sf agent preview trace list. Could you please verify this? Thank you!

@WillieRuemmele
Copy link
Copy Markdown
Contributor Author

@sreckomileta - the command/message is correct, it's

 ../../oss/plugin-agent/bin/run.js agent trace list 
┌───────────────────┬──────────────────────────────────────┬──────────────────────────────────────┬──────────────────────────┬────────┬───────┐
│ Agent             │ Session ID                           │ Plan ID                              │ Recorded At              │ Size   │ Path  │
├───────────────────┼──────────────────────────────────────┼──────────────────────────────────────┼──────────────────────────┼────────┼───────┤
│ Local_Info_Agent  │ 85b4d4c5-956e-4bc0-b952-8ea162ac3b22 │ 9e21ae60-98d4-41a4-b1dd-4b5a9df994a5 │ 2026-04-07T18:32:45.183Z │ 17581B │ /Use… │

…written to the project dir

Without cwd, preview start/send/end wrote the session cache relative to the runner's working
directory, causing trace read/delete NUTs to throw SessionNotFound when they ran with
cwd: session.project.dir.
listCachedPreviewSessions only returns sessions still in the index, but
agent preview end removes the entry when it cleans up the active-session
marker. Both trace read and trace delete now fall back to a filesystem
scan of .sfdx/agents/<agentId>/sessions/ so they work on ended sessions.
When sessions are run with --simulate-actions, the turn index exists but
planId entries are null. --turn N now falls back to positional trace file
order rather than throwing TurnIndexNotFound. Also relaxes the grounding
NUT assertion since simulated sessions may not produce LLMExecutionStep
rows with React prompt names.
@WillieRuemmele WillieRuemmele merged commit 1011ea2 into wr/deleteTraces May 8, 2026
13 checks passed
@WillieRuemmele WillieRuemmele deleted the wr/readTraces branch May 8, 2026 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants