Skip to content
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

Merged
merged 17 commits into from
Aug 22, 2024

Conversation

P1llus
Copy link
Member

@P1llus P1llus commented Aug 19, 2024

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:
image

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.

  • Documentation was added for features that require explanation or tutorials

For maintainers

@P1llus P1llus added release_note:skip Skip the PR/issue when compiling release notes backport:prev-major Backport to (8.x, 8.17, 8.16, 8.15) the previous major branch and other branches in development Feature:GenAI Team:Security Generative AI Security Generative AI v8.16.0 labels Aug 19, 2024
@P1llus P1llus requested a review from spong August 19, 2024 10:47
@P1llus P1llus added backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) and removed backport:prev-major Backport to (8.x, 8.17, 8.16, 8.15) the previous major branch and other branches in development labels Aug 19, 2024
@P1llus P1llus marked this pull request as ready for review August 19, 2024 11:20
@P1llus P1llus requested a review from a team as a code owner August 19, 2024 11:20
@stephmilovic
Copy link
Contributor

@elasticmachine merge upstream

Copy link
Contributor

@stephmilovic stephmilovic left a 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

@P1llus P1llus self-assigned this Aug 22, 2024
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @P1llus

@P1llus P1llus merged commit b660d42 into elastic:main Aug 22, 2024
37 checks passed
@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.15 Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

node scripts/backport --pr 190686

Questions ?

Please refer to the Backport tool documentation

@P1llus
Copy link
Member Author

P1llus commented Aug 27, 2024

💚 All backports created successfully

Status Branch Result
8.15

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:

![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
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![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-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) Feature:GenAI release_note:skip Skip the PR/issue when compiling release notes Team:Security Generative AI Security Generative AI v8.15.1 v8.16.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants