Skip to content

Commit f260b11

Browse files
authored
Merge pull request #1 from Tweakzx/feature/agent-extensibility
Feature/agent extensibility
2 parents 58a1e11 + b6524e5 commit f260b11

36 files changed

+8861
-34
lines changed

cpu.prof

6.53 KB
Binary file not shown.

docs/ARCHITECTURE.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,54 @@ func generateActionPreview(action *K8sAction) *models.ActionPreview {
374374

375375
---
376376

377+
## 工具系统架构
378+
379+
工具系统为 K8s 操作提供统一的抽象层:
380+
381+
### 工具接口
382+
```go
383+
type Tool interface {
384+
Name() string
385+
Description() string
386+
Category() string
387+
Parameters() []Parameter
388+
DangerLevel() DangerLevel
389+
Execute(ctx context.Context, args map[string]interface{}) (Result, error)
390+
}
391+
```
392+
393+
### 注册表模式
394+
工具注册表支持动态发现和路由:
395+
- 工具通过 `registry.Register(tool)` 自注册
396+
- LLM 可通过 `registry.GetLLMDescriptions()` 查询可用工具
397+
- 工具通过 `registry.Execute(ctx, name, args)` 执行
398+
399+
### 处理器模式
400+
资源处理器连接 K8s API 和工具:
401+
- 每种资源类型一个处理器(deployment、pod、service 等)
402+
- 每个处理器定义操作(create、get、scale、delete)
403+
- 处理器自动将其操作注册为工具
404+
405+
### 子图
406+
可复用的工作流片段,用于复杂操作(计划中的实现):
407+
- 子图将封装多步骤工作流,如日志获取、Pod 执行和诊断
408+
- 接口定义在 `pkg/workflow/subgraph.go`
409+
- 具体实现将在后续阶段开发
410+
411+
### 上下文管理
412+
ContextManager 维护对话历史:
413+
- 跟踪上次操作、资源、命名空间
414+
- 通过 CheckpointerManager 持久化到 SQLite
415+
- 为 LLM 提供格式化的上下文
416+
417+
### 迁移策略
418+
新工具系统设计用于渐进式采用:
419+
- 工具注册表和处理器与现有代码路径共存
420+
- 按资源类型逐步迁移
421+
- 无需功能标志 - 根据操作/资源类型自动路由
422+
423+
---
424+
377425
## 扩展性设计
378426

379427
### 1. 插件化节点

docs/MIGRATION.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Migration Guide: Agent Extensibility
2+
3+
## Overview
4+
5+
This guide explains how to migrate existing K8s operations to the new tool system.
6+
7+
## Architecture Changes
8+
9+
### Before (Direct Code Paths)
10+
```go
11+
// Intent parser directly calls K8s client
12+
if intent.Action == "create" && intent.Resource == "deployment" {
13+
// Direct K8s client call
14+
deployment := &appsv1.Deployment{...}
15+
client.Create(deployment)
16+
}
17+
```
18+
19+
### After (Tool System)
20+
```go
21+
// Intent parser routes through tool registry
22+
toolName := fmt.Sprintf("%s_%s", intent.Action, intent.Resource)
23+
result, err := registry.Execute(ctx, toolName, args)
24+
```
25+
26+
## Migration Steps
27+
28+
### Step 1: Create Handler
29+
```go
30+
// pkg/k8s/handlers/myresource.go
31+
type MyResourceHandler struct {
32+
*BaseHandler
33+
}
34+
35+
func NewMyResourceHandler(clientset kubernetes.Interface) *MyResourceHandler {
36+
base := NewBaseHandler(clientset, "myresource")
37+
base.ops = []Operation{...}
38+
return &MyResourceHandler{BaseHandler: base}
39+
}
40+
```
41+
42+
### Step 2: Register Handler
43+
```go
44+
// In agent initialization
45+
handler := NewMyResourceHandler(clientset)
46+
err := handler.RegisterTools(deps.ToolRegistry)
47+
```
48+
49+
### Step 3: Enable Routing
50+
Note: The tool system is designed to coexist with existing code paths. Once handlers are registered, operations will automatically route through the tool registry based on the action and resource type.
51+
52+
## Architecture Evolution
53+
54+
The new tool system is being incrementally adopted:
55+
- Phase 1: Tool registry and handler abstraction (completed)
56+
- Phase 2: Sub-graph integration (in progress)
57+
- Phase 3: Context-aware routing (planned)
58+
59+
During migration, both old and new code paths remain available, allowing for gradual adoption per resource type.
60+
61+
## Testing
62+
63+
Verify migration:
64+
1. Run unit tests: `go test ./pkg/k8s/handlers/...`
65+
2. Run integration tests: `go test ./test/integration/...`
66+
3. Test in development environment

docs/ROADMAP.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
# K8s Wizard Development Roadmap
22

3+
## Completed
4+
5+
- [x] Tool system with Registry pattern
6+
- [x] Resource handler abstraction
7+
- [x] Prompt loader with YAML templates
8+
- [x] Sub-graph interface for reusable workflows
9+
- [x] ContextManager for conversation tracking
10+
11+
## In Progress
12+
13+
- [ ] Migration of all existing resources to handlers
14+
- [ ] Sub-graph implementation (logs, exec, diagnostics)
15+
16+
## Future
17+
18+
- [ ] Additional resource handlers (StatefulSet, DaemonSet, ConfigMap, Secret)
19+
- [ ] Advanced sub-graphs (multi-pod workflows, deployment strategies)
20+
- [ ] Enhanced context awareness (cross-session context, semantic search)
21+
22+
---
23+
324
## 📊 Current Status (v0.1.0)
425

526
### ✅ Implemented Features
@@ -219,25 +240,25 @@ AI monitors cluster and suggests:
219240
## 📅 Timeline
220241
221242
```
222-
2025 Q1 (v0.2.0)
243+
2026 Q1 (v0.2.0)
223244
├── Session Management
224245
├── Streaming Response
225246
├── Markdown Rendering
226247
└── Safety Confirmation
227248

228-
2025 Q2 (v0.3.0)
249+
2026 Q2 (v0.3.0)
229250
├── Logs Support
230251
├── Exec Support
231252
├── Describe Support
232253
└── Extended Resources
233254

234-
2025 Q3 (v0.4.0)
255+
2026 Q3 (v0.4.0)
235256
├── YAML Editor
236257
├── Templates
237258
├── History
238259
└── Multi-cluster
239260

240-
2025 Q4 (v0.5.0)
261+
2026 Q4 (v0.5.0)
241262
├── Authentication
242263
├── Audit Logging
243264
├── Metrics
@@ -301,5 +322,5 @@ AI monitors cluster and suggests:
301322

302323
---
303324

304-
*Last Updated: 2025-03-01*
325+
*Last Updated: 2026-03-15*
305326
*Version: 0.1.1*

0 commit comments

Comments
 (0)