Skip to content

feat(chat): support agentId to auto-select persona - #462

Closed
anfibiacreativa wants to merge 7 commits into
mainfrom
feat/chat-agent-id
Closed

anfibiacreativa wants to merge 7 commits into
mainfrom
feat/chat-agent-id

Conversation

@anfibiacreativa

Copy link
Copy Markdown
Member

Summary

  • Add agent-id attribute to NxChat so embedding contexts can specify which persona the chat uses
  • Pass agentId in the request body to da-agent for automatic preset resolution

Why

  • The skills editor needs a specialized "senior AI engineer" persona instead of the default content-writer
  • Persona selection should be automatic based on the embedding context, not a manual user action

What Changed

  • nx2/blocks/chat/chat-controller.js: new setAgentId(id) method; includes agentId in POST body when set
  • nx2/blocks/chat/chat.js: new agentId LitElement property (reflected as agent-id attribute); forwards to controller on connect and on property change via updated() lifecycle

Security

  • agentId is not sensitive (it's a preset identifier like "skills-engineer")
  • Server-side SAFE_AGENT_ID regex in da-agent prevents path traversal regardless of what the client sends
  • DOM manipulation of the attribute only affects the user's own session

Test Plan

  • Load skills editor, open chat — verify request body includes "agentId": "skills-engineer"
  • Confirm chat without agent-id attribute still works (no agentId field in body)
  • Verify changing agent-id at runtime updates the controller
  • Verify no agentId field when attribute is absent (not sent as empty string or null)

Risks / Follow-ups

  • Requires corresponding da-agent PR (feat/builtin-agent-presets) to take effect
  • No breaking change — field is optional and ignored by older agent versions

Pass an optional agent-id attribute through NxChat → ChatController
so the request body includes agentId, allowing da-agent to resolve
a built-in or content-bus preset automatically.

Co-authored-by: Cursor <cursoragent@cursor.com>
@aem-code-sync

aem-code-sync Bot commented May 22, 2026 •

Copy link
Copy Markdown

Hello, I'm the AEM Code Sync Bot and I will run some actions to deploy your branch.
In case there are problems, just click the checkbox below to rerun the respective action.

  • Re-sync branch
Commits

@mhaack

mhaack commented May 22, 2026 •

Copy link
Copy Markdown
Contributor

LGTM, but looks like you used an older main. Can you fix the conflicts.

Co-authored-by: Cursor <cursoragent@cursor.com>
@aem-code-sync
aem-code-sync Bot temporarily deployed to feat/chat-agent-id May 26, 2026 10:47 Inactive
@anfibiacreativa

Copy link
Copy Markdown
Member Author

LGTM, but looks like you used an older main. Can you fix the conflicts.

Conflict is solved

mhaack
mhaack previously approved these changes May 26, 2026
Comment thread nx2/blocks/chat/chat.js Outdated
thinking: { type: Boolean },
connected: { type: Boolean },
toolCards: { type: Object },
agentId: { type: String, attribute: 'agent-id' },

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.

Since this isnt used for rendering, why do we need to add it to the properties? Why not instead use getAttribute to pass it on?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good question, if agent-id stays purely as a one-time backend config, getAttribute() would be a reasonable simplification. My reasoning tho, and why I decided to go with a Lit property is because we may expect it to be a real component input: it already affects controller behavior, and it may also drive agent-specific UI/rendering later (I envision cases where the renderers are different per agent id). In that case, declaring it in static properties is the more idiomatic Lit pattern.

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.

Agreed for the future, but I would recommend holding off until we actually use it for rendering. Pre-emptively adding it means we re-render the component today for agentid changes for no benefit.

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.

+1 lets add this later if needed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done, dropped it from the reactive properties. we read agent-id once via getAttribute in connectedCallback now and removed the updated() handler, so no re-render on agent-id changes. happy to bring it back as a reactive prop if/when we actually drive rendering off it.

@sharanyavinod

Copy link
Copy Markdown
Contributor

Please update the doc for any and all changes in the contract

@anfibiacreativa

anfibiacreativa commented May 27, 2026 •

Copy link
Copy Markdown
Member Author

Please update the doc for any and all changes in the contract

@sharanyavinod could you clarify which doc you suggest updated? on the da-nx side, this PR adds an optional agent-id attribute to and passes it through to the agent request. The backend contract for the new agentId request field is defined in the da-agent builtin-agent-presets PR, so I am not sure if you're asking for docs on the component API here or the agent request contract there. If helpful, I can also add a short comment/doc note here that agent-id is an optional embedding-time hint forwarded to the agent backend.

@sharanyavinod

Copy link
Copy Markdown
Contributor

Please update the doc for any and all changes in the contract

@sharanyavinod could you clarify which doc you suggest updated?

Here https://github.com/adobe/da-nx/blob/main/docs/chat-ui-component.md - just to ensure the contracts there are up to date and any stale info is removed

anfibiacreativa and others added 2 commits July 8, 2026 15:46
- read agent-id via getAttribute at mount instead of a reactive Lit property, avoiding needless re-renders when it changes
- drop the updated() handler for agentId; the value is read once before mount
- document the agent-id attribute and its request-body contract in chat-ui-component.md

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@anfibiacreativa

Copy link
Copy Markdown
Member Author

Please update the doc for any and all changes in the contract

@sharanyavinod could you clarify which doc you suggest updated?

Here https://github.com/adobe/da-nx/blob/main/docs/chat-ui-component.md - just to ensure the contracts there are up to date and any stale info is removed

updated docs/chat-ui-component.md, added an "Attributes in" section for agent-id and noted it's sent as agentId in the request body when set.

@aem-code-sync
aem-code-sync Bot temporarily deployed to feat/chat-agent-id July 14, 2026 09:42 Inactive
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

Checking in on this PR. It has been quiet for a while, so we have labeled it stale to keep it on our radar. Are you still working on it, or waiting on us? A comment or a new commit keeps it open. If the delay is on our side, that is on us. We will post a final notice before it would close.

@github-actions github-actions Bot added the stale label Sep 8, 2026
@github-actions

Copy link
Copy Markdown

Final notice: this pull request will close in about 7 day(s) unless there is a reply or a new commit. If it is still relevant, just comment or remove the stale label. If you were waiting on us, say so and we will pick it up.

@anfibiacreativa
anfibiacreativa deleted the feat/chat-agent-id branch October 8, 2026 13:30

This branch was successfully deployed

1 active deployment
feat/chat-agent-id — 23914790 Deployed Jul 14, 2026 by aem-code-sync[bot]
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.

4 participants