[Elastic Assistant] Update default assistant graph#190686
Merged
P1llus merged 17 commits intoelastic:mainfrom Aug 22, 2024
Merged
[Elastic Assistant] Update default assistant graph#190686P1llus merged 17 commits intoelastic:mainfrom
P1llus merged 17 commits intoelastic:mainfrom
Conversation
P1llus
commented
Aug 19, 2024
…P1llus/kibana into elastic_assistant_default_graph_rewrite
spong
reviewed
Aug 19, 2024
x-pack/plugins/elastic_assistant/server/lib/langchain/graphs/default_assistant_graph/graph.ts
Show resolved
Hide resolved
Contributor
|
@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
stephmilovic
approved these changes
Aug 22, 2024
Contributor
stephmilovic
left a comment
There was a problem hiding this comment.
LGTM! Thanks for the improvements @P1llus
💚 Build Succeeded
Metrics [docs]
History
To update your PR or re-run it, just comment with: cc @P1llus |
Contributor
💔 All backports failed
Manual backportTo create the backport manually run: Questions ?Please refer to the Backport tool documentation |
Member
Author
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
P1llus
added a commit
to P1llus/kibana
that referenced
this pull request
Aug 27, 2024
## 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:  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
P1llus
added a commit
that referenced
this pull request
Aug 27, 2024
…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\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\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\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-->
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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,isStreamandconversationIdto 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.stepRouterused 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.NodeTypeobject 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.modelInputnode 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 thehasRespondStepstate. 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-graphcommand, 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