Skip to content

Commit 2dfcc4e

Browse files
committed
feat: playbook agents
* playbook run listener support playbook_run as the parent not just notification_send [skip ci]
1 parent ec83673 commit 2dfcc4e

15 files changed

+500
-74
lines changed

api/v1/playbook_actions.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,8 @@ type AIAction struct {
385385
// When enabled, the prompt is simply saved without passing it on to the LLM.
386386
DryRun bool `json:"dryRun,omitempty"`
387387

388+
PlaybookAgents []types.ResourceSelector `json:"playbookAgents,omitempty"`
389+
388390
// Specify selectors for playbooks. The LLM will recommend the best suited playbooks
389391
// in response to the prompt.
390392
RecommendPlaybooks []types.ResourceSelector `json:"recommendPlaybooks,omitempty"`

api/v1/zz_generated.deepcopy.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crds/mission-control.flanksource.com_playbooks.yaml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,66 @@ spec:
140140
Model name based on the backend chosen.
141141
Example: gpt-4o for openai, claude-3-5-sonnet-latest for Anthropic, llama3.1:8b for Ollama
142142
type: string
143+
playbookAgents:
144+
items:
145+
properties:
146+
agent:
147+
description: |-
148+
Agent can be the agent id or the name of the agent.
149+
Additionally, the special "self" value can be used to select resources without an agent.
150+
type: string
151+
cache:
152+
description: |-
153+
Cache directives
154+
'no-cache' (should not fetch from cache but can be cached)
155+
'no-store' (should not cache)
156+
'max-age=X' (cache for X duration)
157+
type: string
158+
fieldSelector:
159+
type: string
160+
health:
161+
description: |-
162+
Health filters resources by the health.
163+
Multiple healths can be provided separated by comma.
164+
type: string
165+
id:
166+
type: string
167+
includeDeleted:
168+
type: boolean
169+
labelSelector:
170+
type: string
171+
limit:
172+
type: integer
173+
name:
174+
type: string
175+
namespace:
176+
type: string
177+
scope:
178+
description: |-
179+
Scope is the reference for parent of the resource to select.
180+
For config items, the scope is the scraper id
181+
For checks, it's canaries and
182+
For components, it's topology.
183+
It can either be a uuid or namespace/name
184+
type: string
185+
search:
186+
description: Search query that applies to the resource
187+
name, tag & labels.
188+
type: string
189+
statuses:
190+
description: Statuses filter resources by the status
191+
items:
192+
type: string
193+
type: array
194+
tagSelector:
195+
type: string
196+
types:
197+
description: Types filter resources by the type
198+
items:
199+
type: string
200+
type: array
201+
type: object
202+
type: array
143203
prompt:
144204
description: Prompt is the human prompt
145205
type: string

config/schemas/playbook-spec.schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
"dryRun": {
3939
"type": "boolean"
4040
},
41+
"playbookAgents": {
42+
"items": {
43+
"$ref": "#/$defs/ResourceSelector"
44+
},
45+
"type": "array"
46+
},
4147
"recommendPlaybooks": {
4248
"items": {
4349
"$ref": "#/$defs/ResourceSelector"

config/schemas/playbook.schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
"dryRun": {
3939
"type": "boolean"
4040
},
41+
"playbookAgents": {
42+
"items": {
43+
"$ref": "#/$defs/ResourceSelector"
44+
},
45+
"type": "array"
46+
},
4147
"recommendPlaybooks": {
4248
"items": {
4349
"$ref": "#/$defs/ResourceSelector"

fixtures/playbooks/ai-agents.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
# yaml-language-server: $schema=../../config/schemas/playbook.schema.json
3+
apiVersion: mission-control.flanksource.com/v1
4+
kind: Playbook
5+
metadata:
6+
name: use-agents
7+
spec:
8+
description: Use AI to diagnose unhealthy config items and send a notification slack
9+
configs:
10+
- name: '*'
11+
parameters:
12+
- name: prompt
13+
label: Prompt
14+
default: Find out why {{.config.name}} is unhealthy and report in one short sentence.
15+
properties:
16+
multiline: 'true'
17+
actions:
18+
- name: query LLM
19+
ai:
20+
connection: connection://mc/anthropic
21+
playbookAgents:
22+
- namespace: mc
23+
systemPrompt: |
24+
**Role:** Seasoned Kubernetes engineer and Diagnostic Expert
25+
26+
**Objective:** Assist users in diagnosing issues with unhealthy Kubernetes resources by analyzing provided manifests and related resources.
27+
28+
**Instructions:**
29+
30+
1. **Resource Analysis:** Examine the manifest of the unhealthy resource thoroughly.
31+
2. **Contextual Investigation:** Consider additional related resources provided (e.g., pods, replica sets, namespaces) to gain a comprehensive understanding of the issue.
32+
4. **One-Time Diagnosis:** Aim to diagnose the issue in a single response without requiring follow-up questions.
33+
prompt: '{{.params.prompt}}'
34+
changes:
35+
since: 2d
36+
analysis:
37+
since: 2d
38+
relationships:
39+
- depth: 3
40+
direction: outgoing
41+
changes:
42+
since: 24h
43+
- depth: 5
44+
direction: incoming
45+
changes:
46+
since: 24h

fixtures/playbooks/ai-recommend-playbook.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,7 @@ metadata:
77
spec:
88
description: Use AI to diagnose unhealthy config items and send a notification slack
99
configs:
10-
<<<<<<< HEAD
1110
- health: unhealthy,warning
12-
||||||| parent of 4e54e54 (feat(ai playbook action): formats support & playbook recommender)
13-
=======
14-
- healths:
15-
- unhealthy
16-
- warning
17-
>>>>>>> 4e54e54 (feat(ai playbook action): formats support & playbook recommender)
1811
parameters:
1912
- name: prompt
2013
label: Prompt

go.mod

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ require (
9292
dario.cat/mergo v1.0.0 // indirect
9393
github.com/GehirnInc/crypt v0.0.0-20200316065508-bb7000b8a962 // indirect
9494
github.com/Masterminds/semver/v3 v3.3.1 // indirect
95+
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
9596
github.com/Microsoft/go-winio v0.6.1 // indirect
9697
github.com/ProtonMail/go-crypto v1.0.0 // indirect
9798
github.com/RaveNoX/go-jsonmerge v1.0.0 // indirect
@@ -167,13 +168,15 @@ require (
167168
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect
168169
github.com/google/s2a-go v0.1.8 // indirect
169170
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
171+
github.com/goph/emperror v0.17.2 // indirect
170172
github.com/gorilla/websocket v1.5.1 // indirect
171173
github.com/gosimple/unidecode v1.0.1 // indirect
172174
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
173175
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
174176
github.com/hairyhenderson/yaml v0.0.0-20220618171115-2d35fca545ce // indirect
175177
github.com/hashicorp/hcl/v2 v2.21.0 // indirect
176178
github.com/hirochachacha/go-smb2 v1.1.0 // indirect
179+
github.com/huandu/xstrings v1.3.3 // indirect
177180
github.com/invopop/jsonschema v0.12.0 // indirect
178181
github.com/itchyny/gojq v0.12.17 // indirect
179182
github.com/itchyny/timefmt-go v0.1.6 // indirect
@@ -204,10 +207,12 @@ require (
204207
github.com/moby/spdystream v0.4.0 // indirect
205208
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
206209
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
210+
github.com/nikolalohinski/gonja v1.5.3 // indirect
207211
github.com/ohler55/ojg v1.25.0 // indirect
208212
github.com/oklog/ulid/v2 v2.1.0 // indirect
209213
github.com/opencontainers/go-digest v1.0.0 // indirect
210214
github.com/orcaman/concurrent-map/v2 v2.0.1 // indirect
215+
github.com/pelletier/go-toml/v2 v2.0.9 // indirect
211216
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
212217
github.com/pjbgf/sha1cd v0.3.0 // indirect
213218
github.com/pkg/sftp v1.13.6 // indirect
@@ -223,10 +228,12 @@ require (
223228
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
224229
github.com/shirou/gopsutil/v3 v3.24.5 // indirect
225230
github.com/shoenig/go-m1cpu v0.1.6 // indirect
231+
github.com/shopspring/decimal v1.2.0 // indirect
226232
github.com/shurcooL/githubv4 v0.0.0-20190718010115-4ba037080260 // indirect
227233
github.com/shurcooL/graphql v0.0.0-20181231061246-d48a9a75455f // indirect
228234
github.com/sirupsen/logrus v1.9.3 // indirect
229235
github.com/skeema/knownhosts v1.2.2 // indirect
236+
github.com/spf13/cast v1.5.0 // indirect
230237
github.com/stoewer/go-strcase v1.3.0 // indirect
231238
github.com/tidwall/gjson v1.17.0 // indirect
232239
github.com/tidwall/match v1.1.1 // indirect
@@ -243,6 +250,7 @@ require (
243250
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
244251
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
245252
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
253+
github.com/yargevad/filepathx v1.0.0 // indirect
246254
github.com/yuin/gopher-lua v1.1.1 // indirect
247255
github.com/yusufpapurcu/wmi v1.2.4 // indirect
248256
github.com/zclconf/go-cty v1.15.0 // indirect
@@ -251,6 +259,7 @@ require (
251259
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.22.0 // indirect
252260
go.opentelemetry.io/otel/metric v1.29.0 // indirect
253261
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
262+
go.starlark.net v0.0.0-20231121155337-90ade8b19d09 // indirect
254263
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f // indirect
255264
golang.org/x/mod v0.22.0 // indirect
256265
golang.org/x/sync v0.10.0 // indirect
@@ -364,7 +373,7 @@ require (
364373
sigs.k8s.io/yaml v1.4.0
365374
)
366375

367-
// replace github.com/flanksource/duty => ../duty
376+
replace github.com/flanksource/duty => ../duty
368377

369378
// replace github.com/flanksource/gomplate/v3 => ../gomplate
370379

0 commit comments

Comments
 (0)