MSGEncrypted commited on
Commit
38e44da
·
1 Parent(s): 1f5cc33

wip agent skills

Browse files
.cursor/plans/skill_agent_pptx_5413e3c2.plan.md ADDED
@@ -0,0 +1,230 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ name: Skill Agent PPTX
3
+ overview: Add a Hermes-style skill agent library on top of your existing TransformersBackend, with one education PowerPoint task as the first tab in a multi-tab Gradio Space — structured so more task tabs can be added later.
4
+ todos:
5
+ - id: agent-lib
6
+ content: "Create libs/agent: SkillRegistry, ToolRegistry, AgentRunner, TraceRecorder, pydantic outline models"
7
+ status: pending
8
+ - id: pptx-skill
9
+ content: Add skills/education-pptx/SKILL.md and create_pptx tool (python-pptx)
10
+ status: pending
11
+ - id: gradio-tabs
12
+ content: "Refactor Gradio app into Tabs: Education PPTX (primary) + Chat (debug)"
13
+ status: pending
14
+ - id: docker-workspace
15
+ content: Wire agent package into uv workspace, Dockerfile, models.yaml active_model
16
+ status: pending
17
+ - id: trace-demo
18
+ content: Add trace JSON export + README demo script for hackathon submission
19
+ status: pending
20
+ isProject: false
21
+ ---
22
+
23
+ # Skill Agent + Education PowerPoint (Phase 1)
24
+
25
+ ## Goal
26
+
27
+ Replace the generic chat demo with a **local skill-based agent** that uses your **transformers** presets (default: `minicpm5-1b` or `openbmb/MiniCPM5-1B` from [`models.yaml`](models.yaml)) to run a real workflow: **topic in → slide outline → downloadable `.pptx` out**.
28
+
29
+ This follows the **agentskills.io / Hermes SKILL.md pattern** without embedding the full Hermes runtime (too heavy for HF Space Docker).
30
+
31
+ **Hackathon alignment:** Backyard AI (teacher/tutor you know), **Best Agent**, **Tiny Titan** (≤4B), **OpenBMB** (MiniCPM), **Sharing is Caring** (publish trace JSON to Hub), optional **Well-Tuned** if you ship a fine-tuned preset later.
32
+
33
+ ---
34
+
35
+ ## Architecture
36
+
37
+ ```mermaid
38
+ flowchart TB
39
+ subgraph ui [apps/gradio-space]
40
+ Tabs[gr.Tabs]
41
+ EduTab[EducationPptxTab]
42
+ ChatTab[ChatTab optional later]
43
+ Tabs --> EduTab
44
+ end
45
+
46
+ subgraph agent [libs/agent]
47
+ Runner[AgentRunner]
48
+ Skills[SkillRegistry]
49
+ Tools[ToolRegistry]
50
+ Trace[TraceRecorder]
51
+ Runner --> Skills
52
+ Runner --> Tools
53
+ Runner --> Trace
54
+ end
55
+
56
+ subgraph inference [libs/inference]
57
+ Factory[factory.get_backend]
58
+ TF[TransformersBackend]
59
+ Factory --> TF
60
+ end
61
+
62
+ EduTab --> Runner
63
+ Runner --> Factory
64
+ Tools --> PptxTool[python-pptx]
65
+ ```
66
+
67
+ **Agent loop (simple, reliable for small models):**
68
+
69
+ 1. Load skill `education-pptx` from `skills/education-pptx/SKILL.md`
70
+ 2. User provides: topic, grade level, number of slides (3–8)
71
+ 3. **Step A — LLM:** generate structured slide outline (JSON schema in prompt; parse with fallback regex)
72
+ 4. **Step B — Tool:** `create_pptx(outline)` writes file via `python-pptx` (deterministic; no LLM needed for file bytes)
73
+ 5. **Step C — LLM (optional):** one-sentence “teacher notes” per slide
74
+ 6. Return: trace steps + `gr.File` download + markdown preview
75
+
76
+ Small models are weak at multi-hop tool JSON — keep the loop **fixed 2-step** (outline → tool) rather than open-ended ReAct for v1.
77
+
78
+ ---
79
+
80
+ ## New package: `libs/agent`
81
+
82
+ Add workspace member `libs/agent` with:
83
+
84
+ | Module | Responsibility |
85
+ |--------|----------------|
86
+ | `skills.py` | Load `SKILL.md` (YAML frontmatter + body), list skills by `task` tag |
87
+ | `tools.py` | Register callable tools with name, description, JSON schema |
88
+ | `runner.py` | `AgentRunner.run(skill_id, user_input, backend)` — orchestrates LLM + tools |
89
+ | `trace.py` | Append-only step log (`thought`, `tool_call`, `tool_result`, `artifact`) |
90
+ | `prompts.py` | Skill-specific system prompts and JSON outline template |
91
+
92
+ **Dependencies:** `inference` (workspace), `python-pptx`, `pydantic` (outline validation)
93
+
94
+ **Extend [`libs/inference/src/inference/base.py`](libs/inference/src/inference/base.py) usage only** — no changes required to `TransformersBackend` beyond optionally bumping `max_tokens` for outline generation via env or per-call kwargs (already supported in [`transformers.py`](libs/inference/src/inference/transformers.py)).
95
+
96
+ ---
97
+
98
+ ## First skill: `skills/education-pptx/SKILL.md`
99
+
100
+ ```markdown
101
+ ---
102
+ name: education-pptx
103
+ description: Create a short lesson PowerPoint from a topic and grade level
104
+ task: education
105
+ tools:
106
+ - create_pptx
107
+ model_hints:
108
+ - minicpm5-1b
109
+ - qwen3b-gguf
110
+ ---
111
+
112
+ ## Workflow
113
+ 1. Ask for topic, audience grade, slide count.
114
+ 2. Produce JSON outline: title, slides[{title, bullets[], speaker_note}].
115
+ 3. Call create_pptx with validated outline.
116
+ 4. Return download link and preview.
117
+ ```
118
+
119
+ ---
120
+
121
+ ## First tool: `create_pptx`
122
+
123
+ Implement in `libs/agent/src/agent/tools/pptx.py`:
124
+
125
+ - Input: Pydantic model `SlideOutline` (title, slides list)
126
+ - Output: path under `/tmp/agent_outputs/{run_id}.pptx` (HF Space writable temp)
127
+ - Simple template: title slide + bullet slides + optional speaker notes in notes field
128
+ - No images in v1 (keeps scope shippable by June 15)
129
+
130
+ ---
131
+
132
+ ## Gradio UI changes: [`apps/gradio-space/src/gradio_space/app.py`](apps/gradio-space/src/gradio_space/app.py)
133
+
134
+ Refactor into:
135
+
136
+ ```
137
+ gradio_space/
138
+ app.py # build_demo(), launch
139
+ tabs/
140
+ __init__.py
141
+ education_pptx.py # first task tab
142
+ chat.py # move existing ChatInterface here (secondary tab)
143
+ ```
144
+
145
+ **Tab 1 — Lesson Slides (primary submission UI):**
146
+
147
+ - Inputs: Topic, Grade (dropdown), Slides (slider 3–8)
148
+ - Button: Generate
149
+ - Outputs: Markdown outline preview, File download, Agent trace (accordion)
150
+ - Status line: model name + device from existing `warmup()` / `model_status()`
151
+
152
+ **Tab 2 — Chat (keep for debugging):** existing chat wired to same `ACTIVE_MODEL`
153
+
154
+ Use `gr.Tabs()` at top level; only Tab 1 needs polish for demo video.
155
+
156
+ **Model default for Space:** set `active_model: minicpm5-1b` in [`models.yaml`](models.yaml) (OpenBMB + Tiny Titan). Space hardware: GPU basic if transformers on CPU is too slow.
157
+
158
+ ---
159
+
160
+ ## Trace export (Sharing is Caring badge)
161
+
162
+ After each run, write trace JSON to `outputs/traces/{run_id}.json` and expose a “Copy trace” / optional Hub dataset upload script:
163
+
164
+ - `scripts/upload_trace.py` — pushes latest trace to a HF dataset repo (manual one-time setup; not required for v1 demo)
165
+
166
+ Trace schema (minimal):
167
+
168
+ ```json
169
+ {
170
+ "skill": "education-pptx",
171
+ "model": "minicpm5-1b",
172
+ "input": {"topic": "...", "grade": "6", "slides": 5},
173
+ "steps": [{"type": "llm", "prompt_hash": "...", "output": "..."}, {"type": "tool", "name": "create_pptx", "result": "..."}],
174
+ "artifact": "lesson_photosynthesis.pptx"
175
+ }
176
+ ```
177
+
178
+ ---
179
+
180
+ ## Docker / workspace updates
181
+
182
+ - [`pyproject.toml`](pyproject.toml): add `agent` workspace member + root dep
183
+ - [`Dockerfile`](Dockerfile): COPY `libs/agent`, `skills/`, update `uv sync`
184
+ - [`apps/gradio-space/pyproject.toml`](apps/gradio-space/pyproject.toml): depend on `agent`
185
+ - Update root [`README.md`](README.md) hackathon story: “Lesson slide builder for a teacher you know”
186
+
187
+ ---
188
+
189
+ ## Phase 2 (after v1 ships — not in first PR)
190
+
191
+ - New tabs: `tabs/quiz_maker.py`, `tabs/worksheet.py` — each maps to a new `skills/*/SKILL.md`
192
+ - `SkillRegistry` already supports multiple skills; tabs just call `AgentRunner.run(skill_id=...)`
193
+ - **Off-Brand:** custom layout via `gr.Blocks` theming or `gr.Server` if time allows
194
+ - Fine-tuned Gemma preset from [`notebook/gemma-finetune.ipynb`](notebook/gemma-finetune.ipynb) for **Well-Tuned** badge
195
+
196
+ ---
197
+
198
+ ## Demo video script (for submission)
199
+
200
+ 1. Introduce real user (teacher/tutor) and problem: “building a 5-slide lesson takes 30+ minutes”
201
+ 2. Enter topic + grade in Tab 1, click Generate (~30–90s on GPU)
202
+ 3. Show outline preview + download `.pptx`, open in LibreOffice/Google Slides
203
+ 4. Show agent trace proving local model + tool pipeline (no cloud LLM API)
204
+
205
+ ---
206
+
207
+ ## Risks and mitigations
208
+
209
+ | Risk | Mitigation |
210
+ |------|------------|
211
+ | Small model outputs invalid JSON | Pydantic validate + one repair retry with “fix JSON only” prompt |
212
+ | CPU Space too slow | Pin `minicpm5-1b`, use GPU basic, or fallback `qwen3b-gguf` + llama.cpp for outline-only step |
213
+ | pptx dependency size | `python-pptx` is lightweight (~few MB) |
214
+ | Scope creep (many tabs) | Ship Tab 1 only; stub Tab 2 chat for dev |
215
+
216
+ ---
217
+
218
+ ## Files to create / modify (summary)
219
+
220
+ **Create:**
221
+ - `libs/agent/` (package + runner, tools, skills loader, trace)
222
+ - `skills/education-pptx/SKILL.md`
223
+ - `apps/gradio-space/src/gradio_space/tabs/education_pptx.py`
224
+ - `apps/gradio-space/src/gradio_space/tabs/chat.py`
225
+
226
+ **Modify:**
227
+ - [`apps/gradio-space/src/gradio_space/app.py`](apps/gradio-space/src/gradio_space/app.py) — Tabs shell
228
+ - [`models.yaml`](models.yaml) — `active_model: minicpm5-1b` for Space
229
+ - [`Dockerfile`](Dockerfile), [`pyproject.toml`](pyproject.toml), workspace lockfile
230
+ - [`README.md`](README.md) — product story + agent docs