Skip to content

[onechat] add tool progression events#233724

Merged
joemcelroy merged 9 commits intoelastic:mainfrom
pgayvallet:onechat-10841-tool-progression-events
Sep 5, 2025
Merged

[onechat] add tool progression events#233724
joemcelroy merged 9 commits intoelastic:mainfrom
pgayvallet:onechat-10841-tool-progression-events

Conversation

@pgayvallet
Copy link
Contributor

@pgayvallet pgayvallet commented Sep 2, 2025

Summary

Fix https://github.com/elastic/search-team/issues/10841

  • Add a new tool_progression type of event
export interface ToolProgressEventData {
  tool_call_id: string;
  message: string;
}
  • Change the structure of persisted tool calls to include a list of progression events
  • Expose a dedicated event emitter to tool handlers for them to send progression events
  • Add example of such events for the .search tool
Screenshot 2025-09-02 at 20 09 15

@pgayvallet
Copy link
Contributor Author

/ci

@pgayvallet pgayvallet added release_note:skip Skip the PR/issue when compiling release notes backport:skip This PR does not require backporting v9.2.0 labels Sep 2, 2025
@pgayvallet
Copy link
Contributor Author

/ci

1 similar comment
@pgayvallet
Copy link
Contributor Author

/ci

Copy link
Contributor Author

@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.

self-review

/**
* Defines all possible types for round steps.
*/
export type ConversationRoundStep<T = ToolResult[]> = ToolCallStep<T> | ReasoningStep;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Out of the scope of the issue, but I took the opportunity to remove the arguably not useful generics around conversation round types.

Comment on lines +45 to +48
export interface ToolProgressEventData {
tool_call_id: string;
message: string;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The new tool_progress event, having the tool_call_id to be able to identify which tool call it's attached to (similar to tool_result events), and a plain text message.

We can make that evolve into something more structured later, but for now, simpler is better, and full text is gonna be fine ihmo.

Comment on lines +107 to +108
if (sendEvent) {
const toolCallId = config.configurable?.tool_call_id ?? config.toolCall?.id ?? 'unknown';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one took time to find, but we do have the info of the tool_call_id within langchain wrappers, so we can "automatically" attach it to the underlying tool events.

const toolNode = new ToolNode<typeof StateAnnotation.State.messages>(tools);

const selectAndValidateIndex = async (state: StateType) => {
events?.reportProgress(progressMessages.selectingTarget());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Example of reporting progress for the search tool

Comment on lines -15 to -16
/** ID of this run */
runId: string;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was not being useful in any way after 6 months (it was meant to be used as "traceId" but we are using OTel directly for that now...), so removed it

Comment on lines +62 to +72
'results' in step
? JSON.parse(step.results).map((result: ToolResult) => {
if (step.type === ConversationRoundStepType.toolCall) {
return {
...step,
progression: step.progression ?? [],
};
}
return step;
})
: [],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We'll switch to a more "elegant" way of populating non-backfilled fields later. But the idea is to add that progression: [] attribute during deserialization instead of making it optional on our domain model.

@pgayvallet pgayvallet marked this pull request as ready for review September 2, 2025 18:45
@pgayvallet pgayvallet requested a review from a team as a code owner September 2, 2025 18:45
Copy link
Contributor

@jedrazb jedrazb left a comment

Choose a reason for hiding this comment

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

Only one question about ser/de progression, how can i validate that this works? would ftr tests cover this?

? JSON.parse(step.results).map((result: ToolResult) => {
if (step.type === ConversationRoundStepType.toolCall) {
return {
...step,
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we return step (outer object) instead of result in the map function? result is not used anywhere which feels like a bug?

I'm lost why we are mixing up results, step and progression under results, while in the ToolCallWithResult results and progression are on the same level

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it's definitely a bug, nice catch. I did too many things refactoring what Soren did while adding that backfilling for the progress array... I'll fix that, thank you

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in fa9770e

@pgayvallet pgayvallet force-pushed the onechat-10841-tool-progression-events branch from 5b160c7 to 2f5bcf8 Compare September 4, 2025 07:27
@pgayvallet pgayvallet requested a review from jedrazb September 4, 2025 07:28
@pgayvallet
Copy link
Contributor Author

Only one question about ser/de progression, how can i validate that this works? would ftr tests cover this?

We can't have FTR tests for anything leveraging the chat API / an LLM atm, unfortunately.

How I tested was:

  1. I look at the converse/async SSE response from the debugger console, and observe we are emitting the tool_progress events
  2. once the current round is over, I check the call reloading the conversation to make sure that the progression array is populated in the round's tool call

Copy link
Contributor

@jedrazb jedrazb left a comment

Choose a reason for hiding this comment

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

LGTM

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/onechat-common 161 167 +6
@kbn/onechat-genai-utils 103 104 +1
total +7

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
onechat 829.0KB 829.0KB +31.0B

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
@kbn/onechat-server 2 4 +2
Unknown metric groups

API count

id before after diff
@kbn/onechat-common 243 252 +9
@kbn/onechat-genai-utils 115 116 +1
@kbn/onechat-server 127 126 -1
total +9

History

@joemcelroy
Copy link
Member

tested works well!

@joemcelroy joemcelroy merged commit 2e77415 into elastic:main Sep 5, 2025
12 checks passed
shahargl pushed a commit to shahargl/kibana that referenced this pull request Sep 7, 2025
## Summary

Fix elastic/search-team#10841

- Add a new `tool_progression` type of event

```ts
export interface ToolProgressEventData {
  tool_call_id: string;
  message: string;
}
```

- Change the structure of persisted tool calls to include a list of
progression events
- Expose a dedicated event emitter to tool handlers for them to send
progression events
- Add example of such events for the `.search` tool

<img width="944" height="303" alt="Screenshot 2025-09-02 at 20 09 15"
src="https://github.com/user-attachments/assets/776a7b13-9d68-4255-9a5c-d27189db208e"
/>

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
KodeRad pushed a commit to KodeRad/kibana that referenced this pull request Sep 15, 2025
## Summary

Fix elastic/search-team#10841

- Add a new `tool_progression` type of event

```ts
export interface ToolProgressEventData {
  tool_call_id: string;
  message: string;
}
```

- Change the structure of persisted tool calls to include a list of
progression events
- Expose a dedicated event emitter to tool handlers for them to send
progression events
- Add example of such events for the `.search` tool

<img width="944" height="303" alt="Screenshot 2025-09-02 at 20 09 15"
src="https://github.com/user-attachments/assets/776a7b13-9d68-4255-9a5c-d27189db208e"
/>

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Sep 24, 2025
## Summary

Fix elastic/search-team#10841

- Add a new `tool_progression` type of event

```ts
export interface ToolProgressEventData {
  tool_call_id: string;
  message: string;
}
```

- Change the structure of persisted tool calls to include a list of
progression events
- Expose a dedicated event emitter to tool handlers for them to send
progression events
- Add example of such events for the `.search` tool

<img width="944" height="303" alt="Screenshot 2025-09-02 at 20 09 15"
src="https://github.com/user-attachments/assets/776a7b13-9d68-4255-9a5c-d27189db208e"
/>

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
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:skip Skip the PR/issue when compiling release notes v9.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants