-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Security AI] Add Kibana Support for Security AI Prompts Integration #207138
Conversation
x-pack/solutions/security/plugins/elastic_assistant/server/lib/prompt/saved_object_mappings.ts
Show resolved
Hide resolved
x-pack/solutions/security/plugins/elastic_assistant/server/lib/prompt/saved_object_mappings.ts
Outdated
Show resolved
Hide resolved
Pinging @elastic/security-solution (Team: SecuritySolution) |
...urity/plugins/elastic_assistant/server/lib/langchain/graphs/default_assistant_graph/index.ts
Outdated
Show resolved
Hide resolved
x-pack/solutions/security/plugins/elastic_assistant/server/saved_objects.ts
Outdated
Show resolved
Hide resolved
x-pack/solutions/security/plugins/elastic_assistant/server/lib/prompt/saved_object_mappings.ts
Outdated
Show resolved
Hide resolved
x-pack/solutions/security/plugins/elastic_assistant/server/lib/prompt/get_prompt.ts
Outdated
Show resolved
Hide resolved
@elasticmachine merge upstream |
let userPrompt = ''; | ||
if (state.llmType === 'gemini') { | ||
userPrompt = await getPrompt({ | ||
actionsClient, | ||
connectorId: state.connectorId, | ||
promptId: promptDictionary.userPrompt, | ||
promptGroupId: promptGroupId.aiAssistant, | ||
provider: 'gemini', | ||
savedObjectsClient, | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Consider an alternative like:
const userPrompt =
state.llmType === 'gemini'
? await getPrompt({
actionsClient,
connectorId: state.connectorId,
promptId: promptDictionary.userPrompt,
promptGroupId: promptGroupId.aiAssistant,
provider: 'gemini',
savedObjectsClient,
})
: '';
to eliminate the local mutation.
@elasticmachine merge upstream |
|
||
const prompts = await savedObjectsClient.find<Prompt>({ | ||
type: promptSavedObjectType, | ||
filter: `${promptSavedObjectType}.attributes.promptId: ${promptId} AND ${promptSavedObjectType}.attributes.promptGroupId: ${promptGroupId}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider wrapping the filter
's promptId
and promptGroupId
in quotes, for example:
filter: `${promptSavedObjectType}.attributes.promptId: "${promptId}" AND ${promptSavedObjectType}.attributes.promptGroupId: "${promptGroupId}"`,
💚 Build Succeeded
Metrics [docs]Module Count
Public APIs missing comments
Page load bundle
Saved Objects .kibana field count
History
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @stephmilovic for adding support for out of band prompt updates to the security assistant and Attack discovery prompts! 🙏
✅ Desk tested locally
LGTM 🚀
Starting backport for target branches: 8.x |
💔 All backports failed
Manual backportTo create the backport manually run:
Questions ?Please refer to the Backport tool documentation |
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…lastic#207138) (cherry picked from commit 7af5a83) # Conflicts: # src/core/packages/saved-objects/server-internal/src/object_types/index.ts # x-pack/platform/plugins/shared/fleet/server/routes/epm/index.test.ts # x-pack/platform/plugins/shared/fleet/server/services/agent_policies/package_policies_to_agent_permissions.test.ts
…ation (#207138) (#208648) # Backport This will backport the following commits from `main` to `8.x`: - [[Security AI] Add Kibana Support for Security AI Prompts Integration (#207138)](#207138) <!--- Backport version: 9.6.4 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Steph Milovic","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-01-28T22:35:39Z","message":"[Security AI] Add Kibana Support for Security AI Prompts Integration (#207138)","sha":"7af5a8338bab6da9bc45eccfd21b11129b05048c","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:enhancement","Team:Fleet","v9.0.0","Team: SecuritySolution","backport:prev-minor","Team:Security Generative AI","v8.18.0"],"title":"[Security AI] Add Kibana Support for Security AI Prompts Integration","number":207138,"url":"https://github.com/elastic/kibana/pull/207138","mergeCommit":{"message":"[Security AI] Add Kibana Support for Security AI Prompts Integration (#207138)","sha":"7af5a8338bab6da9bc45eccfd21b11129b05048c"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/207138","number":207138,"mergeCommit":{"message":"[Security AI] Add Kibana Support for Security AI Prompts Integration (#207138)","sha":"7af5a8338bab6da9bc45eccfd21b11129b05048c"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT-->
Out of Band Security AI Prompts
This PR introduces support for the future integration of Security AI prompts in Kibana. Prompts will be stored within the integration as saved objects identified by the id
security-ai-prompt
.To ensure reliability, fallback prompts are maintained in a local file and will be used when the corresponding prompt is unavailable in the integration.
Introduces 2 methods for fetching prompts:
getPrompt
: Retrieves a prompt bypromptId
.getPromptsByGroupId
: Retrieves a group of prompts bypromptGroupId
.The methods use a helper called
resolveProviderAndModel
to identify a provider + model by either providing theprovider
+model
arguments or theconnector
argument. If neither arguments are provided, the connector is fetched by id from theactionsClient
.The saved object inference prompts are then fetched either by
promptId
ingetPrompts
or by thepromptGroupId
field ingetPromptsByGroupId
.Finally, the returned saved objects along with a local prompt object are used in
findPromptEntry
to identify the best matching prompt perpromptId
+promptGroupId
andprovider
+model
. The prompts are matched in the following order:provider
+model
(integration)provider
(integration)provider
+model
(local)provider
(local)promptId
,promptGroupId
,promptDictionary
A
promptId
is the unique identifier of the prompt. ThepromptGroupId
is the group of which the prompt belongs to. EachpromptId
is stored inpromptDictionary
. When using apromptId
, refer to it from thepromptDictionary
, ex:promptDictionary.attackDiscoveryDefault
.Inference
We try to find the
provider
for inference connectors fromconfig
, since these connectors all have different provider types and we cannot rely on theactionTypeId
. When the inference connector uses EIS, we use a mapping to identify theprovider
+model
from the EIS model. If no provider can be identified for an inference connector, we default to Bedrock as provider. For 9.0.0 this model mapping will live in solutions code, but we hope to find a centralized design for the mappings in 9.1.0.Testing
curl
to create an inference endpoint configured for EIS:xpack.stack_connectors.enableExperimental: ['inferenceConnectorOn']
security-ai-prompt
saved object, the type that will ship with our planned integration. The saved object specifies a prompt for Bedrock providers for the AI Assistant system prompt.ai-assistant-default.json
hello world
. Find the trace in LangSmith. The system message should be the local prompt:You are a security analyst and expert in resolving security incidents. Your role is to assist by answering questions about Elastic Security. Do not answer questions unrelated to Elastic Security. If available, use the Knowledge History provided to try and answer the question. If not provided, you can try and query for additional knowledge via the KnowledgeBaseRetrievalTool.
Default system prompt test
Default system prompt test