[Workflows] support passing attachments to run_agent step#251291
[Workflows] support passing attachments to run_agent step#251291KDKHD merged 15 commits intoelastic:mainfrom
Conversation
pgayvallet
left a comment
There was a problem hiding this comment.
Feature makes sense, thanks for adding that.
There's only one thing we need to address, about attachment validation - added a specific comment below.
| outputSchema: schema, | ||
| nextInput: { | ||
| message, | ||
| attachments, |
There was a problem hiding this comment.
We're going to have a problem with the way attachment validation currently work.
Atm, validation is done in the converse route handler directly (which is pretty bad - agreed). This was "fine" because before this PR, the converse API was the only entry point for attachments, so for their validation.
kibana/x-pack/platform/plugins/shared/agent_builder/server/routes/chat.ts
Lines 172 to 189 in f2c007b
So passing attachments directly to chatService.converse as done here bypass this validation.
But now we need to find a way to address that, either by:
- moving the validation which is currently living in the
converseroute handler a few layers down, either inchatServiceor even lower in the chain, so that we hit the attachment validation when calling an agent via that workflow step (probably the most robust way, even if more work - there might be a few type issues between Attachment vs AttachmentInput) - extract / re-use the logic we use from the route handler in the step definition - move that
validateAttachmentsliving in the handler file elsewhere, and then re-use it from the step definition (I would be fine with that too) - re-use the "attachment state manager" we use for the attachment routes (
x-pack/platform/plugins/shared/agent_builder/server/routes/attachments.ts). It doesn't have an API for validation atm, but it has an internalvalidateAttachmentDatafunction. we could add a new public "validateAttachment" which would reproduce the logic of what we do in validateAttachments` in the converse route handler today, and then use this in the step definition and in the route (seems like a good compromise)
Fine with either, you can pick.
There was a problem hiding this comment.
Moved into ExecutionService since ChatService has been removed.
|
@elasticmachine merge upstream |
|
merge conflict between base and head |
…w_run_agent_attachments
| ), | ||
| }); | ||
|
|
||
| const validateAttachments = async ({ |
There was a problem hiding this comment.
Moved attachment validation down into the execution service.
…w_run_agent_attachments
…DKHD/kibana into feature/workflow_run_agent_attachments
|
@elasticmachine merge upstream |
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Page load bundle
Unknown metric groupsReferences to deprecated APIs
Unreferenced deprecated APIs
History
|
…ps-config-rebase * commit 'f135f030951237c5e9b0251931441aee3121b31d': (163 commits) [CPS] Support data view requests and do not sanitize project_routing in data plugin/resolve indices (elastic#253654) [One Workflow] Execute workflow from historical (elastic#253396) [streams][background tasks] gracefully handle non existing stream (elastic#254683) [Lens API] Waffle/Mosaic get green as a default color (elastic#254304) [Security Solution] Remove prebuilt rules customization callout on Rule Management page (elastic#254386) [Workflows] support passing attachments to run_agent step (elastic#251291) [One Discover][Logs UX] Update OpenTelemetry Semantic Conventions (elastic#254367) [kbn-es] Add --docker flag to yarn es snapshot (elastic#254306) [Workplace AI] Remove Data Source Config (elastic#254521) [Entity Store v2] Add CRUD API (elastic#252052) [CI] Increase type checking machine (elastic#254676) [main] Sync bundled packages with Package Storage (elastic#254232) Skip flaky test elastic#254625 (elastic#254662) Upgrade `@elastic/elasticsearch` to 9.3.1 (elastic#253660) [One Workflow] Migrate http step to new connector (elastic#249004) [Entity Store] Store EUID Scripts (elastic#254515) [APM] Fix Otel missing fields undefined errors (elastic#254271) [Console] Add support for documentation links on Serverless (elastic#254489) Create edit ILM flow (elastic#253393) [Agent Builder] Mid term: minimal recommended model set elastic#12875 (elastic#254560) ...
…1291) ## Summary Summarize your PR. If it involves visual changes include a screenshot or gif. Add support for passing attachments to the run agent step in workflows. <img width="3355" height="1040" alt="image" src="https://github.com/user-attachments/assets/1890761d-6e17-4746-b9fd-0b40e89983a8" /> <img width="2180" height="615" alt="image" src="https://github.com/user-attachments/assets/60f1675b-89a8-4fb5-9c14-0ce16efdb0ff" /> Example workflow with alert attachment ``` name: New workflow enabled: false description: This is a new workflow triggers: - type: alert steps: - name: ai_agent_step type: ai.agent connector-id: "<connector_id>" with: message: "Summarise these alert" attachments: - type: security.alert data: alert: "{{event.alerts | json:2}}" attachmentLabel: "Alert attachment." ``` PR also moves attachment validation down into ExecutionService so that attachments passed via workflows are validated. ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [X] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md) - [X] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [X] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [X] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [X] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [X] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [X] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) - [X] Review the [backport guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing) and apply applicable `backport:*` labels. ### Identify risks Does this PR introduce any risks? For example, consider risks like hard to test bugs, performance regression, potential of data loss. Describe the risk, its severity, and mitigation for each identified risk. Invite stakeholders and evaluate how to proceed before merging. - [ ] [See some risk examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) - [ ] ... --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
…1291) ## Summary Summarize your PR. If it involves visual changes include a screenshot or gif. Add support for passing attachments to the run agent step in workflows. <img width="3355" height="1040" alt="image" src="https://github.com/user-attachments/assets/1890761d-6e17-4746-b9fd-0b40e89983a8" /> <img width="2180" height="615" alt="image" src="https://github.com/user-attachments/assets/60f1675b-89a8-4fb5-9c14-0ce16efdb0ff" /> Example workflow with alert attachment ``` name: New workflow enabled: false description: This is a new workflow triggers: - type: alert steps: - name: ai_agent_step type: ai.agent connector-id: "<connector_id>" with: message: "Summarise these alert" attachments: - type: security.alert data: alert: "{{event.alerts | json:2}}" attachmentLabel: "Alert attachment." ``` PR also moves attachment validation down into ExecutionService so that attachments passed via workflows are validated. ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [X] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md) - [X] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [X] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [X] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [X] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [X] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [X] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) - [X] Review the [backport guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing) and apply applicable `backport:*` labels. ### Identify risks Does this PR introduce any risks? For example, consider risks like hard to test bugs, performance regression, potential of data loss. Describe the risk, its severity, and mitigation for each identified risk. Invite stakeholders and evaluate how to proceed before merging. - [ ] [See some risk examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) - [ ] ... --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Summary
Summarize your PR. If it involves visual changes include a screenshot or gif.
Add support for passing attachments to the run agent step in workflows.
Example workflow with alert attachment
PR also moves attachment validation down into ExecutionService so that attachments passed via workflows are validated.
Checklist
Check the PR satisfies following conditions.
Reviewers should verify this PR satisfies this list as well.
release_note:breakinglabel should be applied in these situations.release_note:*label is applied per the guidelinesbackport:*labels.Identify risks
Does this PR introduce any risks? For example, consider risks like hard to test bugs, performance regression, potential of data loss.
Describe the risk, its severity, and mitigation for each identified risk. Invite stakeholders and evaluate how to proceed before merging.