-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution] [GenAi] Give the security AI assistant access to …
…the current time (#211200) ## Summary This PR adds a new tool that gives the LLM access to the current time. The tool returns the time in the timezone configured on Kibana as well as the UTC time. Changes: - Add time tool - Also increased the speed of the assistant stream making the assistant feel more snappy ([here](https://github.com/elastic/kibana/pull/211200/files#diff-d4dd2f3b250247285fee3300a6d38cf622f2724daa87947fe58111bae9d3d655R12)). The reasons for keeping the small delay (of 10 ms) is because it helps smooth out the stream. <img width="500" alt="image" src="https://github.com/user-attachments/assets/e613f9fb-a0f5-4559-88df-6d8ea0e5d042" /> ## How to test - Check that stack management > advanced settings > timezone is set to "browser" - Open the security assistant - Ask "what is the current time". You should get back the time in your local timezone + the equivalent GMT timezone (UTC and GMT are equivalent) - Go to stack management > advanced settings and set "Time zone" to a different timezone (a timezone with a different timezone offset). - Go to the assistant and ask again, "What is the current time". You should get back the time in the timezone that you just configured and the UTC equivalent. - Other questions to try out: - "What was the time exactly one week ago? Rounded to the nearest hour.". The result should be correct depending on what you have configured in advanced settings. - "Write an esql query that gets 100 records from the .logs index from the last week. Use the absolute time in the query." (may need to prompt again to have the query include the absolute time) - "When is my birthday", The assistant responds with "I don't know but you can tell me". You reply with "It was exactly 3 weeks ago". The assistant should create a KB document with the correct date. ## Considerations: - When asked "Which security labs content was published in the last 2 months", gemini-1-5-pro-002 often responds incorrectly ([trace](https://smith.langchain.com/o/b739bf24-7ba4-4994-b632-65dd677ac74e/projects/p/6bfddf7b-1225-4e97-ac9f-6cdf9158ac35?timeModel=%7B%22duration%22%3A%227d%22%7D&peek=4f5244a3-68fd-45e3-b1df-6c80e739377f)). GPT4o performs better and does not return an incorrect result when asked this question ([trace](https://smith.langchain.com/o/b739bf24-7ba4-4994-b632-65dd677ac74e/projects/p/6bfddf7b-1225-4e97-ac9f-6cdf9158ac35?timeModel=%7B%22duration%22%3A%227d%22%7D&peek=61bc4c12-d5ea-48be-8460-3e891d2e243b)). - You will notice that the formatted time string contains the time in the user's timezone and in UTC timezone (e.g. `Current time: 14/02/2025, 00:33:12 UTC-07:00 (14/02/2025, 07:33:12 UTC+00:00)`). The reason for this is that the weaker LLMs sometimes make mistakes when converting from one timezone to another. Therefore I have included both in the formatted message. * If the user is in UTC, then the UTC timezone will not be repeated. ## How is the current time string formatted? The formatted time string is added directly into the system prompt. Bellow is the logic for how the string is formatted. - If the user's kibana timezone setting is "Browser" 1. and their browser timezone is not UTC, then the format is `Current time: Thu, Feb 13, 2025 11:33 PM UTC-08:00 (7:33 AM UTC)` (where the first timezone is the client timezone, the one from the browser) 2. and their browser is in UTC, then the format is `Current time: Thu, Feb 13, 2025 11:33 PM UTC+00:00` - If the user's kibana timezone is set to something other than "Browser" 1. and the Kibana timezone setting is not UTC equivalent, then the format is `Current time: Thu, Feb 13, 2025 11:33 PM UTC-08:00 (7:33 AM UTC)` (where the first timezone is the one from the Kibana timezone setting) 2. and their kibana timezone is UTC equivalent, then the format is `Current time: Thu, Feb 13, 2025 11:33 PM UTC+00:00` ### 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) ### 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>
- Loading branch information
1 parent
bbc3b45
commit 7dce6e6
Showing
26 changed files
with
339 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.