Skip to content

W-22203672: add hidden --agent-json flag to agent preview start#405

Merged
EstebanRomero84 merged 15 commits intomainfrom
ar/W-22203672/agent-json-flag-preview-start
May 4, 2026
Merged

W-22203672: add hidden --agent-json flag to agent preview start#405
EstebanRomero84 merged 15 commits intomainfrom
ar/W-22203672/agent-json-flag-preview-start

Conversation

@andresrivas-sf
Copy link
Copy Markdown
Contributor

Summary

@W-22203672@

  • Add hidden --agent-json flag to sf agent preview start accepting a file path to a pre-compiled AgentJSON
  • When provided, passes the parsed JSON to ScriptAgent via ScriptAgentOptions, skipping the compile step
  • Adds loadAgentJson() helper to keep run() complexity within lint limits
  • Add 2 new unit tests: happy path (parsed JSON passed to Agent.init) and error path (invalid JSON throws AgentJsonReadError)

Dependencies

Depends on forcedotcom/agents#271@salesforce/agents must be bumped after that merges.

Test plan

  • yarn test:only passes (244 tests)
  • Manually run sf agent preview start --authoring-bundle MyAgent --simulate-actions --agent-json /path/to/compiled.json --target-org myOrg and confirm session starts without a compile request

🤖 Generated with Claude Code

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>
@andresrivas-sf andresrivas-sf requested a review from a team as a code owner April 28, 2026 17:22
Comment thread messages/agent.preview.start.md Outdated
Copy link
Copy Markdown
Contributor

@jshackell-sfdc jshackell-sfdc left a comment

Choose a reason for hiding this comment

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

see my small suggestion.

Co-authored-by: Juliet Shackell <63259011+jshackell-sfdc@users.noreply.github.com>
@EstebanRomero84
Copy link
Copy Markdown
Contributor

@andresrivas-sf few comments:

  • agentJSON is used only used when --authoring-bundle flag is used so can you add a dependsOn attribute i the new flag?
  • Should the new feature be also available in agent preview command?
  • Please add a NUT.

Comment thread src/commands/agent/preview/start.ts Outdated
throw new SfError(
`Failed to read or parse --agent-json file '${filePath}': ${SfError.wrap(error).message}`,
'AgentJsonReadError'
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can you add telemetry logging similar to line 120?

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>
andresrivas-sf and others added 2 commits April 29, 2026 12:36
W-22203672

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

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@EstebanRomero84
Copy link
Copy Markdown
Contributor

QA Notes

Flag is hidden:
sf agent preview --help and sf agent preview start --help don't show the --agent-json flag ✅
sf agent preview and sf agent preview start accept the --agent-json flag ✅

When passing an invalid file path the commands display correct error message ✅

When passing a agentJSON using the --agent-json flag, the commands don't call the v1.1/authoring/scripts endpoint to obtain the corresponding agentJSON. I verified it by modifying the original agent script file to have a syntax error. Since the preview session is generated successfully it means the command is using the provided agentJSON. ✅

andresrivas-sf and others added 10 commits April 30, 2026 17:16
…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>
@EstebanRomero84 EstebanRomero84 merged commit a809026 into main May 4, 2026
13 checks passed
@EstebanRomero84 EstebanRomero84 deleted the ar/W-22203672/agent-json-flag-preview-start branch May 4, 2026 13:40
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.

3 participants