Skip to content

[Security Assistant] Context prompts#224956

Merged
stephmilovic merged 30 commits intoelastic:mainfrom
stephmilovic:context_prompts
Jun 25, 2025
Merged

[Security Assistant] Context prompts#224956
stephmilovic merged 30 commits intoelastic:mainfrom
stephmilovic:context_prompts

Conversation

@stephmilovic
Copy link
Contributor

@stephmilovic stephmilovic commented Jun 23, 2025

Summary

Implements the context prompts within the Security AI Prompts package. These prompts were client side only, so in order to fetch the prompts from the integration, a new find security AI prompts API was introduced. If the API fails, the prompts fallback to a client side i18n'd version. The context prompts include:

Alert/event analysis

Screenshot 2025-06-23 at 12 52 27 PM

Data Quality Dashboard

Screenshot 2025-06-23 at 1 02 55 PM

Rules

Screenshot 2025-06-23 at 12 44 10 PM

Imperfections

Given that this user prompt is executed in a conversation with a connector id, it would be nice to include the connector id in the request in case provider specific prompts are introduced. However, these prompts are currently stored in the assistant provider context. Because of the short turnaround required for this feature (I was asked to implement it shortly before feature freeze), I left the prompts in the provider context and did not implement a connector id as a requirement for the request. It would be nice to refactor this in the future, perhaps as a part of this issue: #219142

Cypress changes

We were checking if the correct user prompt was sent when these prompts are used. However, since it is now part of the Security AI Prompt package and the prompt can be changed out of band, this check could break if the integration is updated with a new prompt. Therefore, I removed this check.

Integrations PR

As this adds new prompts, the @elastic/security-generative-ai reviewer should also review this integrations PR: elastic/integrations#14296
The integrations PR includes new prompts from #224981

@stephmilovic stephmilovic added release_note:skip Skip the PR/issue when compiling release notes Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. labels Jun 23, 2025
@stephmilovic stephmilovic requested review from a team as code owners June 23, 2025 20:06
@stephmilovic stephmilovic added the Team:Security Generative AI Security Generative AI label Jun 23, 2025
@stephmilovic stephmilovic requested a review from a team as a code owner June 23, 2025 20:06
@stephmilovic stephmilovic added backport:version Backport to applied version labels v9.1.0 labels Jun 23, 2025
@stephmilovic stephmilovic requested a review from xcrzx June 23, 2025 20:06
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

const styles = useStyles();
const { isAssistantEnabled } = useDataQualityContext();
const { isAssistantEnabled, httpFetch, toasts } = useDataQualityContext();
const {
Copy link
Contributor Author

@stephmilovic stephmilovic Jun 23, 2025

Choose a reason for hiding this comment

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

I tried for about 45 minutes to add tests for this, but the mocking logic in this package is extremely difficult to follow. Given the approaching feature freeze and lack of time, I ask that @elastic/security-threat-hunting-investigations add tests to this PR or forgive the missing tests.

Copy link
Contributor

@kapral18 kapral18 Jun 24, 2025

Choose a reason for hiding this comment

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

Sorry to hear that. Seems like your AssistantProvider file causes a circular imports issue that makes it impossible to jest mock components inside of it from outside. Will have a look at it some time later when I have time to pinpoint specifically where it happens.

Nevertheless I added tests and pushed to your branch.

To make this work, unfortunately had to completely mock out NewChat and remove assistant provider which makes it a blackbox from now on in our tests to test anything besides the immediate contract of your exposed components.

Also I spotted a slight uncovered edge case in title, fixed and tested it.

Let me know if it works for you

Copy link
Contributor

@christineweng christineweng left a comment

Choose a reason for hiding this comment

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

Investigations changes LGTM. I pinged another team member on data quality tests

Copy link
Contributor

@dplumlee dplumlee left a comment

Choose a reason for hiding this comment

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

Rule management changes LGTM

@stephmilovic
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Member

@KDKHD KDKHD left a comment

Choose a reason for hiding this comment

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

Code changes look good! Ran locally and saw the API request being made and the prompts from the response being added into the Assistant.

image

@stephmilovic
Copy link
Contributor Author

@elasticmachine merge upstream

@stephmilovic stephmilovic enabled auto-merge (squash) June 24, 2025 15:38
@stephmilovic
Copy link
Contributor Author

@elasticmachine merge upstream

@KDKHD KDKHD requested a review from a team as a code owner June 24, 2025 18:38
@stephmilovic
Copy link
Contributor Author

@elasticmachine merge upstream

@stephmilovic stephmilovic merged commit 2e384fb into elastic:main Jun 25, 2025
10 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.19

https://github.com/elastic/kibana/actions/runs/15865936770

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
automaticImport 755 758 +3
cases 1133 1135 +2
elasticAssistant 407 410 +3
securitySolution 7764 7768 +4
total +12

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/elastic-assistant 174 175 +1
@kbn/elastic-assistant-common 660 667 +7
total +8

Async chunks

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

id before after diff
securitySolution 9.7MB 9.8MB +57.5KB

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/elastic-assistant 12 13 +1

Page load bundle

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

id before after diff
securitySolution 147.7KB 94.2KB -53.5KB
Unknown metric groups

API count

id before after diff
@kbn/elastic-assistant 206 208 +2
@kbn/elastic-assistant-common 772 779 +7
total +9

History

@kibanamachine
Copy link
Contributor

stephmilovic added a commit to stephmilovic/kibana that referenced this pull request Jun 25, 2025
(cherry picked from commit 2e384fb)

# Conflicts:
#	x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/index.ts
#	x-pack/platform/plugins/private/translations/translations/fr-FR.json
#	x-pack/platform/plugins/private/translations/translations/ja-JP.json
#	x-pack/platform/plugins/private/translations/translations/zh-CN.json
#	x-pack/solutions/security/plugins/security_solution/public/assistant/provider.tsx
#	x-pack/solutions/security/plugins/security_solution/public/plugin.tsx
@stephmilovic
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
8.19

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

stephmilovic added a commit that referenced this pull request Jun 25, 2025
# Backport

This will backport the following commits from `main` to `8.19`:
- [[Security Assistant] Context prompts
(#224956)](#224956)

<!--- Backport version: 10.0.1 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Steph
Milovic","email":"stephanie.milovic@elastic.co"},"sourceCommit":{"committedDate":"2025-06-25T02:32:51Z","message":"[Security
Assistant] Context prompts
(#224956)","sha":"2e384fb0a56e84a2ea60c113fa009642e9fb8925","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:
SecuritySolution","Team:Security Generative
AI","backport:version","v9.1.0","v8.19.0"],"title":"[Security Assistant]
Context
prompts","number":224956,"url":"https://github.com/elastic/kibana/pull/224956","mergeCommit":{"message":"[Security
Assistant] Context prompts
(#224956)","sha":"2e384fb0a56e84a2ea60c113fa009642e9fb8925"}},"sourceBranch":"main","suggestedTargetBranches":["8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/224956","number":224956,"mergeCommit":{"message":"[Security
Assistant] Context prompts
(#224956)","sha":"2e384fb0a56e84a2ea60c113fa009642e9fb8925"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
akowalska622 pushed a commit to akowalska622/kibana that referenced this pull request Jun 25, 2025
Comment on lines +104 to +107
const promptContext = useObservable(
elasticAssistantSharedState.promptContexts.getPromptContext$(),
{}
);
Copy link
Member

@KDKHD KDKHD Jun 25, 2025

Choose a reason for hiding this comment

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

How come you needed to add this useObservable hook? Was it not enough to call elasticAssistantSharedState.promptContexts.setPromptContext(PROMPT_CONTEXTS) wheneverPROMPT_CONTEXTS changes?

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 useEffect was stack overflowing, crashed the app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels release_note:skip Skip the PR/issue when compiling release notes Team:Security Generative AI Security Generative AI Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v8.19.0 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants