Skip to content

[Agent Builder] Add new property to public events contract to filter events by conversation id#268440

Merged
chrisbmar merged 4 commits into
elastic:mainfrom
chrisbmar:ab-expose-stream-events-public-contract-14381
May 11, 2026
Merged

[Agent Builder] Add new property to public events contract to filter events by conversation id#268440
chrisbmar merged 4 commits into
elastic:mainfrom
chrisbmar:ab-expose-stream-events-public-contract-14381

Conversation

@chrisbmar
Copy link
Copy Markdown
Contributor

Summary

closes https://github.com/elastic/search-team/issues/14381

What changed

  • Added events.getChatEvents$(conversationId) to the public events contract — returns a hot observable scoped to one conversation.
  • Deprecated events.chat$ (kept for backward compatibility) it interleaves events from every concurrent conversation and consumers can't reliably attribute them right now if there are multiple streams (low chance of this being the case, we haven't broadcasted the fact that concurrent streams are possible in the Agent Builder UI yet).
  • Internal events bus now tags every event with its conversationId at propagation time; chat$ strips the tag for shape-parity.

Why

  • After enabling concurrent per-conversation streams, the public chat$ became conflated - consumers (dashboard_agent, workflows_management) can no longer tell which conversation an event came from i_f there are multiple streams at the one time_.
  • Most chat event payloads don't carry conversation_id, so consumers can't filter on the payload alone.
  • getChatEvents$(id) gives them clean per-conversation scoping without a breaking change. Migration is one-line per call site (recommendations in the contract docstring + CONTRIBUTOR_GUIDE.md).

Logs
image

@chrisbmar chrisbmar self-assigned this May 8, 2026
@chrisbmar chrisbmar requested a review from a team as a code owner May 8, 2026 13:28
@chrisbmar chrisbmar added release_note:fix backport:skip This PR does not require backporting labels May 8, 2026
Copy link
Copy Markdown
Contributor

@pgayvallet pgayvallet left a comment

Choose a reason for hiding this comment

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

LGTM, just 2 comments

Comment on lines +109 to +112
// Every Agent Builder UI caller passes a client-generated UUID before chat fires.
// The fallback to `''` is defensive only - events with that tag won't reach any
// per-conversation subscriber but still flow through the deprecated `obs$` stream.
const conversationId = payload.conversation_id ?? '';
Copy link
Copy Markdown
Contributor

@pgayvallet pgayvallet May 11, 2026

Choose a reason for hiding this comment

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

If we always pass an id when calling that API now, can we fix the type instead of doing this defaulting to empty string?

the payload: ChatRequestBodyPayload second param

would become (but please not inlined)

payload: ChatRequestBodyPayload & { conversation_id: string } // conversation_id is required here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

great feedback, much better way of handling it - 84556c6

@chrisbmar chrisbmar enabled auto-merge (squash) May 11, 2026 06:56
@kibanamachine
Copy link
Copy Markdown
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Scout Lane #20 - serverless-search / agent_builder / local-serverless-search - Agent Builder — conversation error handling - keeps the previous conversation rounds visible when there is an error

Metrics [docs]

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
agentBuilder 47.0KB 47.3KB +242.0B
Unknown metric groups

API count

id before after diff
@kbn/agent-builder-browser 110 112 +2

References to deprecated APIs

id before after diff
agentBuilder 56 58 +2
dashboardAgent 2 4 +2
workflowsManagement 30 32 +2
total +6

Unreferenced deprecated APIs

id before after diff
agentBuilder 56 58 +2
dashboardAgent 2 4 +2
workflowsManagement 30 32 +2
total +6

History

cc @chrisbmar

@chrisbmar chrisbmar merged commit ad015fa into elastic:main May 11, 2026
45 checks passed
clintandrewhall pushed a commit that referenced this pull request May 12, 2026
mbondyra added a commit that referenced this pull request May 12, 2026
…tion (#268766)

## Summary

Rewrite after merging #268440

Migrates Dashboard Agent off the deprecated shared
`agentBuilder.events.chat$` stream and onto the new per-conversation
`agentBuilder.events.getChatEvents$(conversationId)` API.

This prevents dashboard live updates from reacting to events emitted by
other concurrent Agent Builder conversations and adjusts our code to the
new api.
patrykkopycinski pushed a commit to patrykkopycinski/kibana that referenced this pull request May 13, 2026
patrykkopycinski pushed a commit to patrykkopycinski/kibana that referenced this pull request May 13, 2026
…tion (elastic#268766)

## Summary

Rewrite after merging elastic#268440

Migrates Dashboard Agent off the deprecated shared
`agentBuilder.events.chat$` stream and onto the new per-conversation
`agentBuilder.events.getChatEvents$(conversationId)` API.

This prevents dashboard live updates from reacting to events emitted by
other concurrent Agent Builder conversations and adjusts our code to the
new api.
jcger pushed a commit that referenced this pull request May 26, 2026
…tion (#268766)

## Summary

Rewrite after merging #268440

Migrates Dashboard Agent off the deprecated shared
`agentBuilder.events.chat$` stream and onto the new per-conversation
`agentBuilder.events.getChatEvents$(conversationId)` API.

This prevents dashboard live updates from reacting to events emitted by
other concurrent Agent Builder conversations and adjusts our code to the
new api.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting release_note:fix v9.5.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants