-
Notifications
You must be signed in to change notification settings - Fork 25
feat(playbooks): add AI diagnose failure button for failed playbook runs #2849
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a27dc5a
feat(playbooks): add AI diagnose failure button for failed playbook runs
adityathebe 46f501d
fix(ai): auto-send initial prompt and prevent infinite loop
adityathebe 998b7be
fix(playbooks): wrap PlaybookRunsAction tests with AiFeatureLoaderPro…
adityathebe 5d89caa
fix(playbooks): use consistent Button component for diagnose failure …
adityathebe 2c0743f
refactor(playbooks): improve AI diagnosis with system prompt and full…
adityathebe 6fb33bb
refactor(ai): remove initialPrompt and auto-send pre-seeded user mess…
adityathebe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
78 changes: 78 additions & 0 deletions
78
src/components/Playbooks/Runs/DiagnosePlaybookFailureButton.tsx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import { useCallback } from "react"; | ||
| import { type PlaybookRunWithActions } from "@flanksource-ui/api/types/playbooks"; | ||
| import { useAiChatPopover } from "@flanksource-ui/components/ai/AiChatPopover"; | ||
| import { Button } from "@flanksource-ui/ui/Buttons/Button"; | ||
| import { Sparkles } from "lucide-react"; | ||
|
|
||
| type DiagnosePlaybookFailureButtonProps = { | ||
| data: PlaybookRunWithActions; | ||
| }; | ||
|
|
||
| export function DiagnosePlaybookFailureButton({ | ||
| data | ||
| }: DiagnosePlaybookFailureButtonProps) { | ||
| const { setOpen, setChatMessages } = useAiChatPopover(); | ||
|
|
||
| const handleDiagnoseFailure = useCallback(() => { | ||
| const systemPrompt = `You are helping diagnose why a Playbook run failed in Mission Control. | ||
|
|
||
| Context on Playbooks: | ||
| - A Playbook is an automated workflow that executes a sequence of Actions | ||
| - Each Action in the playbook has a status (scheduled, running, completed, failed, skipped, etc.) | ||
| - A PlaybookRun is an instance/execution of a Playbook | ||
| - PlaybookRuns can have parameters and child runs | ||
|
|
||
| When analyzing a failed run: | ||
| 1. Check the overall run status and error message | ||
| 2. Identify which actions failed and their error details | ||
| 3. Look at action results to understand what went wrong | ||
| 4. Consider the parameters that were passed in | ||
| 5. Look at the playbook spec to understand the intended flow | ||
| 6. Suggest specific fixes based on the error | ||
|
|
||
| Be concise and actionable in your diagnosis.`; | ||
|
|
||
| const failedActions = | ||
| data.actions?.filter((a) => a.status === "failed") || []; | ||
| const userPrompt = `Please diagnose why this playbook run failed.${ | ||
| data.error ? ` Run error: ${data.error}` : "" | ||
| }${ | ||
| failedActions.length > 0 | ||
| ? ` ${failedActions.length} action(s) failed.` | ||
| : "" | ||
| } What went wrong and how do we fix it?`; | ||
|
|
||
| const text = JSON.stringify(data, null, 2); | ||
|
|
||
| setChatMessages([ | ||
| { | ||
| id: `system-${Date.now()}`, | ||
| role: "system", | ||
| parts: [{ type: "text", text: systemPrompt }] | ||
| }, | ||
| { | ||
| id: `user-${Date.now()}`, | ||
| role: "user", | ||
| parts: [ | ||
| { | ||
| type: "text", | ||
| text: `${userPrompt}\n\nPlaybook Run Data:\n\`\`\`json\n${text}\n\`\`\`` | ||
| } | ||
| ] | ||
| } | ||
| ]); | ||
|
|
||
| setOpen(true); | ||
| }, [data, setChatMessages, setOpen]); | ||
|
|
||
| return ( | ||
| <Button | ||
| onClick={handleDiagnoseFailure} | ||
| className="btn-white min-w-max space-x-1" | ||
| title="Diagnose playbook failure with AI" | ||
| > | ||
| <Sparkles className="h-5 w-5" /> | ||
| <span>Diagnose Failure</span> | ||
| </Button> | ||
| ); | ||
| } |
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.