[Security Assistant] Migrates to LangGraph and adds KB Tools#184554
[Security Assistant] Migrates to LangGraph and adds KB Tools#184554spong merged 26 commits intoelastic:mainfrom
Conversation
… to use kbDataClient instead of esStore
|
|
||
| const userFilter = [ | ||
| { | ||
| nested: { |
There was a problem hiding this comment.
I think we should extend the filter to support empty("shared") KBs, which are available for all users in the space.
There was a problem hiding this comment.
I'm working through adding the different permutations of kb mock data today for #184974 and will use that to start crafting tests to cover these scenarios.
I want to take a moment and rethink how we're categorizing/namespacing content using kbResource though to see if there will be any issues here. For now I've kept things matching the original KB implementation, and just introduced the user kbResource for all user created entries. We will also need to capture entryType somewhere to differentiate between raw text content and index-backed entries. Would be nice to have a catch-all tags for organization and labeling too.
I will start thinking through more of this early next week as I get back to plumbing through the remainder of the kbDataClient methods and REST API's, but if you have any thoughts here I would love to hear them 🙂
# Conflicts: # package.json
|
@elasticmachine merge upstream |
patrykkopycinski
left a comment
There was a problem hiding this comment.
Thank you Garrett! 🙇
💛 Build succeeded, but was flaky
Failed CI StepsTest FailuresMetrics [docs]Public APIs missing comments
Public APIs missing exports
History
To update your PR or re-run it, just comment with: cc @spong |
Summary
Migrates our existing RAG pipeline to use LangGraph, and adds tools for Knowledge Base retrieval/storage.
When the
assistantKnowledgeBaseByDefaultFF is enabled, a new branch,callAssistantGraph(), is taken inpostActionsConnectorExecuteRoutethat exercises the LangGraph implementation. This is a drop-in replacement for the existingcallAgentExecutor()in effort to keep adoption as clean and easy as possible.The new control flow is as follows:
postActionsConnectorExecuteRoute->callAssistantGraph()->getDefaultAssistantGraph()->isStreamingEnabled ? streamGraph() : invokeGraph()Graph creation is isolated to
getDefaultAssistantGraph(), and execution (streaming or not) has been extracted tostreamGraph()andinvokeGraph()respectively. Note: Streaming currently only works withChatOpenAImodels, butSimpleChatModelStreamingwas de-risked and just need to discuss potential solutions with @stephmilovic. See comment here.DefaultAssistantGraph
To start with a predictable and piecemeal migration, our existing
agentExecutorpipeline has been recreated in LangGraph. It consists of a single agent node, eitherOpenAIFunctionsAgent, orStructuredChatAgent(depending on the backing LLM), a tool executing node, and a conditional edge that routes between the two nodes until there are no more function calls chosen by the agent. This varies from our initial implementation in that multiple tool calls are now supported, so a user could ask about their alerts AND retrieve additional knowledge base information in the same response.Note
While
chat_historyhas been plumbed into the graph, after discussing with @YulNaumenko we decided to wait to plumb the rest of persistence into the graph until #184485 is merged. I had already plumbed through thechatTitleGenerationnode (here), and so will just need to include initial conversation creation and append/update operations.Knowledge History & KB Tools
Knowledge History is now always added in the initial prompt for any KB documents marked as
required, and two new tools were added for creating and recalling KB entries from within the conversation,KnowledgeBaseWriteToolandKnowledgeBaseRetrievalToolrespectively. All three methods of storing and retrieving KB content use thekbDataClientfor access, and scopes all requests to the authenticatedUser that made the initial request.Additional Notes:
LangGraphhas been added.Checklist
Delete any items that are not applicable to this PR.