-
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
[Elastic Assistant] Update default assistant graph #190686
[Elastic Assistant] Update default assistant graph #190686
Conversation
…P1llus/kibana into elastic_assistant_default_graph_rewrite
x-pack/plugins/elastic_assistant/server/lib/langchain/graphs/default_assistant_graph/graph.ts
Show resolved
Hide resolved
@elasticmachine merge upstream |
x-pack/plugins/elastic_assistant/server/lib/langchain/graphs/default_assistant_graph/helpers.ts
Outdated
Show resolved
Hide resolved
x-pack/plugins/elastic_assistant/server/lib/langchain/graphs/default_assistant_graph/helpers.ts
Outdated
Show resolved
Hide resolved
x-pack/plugins/elastic_assistant/server/lib/langchain/graphs/default_assistant_graph/graph.ts
Outdated
Show resolved
Hide resolved
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.
LGTM! Thanks for the improvements @P1llus
💚 Build Succeeded
Metrics [docs]
History
To update your PR or re-run it, just comment with: cc @P1llus |
💔 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 |
## Summary **NOTE** I will need help testing this before we merge it! I spoke with @spong about an upcoming PR we have here: elastic#190426 which bumps the langgraph version from 0.0.31 to 0.0.34, unfortunately this caused a lot of type errors in the default assistant. After some more discussion we proposed to open a PR that removes some of the more complex layers and to fix up the type issues. Though I have not worked on this graph before, the changes hopefully makes sense 👍 Graph flow: ![image](https://github.com/user-attachments/assets/911190c1-2cdc-429f-bd1b-2b4a6a343729) The PR changes the below items to remove some of the abstractions and resolve some of the type issues, also adds a few improvements in general: - Moves `llmType`, `bedrockChatEnabled`, `isStream` and `conversationId` to be invoke parameters rather than compile parameters. This allows them to be used in state, and removes the need to pass them everywhere as parameters. Adding them to the state also allows them to be available in langsmith. - Removes the constants defining each node with wrappers and rather expose them directly as async functions. This removes a lot of the boilerplate code and it makes reading the stacktraces much easier. - Moved to a single `stepRouter` used for the current conditional edges. This allows one to very easily extend the routing between either existing or new nodes, and makes it much easier to understand what conditions are routed where. - Exports a common `NodeType` object constant (no need for the extra compile overhead of Enums here, we are only using strings), to make the node name strings auto-complete and prevent hardcoded names for the router. - Added a `modelInput` node to be the starter node. This was first because adding nodes inside if conditions usually create errors, so it was created to be able to set the `hasRespondStep` state. However this node is nice to have as an entrypoint in which you find yourself wanting to change the state based on the invoke parameters or other conditions retrieved from other parts of the stack etc before it continues to any of the other nodes. - Added a `yarn draw-graph` command, that outputs to `docs/img/default_assistant_graph.png`. This is then also included in the readme. This makes it better for changes by other teams (like me) to understand the intended graph workflows easier. ### Checklist Delete any items that are not applicable to this PR. - [x] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials ### For maintainers - [x] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> (cherry picked from commit b660d42) # Conflicts: # x-pack/plugins/elastic_assistant/server/lib/langchain/graphs/default_assistant_graph/nodes/execute_tools.ts # x-pack/plugins/elastic_assistant/server/lib/langchain/graphs/default_assistant_graph/nodes/generate_chat_title.ts # x-pack/plugins/elastic_assistant/server/lib/langchain/graphs/default_assistant_graph/nodes/run_agent.ts # x-pack/plugins/elastic_assistant/server/lib/langchain/graphs/default_assistant_graph/nodes/should_continue.ts
…191386) # Backport This will backport the following commits from `main` to `8.15`: - [[Elastic Assistant] Update default assistant graph (#190686)](#190686) <!--- Backport version: 8.9.8 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Marius Iversen","email":"marius.iversen@elastic.co"},"sourceCommit":{"committedDate":"2024-08-22T20:52:28Z","message":"[Elastic Assistant] Update default assistant graph (#190686)\n\n## Summary\n\n**NOTE** I will need help testing this before we merge it!\n\nI spoke with @spong about an upcoming PR we have here:\nhttps://github.com//pull/190426 which bumps the langgraph\nversion from 0.0.31 to 0.0.34, unfortunately this caused a lot of type\nerrors in the default assistant.\n\nAfter some more discussion we proposed to open a PR that removes some of\nthe more complex layers and to fix up the type issues. Though I have not\nworked on this graph before, the changes hopefully makes sense 👍\n\nGraph flow:\n\n![image](https://github.com/user-attachments/assets/911190c1-2cdc-429f-bd1b-2b4a6a343729)\n\n\nThe PR changes the below items to remove some of the abstractions and\nresolve some of the type issues, also adds a few improvements in\ngeneral:\n\n- Moves `llmType`, `bedrockChatEnabled`, `isStream` and `conversationId`\nto be invoke parameters rather than compile parameters. This allows them\nto be used in state, and removes the need to pass them everywhere as\nparameters. Adding them to the state also allows them to be available in\nlangsmith.\n- Removes the constants defining each node with wrappers and rather\nexpose them directly as async functions. This removes a lot of the\nboilerplate code and it makes reading the stacktraces much easier.\n- Moved to a single `stepRouter` used for the current conditional edges.\nThis allows one to very easily extend the routing between either\nexisting or new nodes, and makes it much easier to understand what\nconditions are routed where.\n- Exports a common `NodeType` object constant (no need for the extra\ncompile overhead of Enums here, we are only using strings), to make the\nnode name strings auto-complete and prevent hardcoded names for the\nrouter.\n- Added a `modelInput` node to be the starter node. This was first\nbecause adding nodes inside if conditions usually create errors, so it\nwas created to be able to set the `hasRespondStep` state. However this\nnode is nice to have as an entrypoint in which you find yourself wanting\nto change the state based on the invoke parameters or other conditions\nretrieved from other parts of the stack etc before it continues to any\nof the other nodes.\n- Added a `yarn draw-graph` command, that outputs to\n`docs/img/default_assistant_graph.png`. This is then also included in\nthe readme. This makes it better for changes by other teams (like me) to\nunderstand the intended graph workflows easier.\n\n\n### Checklist\n\nDelete any items that are not applicable to this PR.\n\n- [x]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas added for features that require explanation or tutorials\n\n### For maintainers\n\n- [x] This was checked for breaking API changes and was [labeled\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n\n---------\n\nCo-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>","sha":"b660d42b08a645bcbb8f1e5c78341f32f6c5d5fe","branchLabelMapping":{"^v8.16.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:prev-minor","Feature:GenAI","Team:Security Generative AI","v8.16.0"],"number":190686,"url":"https://github.com/elastic/kibana/pull/190686","mergeCommit":{"message":"[Elastic Assistant] Update default assistant graph (#190686)\n\n## Summary\n\n**NOTE** I will need help testing this before we merge it!\n\nI spoke with @spong about an upcoming PR we have here:\nhttps://github.com//pull/190426 which bumps the langgraph\nversion from 0.0.31 to 0.0.34, unfortunately this caused a lot of type\nerrors in the default assistant.\n\nAfter some more discussion we proposed to open a PR that removes some of\nthe more complex layers and to fix up the type issues. Though I have not\nworked on this graph before, the changes hopefully makes sense 👍\n\nGraph flow:\n\n![image](https://github.com/user-attachments/assets/911190c1-2cdc-429f-bd1b-2b4a6a343729)\n\n\nThe PR changes the below items to remove some of the abstractions and\nresolve some of the type issues, also adds a few improvements in\ngeneral:\n\n- Moves `llmType`, `bedrockChatEnabled`, `isStream` and `conversationId`\nto be invoke parameters rather than compile parameters. This allows them\nto be used in state, and removes the need to pass them everywhere as\nparameters. Adding them to the state also allows them to be available in\nlangsmith.\n- Removes the constants defining each node with wrappers and rather\nexpose them directly as async functions. This removes a lot of the\nboilerplate code and it makes reading the stacktraces much easier.\n- Moved to a single `stepRouter` used for the current conditional edges.\nThis allows one to very easily extend the routing between either\nexisting or new nodes, and makes it much easier to understand what\nconditions are routed where.\n- Exports a common `NodeType` object constant (no need for the extra\ncompile overhead of Enums here, we are only using strings), to make the\nnode name strings auto-complete and prevent hardcoded names for the\nrouter.\n- Added a `modelInput` node to be the starter node. This was first\nbecause adding nodes inside if conditions usually create errors, so it\nwas created to be able to set the `hasRespondStep` state. However this\nnode is nice to have as an entrypoint in which you find yourself wanting\nto change the state based on the invoke parameters or other conditions\nretrieved from other parts of the stack etc before it continues to any\nof the other nodes.\n- Added a `yarn draw-graph` command, that outputs to\n`docs/img/default_assistant_graph.png`. This is then also included in\nthe readme. This makes it better for changes by other teams (like me) to\nunderstand the intended graph workflows easier.\n\n\n### Checklist\n\nDelete any items that are not applicable to this PR.\n\n- [x]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas added for features that require explanation or tutorials\n\n### For maintainers\n\n- [x] This was checked for breaking API changes and was [labeled\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n\n---------\n\nCo-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>","sha":"b660d42b08a645bcbb8f1e5c78341f32f6c5d5fe"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.16.0","labelRegex":"^v8.16.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/190686","number":190686,"mergeCommit":{"message":"[Elastic Assistant] Update default assistant graph (#190686)\n\n## Summary\n\n**NOTE** I will need help testing this before we merge it!\n\nI spoke with @spong about an upcoming PR we have here:\nhttps://github.com//pull/190426 which bumps the langgraph\nversion from 0.0.31 to 0.0.34, unfortunately this caused a lot of type\nerrors in the default assistant.\n\nAfter some more discussion we proposed to open a PR that removes some of\nthe more complex layers and to fix up the type issues. Though I have not\nworked on this graph before, the changes hopefully makes sense 👍\n\nGraph flow:\n\n![image](https://github.com/user-attachments/assets/911190c1-2cdc-429f-bd1b-2b4a6a343729)\n\n\nThe PR changes the below items to remove some of the abstractions and\nresolve some of the type issues, also adds a few improvements in\ngeneral:\n\n- Moves `llmType`, `bedrockChatEnabled`, `isStream` and `conversationId`\nto be invoke parameters rather than compile parameters. This allows them\nto be used in state, and removes the need to pass them everywhere as\nparameters. Adding them to the state also allows them to be available in\nlangsmith.\n- Removes the constants defining each node with wrappers and rather\nexpose them directly as async functions. This removes a lot of the\nboilerplate code and it makes reading the stacktraces much easier.\n- Moved to a single `stepRouter` used for the current conditional edges.\nThis allows one to very easily extend the routing between either\nexisting or new nodes, and makes it much easier to understand what\nconditions are routed where.\n- Exports a common `NodeType` object constant (no need for the extra\ncompile overhead of Enums here, we are only using strings), to make the\nnode name strings auto-complete and prevent hardcoded names for the\nrouter.\n- Added a `modelInput` node to be the starter node. This was first\nbecause adding nodes inside if conditions usually create errors, so it\nwas created to be able to set the `hasRespondStep` state. However this\nnode is nice to have as an entrypoint in which you find yourself wanting\nto change the state based on the invoke parameters or other conditions\nretrieved from other parts of the stack etc before it continues to any\nof the other nodes.\n- Added a `yarn draw-graph` command, that outputs to\n`docs/img/default_assistant_graph.png`. This is then also included in\nthe readme. This makes it better for changes by other teams (like me) to\nunderstand the intended graph workflows easier.\n\n\n### Checklist\n\nDelete any items that are not applicable to this PR.\n\n- [x]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas added for features that require explanation or tutorials\n\n### For maintainers\n\n- [x] This was checked for breaking API changes and was [labeled\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n\n---------\n\nCo-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>","sha":"b660d42b08a645bcbb8f1e5c78341f32f6c5d5fe"}}]}] BACKPORT-->
Summary
NOTE I will need help testing this before we merge it!
I spoke with @spong about an upcoming PR we have here: #190426 which bumps the langgraph version from 0.0.31 to 0.0.34, unfortunately this caused a lot of type errors in the default assistant.
After some more discussion we proposed to open a PR that removes some of the more complex layers and to fix up the type issues. Though I have not worked on this graph before, the changes hopefully makes sense 👍
Graph flow:
The PR changes the below items to remove some of the abstractions and resolve some of the type issues, also adds a few improvements in general:
llmType
,bedrockChatEnabled
,isStream
andconversationId
to be invoke parameters rather than compile parameters. This allows them to be used in state, and removes the need to pass them everywhere as parameters. Adding them to the state also allows them to be available in langsmith.stepRouter
used for the current conditional edges. This allows one to very easily extend the routing between either existing or new nodes, and makes it much easier to understand what conditions are routed where.NodeType
object constant (no need for the extra compile overhead of Enums here, we are only using strings), to make the node name strings auto-complete and prevent hardcoded names for the router.modelInput
node to be the starter node. This was first because adding nodes inside if conditions usually create errors, so it was created to be able to set thehasRespondStep
state. However this node is nice to have as an entrypoint in which you find yourself wanting to change the state based on the invoke parameters or other conditions retrieved from other parts of the stack etc before it continues to any of the other nodes.yarn draw-graph
command, that outputs todocs/img/default_assistant_graph.png
. This is then also included in the readme. This makes it better for changes by other teams (like me) to understand the intended graph workflows easier.Checklist
Delete any items that are not applicable to this PR.
For maintainers