1
+---
2
+name: "agent-zero-dev"
3
+description: "Development framework for extending and building features for the Agent Zero AI framework. Provides patterns, templates, and best practices for creating tools, extensions, skills, API endpoints, subordinate profiles, and framework components."
4
+version: "1.0.0"
5
+author: "Agent Zero Team"
6
+tags: ["development", "framework", "agent-zero", "extending", "tools", "extensions", "skills", "api"]
7
+trigger_patterns:
8
+ - "extend agent zero"
9
+ - "agent zero development"
10
+ - "build agent zero feature"
11
+ - "create agent zero tool"
12
+ - "add extension"
13
+ - "framework development"
14
+ - "agent zero skill"
15
+---
16
+
17
+# Agent Zero Development Framework
18
+
19
+This framework provides comprehensive guidance for extending and building features for the Agent Zero AI framework. Use this skill when you need to:
20
+
21
+- Create new **Tools** for agent capabilities
22
+- Add **Extensions** to hook into framework lifecycle
23
+- Build **Skills** following the SKILL.md standard
24
+- Develop **API Endpoints** for the Web UI
25
+- Create **Subordinate Profiles** for specialized agents
26
+- Extend **Projects** with custom configuration
27
+- Understand framework **Architecture** and patterns
28
+
29
+## Quick Start
30
+
31
+Choose your extension point:
32
+
33
+| Component | Use Case | Location |
34
+|-----------|----------|----------|
35
+| **Tools** | Add agent capabilities (web search, code execution) | `python/tools/` |
36
+| **Extensions** | Hook into lifecycle events | `python/extensions/<hook_point>/` |
37
+| **Skills** | Create reusable instruction bundles | `skills/custom/<skill-name>/` |
38
+| **API Endpoints** | Add Web UI functionality | `python/api/` |
39
+| **Subordinates** | Create specialized agent profiles | `agents/<profile>/` |
40
+| **Projects** | Project-specific configuration | `.a0proj/` |
41
+
42
+---
43
+
44
+## Architecture Overview
45
+
46
+### Core Components
47
+
48
+```
49
+Agent Zero Framework Architecture
50
+├── python/
51
+│ ├── tools/ # Agent capabilities (inherit from Tool)
52
+│ ├── extensions/ # Lifecycle hooks (numbered execution)
53
+│ ├── api/ # FastAPI endpoints (inherit from ApiHandler)
54
+│ └── helpers/ # Utility functions and base classes
55
+├── skills/
56
+│ ├── builtin/ # Built-in skills (system)
57
+│ ├── custom/ # User-created skills
58
+│ └── frameworks/ # Multi-phase framework skills
59
+├── agents/
60
+│ └── <profile>/ # Subordinate agent profiles
61
+├── memory/ # FAISS-based vector memory
62
+└── tmp/
63
+ └── chats/ # Conversation storage
64
+```
65
+
66
+### Key Patterns
67
+
68
+1. **Extensions execute in numeric order** (`_10_*.py`, `_20_*.py`, etc.)
69
+2. **Tools inherit from `Tool` base class** with `execute()` method
70
+3. **Skills use progressive disclosure** (metadata → content → scripts)
71
+4. **Shared AgentContext** enables memory persistence across agents
72
+5. **Async/await throughout** for non-blocking operations
73
+
74
+---
75
+
76
+## Creating Tools
77
+
78
+Tools are the primary way agents interact with the world. Each tool inherits from the `Tool` base class.
79
+
80
+### Tool Structure
81
+
82
+```python
83
+# python/tools/my_tool.py
84
+from python.helpers.tool import Tool, Response
85
+
86
+class MyTool(Tool):
87
+ """
88
+ Brief description of what this tool does.
89
+
90
+ Arguments (tool_args):
91
+ - arg1: Description of first argument
92
+ - arg2: Description of second argument
93
+ """
94
+
95
+ async def execute(self, **kwargs) -> Response:
96
+ # Get arguments from kwargs or self.args
97
+ arg1 = kwargs.get("arg1") or self.args.get("arg1")
98
+ arg2 = kwargs.get("arg2") or self.args.get("arg2")
99
+
100
+ # Tool logic here
101
+ result = await self.do_something(arg1, arg2)
102
+
103
+ return Response(
104
+ message=result,
105
+ break_loop=False # Set True to end agent loop
106
+ )
107
+
108
+ async def do_something(self, arg1, arg2):
109
+ # Implement tool functionality
110
+ pass
111
+```
112
+
113
+### Tool Best Practices
114
+
115
+1. **Always document args** in the class docstring
116
+2. **Use `Response` objects** for consistent return format
117
+3. **Handle errors gracefully** - return error message, don't crash
118
+4. **Access agent context** via `self.agent.context`
119
+5. **Use kwargs fallback** to `self.args` for flexibility
120
+
121
+### Example: Complete Tool
122
+
123
+```python
124
+# python/tools/data_processor.py
125
+from python.helpers.tool import Tool, Response
126
+import json
127
+
128
+class DataProcessor(Tool):
129
+ """
130
+ Process and transform data structures.
131
+
132
+ Arguments (tool_args):
133
+ - operation: The operation to perform (filter, map, reduce)
134
+ - data: JSON data to process
135
+ - key: Key to filter/sort by (for filter/sort operations)
136
+ - value: Value to filter by (for filter operation)
137
+ """
138
+
139
+ async def execute(self, **kwargs) -> Response:
140
+ try:
141
+ operation = kwargs.get("operation") or self.args.get("operation", "")
142
+ data_str = kwargs.get("data") or self.args.get("data", "[]")
143
+ key = kwargs.get("key") or self.args.get("key")
144
+ value = kwargs.get("value") or self.args.get("value")
145
+
146
+ data = json.loads(data_str)
147
+
148
+ if operation == "filter":
149
+ result = [item for item in data if item.get(key) == value]
150
+ elif operation == "sort":
151
+ result = sorted(data, key=lambda x: x.get(key))
152
+ else:
153
+ return Response(message=f"Unknown operation: {operation}", break_loop=False)
154
+
155
+ return Response(
156
+ message=json.dumps(result, indent=2),
157
+ break_loop=False
158
+ )
159
+ except Exception as e:
160
+ return Response(message=f"Error processing data: {e}", break_loop=False)
161
+```
162
+
163
+---
164
+
165
+## Creating Extensions
166
+
167
+Extensions hook into specific points in the agent lifecycle. They execute in numeric order.
168
+
169
+### Extension Hook Points
170
+
171
+| Hook Point | When It Fires | Use For |
172
+|------------|---------------|---------|
173
+| `agent_init` | Agent initialization | Loading configs, setting defaults |
174
+| `message_loop_start` | Before message processing | Pre-processing, logging |
175
+| `message_loop_end` | After message processing | Cleanup, post-processing |
176
+| `before_main_llm_call` | Before LLM API call | Modifying prompts, adding context |
177
+| `response_stream_start` | When response streaming begins | Initializing stream handlers |
178
+| `response_stream_chunk` | Per response chunk | Transforming output |
179
+| `response_stream_end` | When streaming ends | Finalizing, cleanup |
180
+| `tool_execute_before` | Before tool execution | Validation, logging |
181
+| `tool_execute_after` | After tool execution | Post-processing results |
182
+
183
+### Extension Structure
184
+
185
+```python
186
+# python/extensions/<hook_point>/_10_my_extension.py
187
+from python.helpers.extension import Extension
188
+from python.helpers.print_style import PrintStyle
189
+
190
+class MyExtension(Extension):
191
+ """
192
+ Brief description of extension purpose.
193
+ """
194
+
195
+ async def execute(self, **kwargs):
196
+ # Access the agent
197
+ agent = self.agent
198
+ context = agent.context
199
+
200
+ # Extension logic
201
+ PrintStyle.hint("MyExtension executing...")
202
+
203
+ # Modify data if needed (check kwargs for hook-specific data)
204
+ data = kwargs.get("data", {})
205
+ data["modified"] = True
206
+
207
+ # Return modified data if applicable
208
+ return data
209
+```
210
+
211
+### Extension Execution Order
212
+
213
+Extensions execute in numeric order based on filename prefix:
214
+
215
+```
216
+_10_load_config.py # Runs first
217
+_20_validate.py # Runs second
218
+_30_process.py # Runs third
219
+```
220
+
221
+Use 10-number increments to leave room for future extensions.
222
+
223
+### Example: Agent Init Extension
224
+
225
+```python
226
+# python/extensions/agent_init/_15_load_custom_config.py
227
+from python.helpers.extension import Extension
228
+from python.helpers import files
229
+import json
230
+
231
+class LoadCustomConfig(Extension):
232
+ """
233
+ Load custom configuration from .a0proj/config.json
234
+ """
235
+
236
+ async def execute(self, **kwargs):
237
+ agent = self.agent
238
+ context = agent.context
239
+
240
+ config_path = files.get_abs_path(".a0proj/config.json")
241
+ if files.exists(config_path):
242
+ with open(config_path, 'r') as f:
243
+ config = json.load(f)
244
+ context.data["custom_config"] = config
245
+
246
+ return kwargs.get("data", {})
247
+```
248
+
249
+---
250
+
251
+## Creating Skills
252
+
253
+Skills are reusable instruction bundles following the SKILL.md standard.
254
+
255
+### Skill Directory Structure
256
+
257
+```
258
+skills/custom/my-skill/
259
+├── SKILL.md # Required: Main skill file
260
+├── scripts/ # Optional: Helper scripts
261
+│ ├── helper.py
262
+│ └── process.sh
263
+├── templates/ # Optional: Templates
264
+│ └── template.md
265
+└── docs/ # Optional: Additional docs
266
+ └── examples.md
267
+```
268
+
269
+### SKILL.md Format
270
+
271
+```yaml
272
+---
273
+name: "skill-name"
274
+description: "Clear description of what this skill does and when to use it"
275
+version: "1.0.0"
276
+author: "Your Name"
277
+tags: ["category1", "category2"]
278
+trigger_patterns:
279
+ - "keyword1"
280
+ - "phrase that triggers this"
281
+---
282
+
283
+# Skill Title
284
+
285
+## When to Use
286
+Describe trigger conditions and use cases.
287
+
288
+## The Process
289
+Step-by-step instructions for the agent to follow.
290
+
291
+### Step 1: First Action
292
+Details...
293
+
294
+### Step 2: Second Action
295
+Details...
296
+
297
+## Examples
298
+Show sample interactions.
299
+
300
+## Scripts
301
+Reference any helper scripts:
302
+- `scripts/helper.py` - Does X
303
+- `scripts/process.sh` - Does Y
304
+
305
+## Tips
306
+Additional guidance and best practices.
307
+```
308
+
309
+### Using Skills
310
+
311
+```python
312
+# Load skill metadata
313
+await skills_tool.execute(method="list")
314
+
315
+# Load full skill content
316
+await skills_tool.execute(method="load", skill_name="my-skill")
317
+
318
+# Execute skill script
319
+await skills_tool.execute(
320
+ method="execute_script",
321
+ skill_name="my-skill",
322
+ script_path="scripts/helper.py",
323
+ script_args={"input": "value"},
324
+ arg_style="positional" # or "named" or "env"
325
+)
326
+```
327
+
328
+---
329
+
330
+## Creating API Endpoints
331
+
332
+API endpoints serve the Web UI and external clients using FastAPI.
333
+
334
+### API Endpoint Structure
335
+
336
+```python
337
+# python/api/my_endpoint.py
338
+from python.helpers.api import ApiHandler, Request, Response
339
+from agent import AgentContext
340
+
341
+class MyEndpoint(ApiHandler):
342
+ """
343
+ Handle requests for /api/my-endpoint
344
+ """
345
+
346
+ async def process(self, input: dict, request: Request) -> dict | Response:
347
+ # Get query params or JSON body
348
+ param = input.get("param", "default")
349
+
350
+ # Get or create agent context
351
+ ctxid = input.get("context", "")
352
+ context = self.use_context(ctxid)
353
+
354
+ # Process request
355
+ result = await self.process_request(param, context)
356
+
357
+ return {
358
+ "result": result,
359
+ "context": context.id,
360
+ }
361
+
362
+ async def process_request(self, param, context):
363
+ # Implement endpoint logic
364
+ return {"processed": param}
365
+```
366
+
367
+### API Best Practices
368
+
369
+1. **Use `ApiHandler` base class** for consistent request/response handling
370
+2. **Get context with `self.use_context(ctxid)`** - creates if not exists
371
+3. **Return dict or Response** objects
372
+4. **Handle both GET and POST** if applicable
373
+5. **Use `Request` object** for accessing headers, files, etc.
374
+
375
+### Example: File Upload Endpoint
376
+
377
+```python
378
+# python/api/upload_processor.py
379
+from python.helpers.api import ApiHandler, Request
380
+from werkzeug.utils import secure_filename
381
+import os
382
+
383
+class UploadProcessor(ApiHandler):
384
+ async def process(self, input: dict, request: Request) -> dict:
385
+ if request.method == "POST":
386
+ uploaded_file = request.files.get("file")
387
+ if uploaded_file:
388
+ filename = secure_filename(uploaded_file.filename)
389
+ save_path = f"/tmp/uploads/{filename}"
390
+ uploaded_file.save(save_path)
391
+
392
+ return {
393
+ "success": True,
394
+ "filename": filename,
395
+ "path": save_path
396
+ }
397
+
398
+ return {"success": False, "error": "No file provided"}
399
+```
400
+
401
+---
402
+
403
+## Creating Subordinate Profiles
404
+
405
+Subordinates are specialized agents with custom prompts and configurations.
406
+
407
+### Profile Directory Structure
408
+
409
+```
410
+agents/<profile-name>/
411
+├── agent.json # Profile configuration
412
+└── prompts/
413
+ ├── system.md # System prompt
414
+ └── subordinates.md # Subordinate delegation prompts
415
+```
416
+
417
+### agent.json Configuration
418
+
419
+```json
420
+{
421
+ "name": "Specialized Agent",
422
+ "description": "What this subordinate specializes in",
423
+ "model": "anthropic/claude-sonnet-4-20250514",
424
+ "temperature": 0.7,
425
+ "max_tokens": 4000,
426
+ "allowed_tools": [
427
+ "code_execution_tool",
428
+ "search_engine",
429
+ "call_subordinate"
430
+ ],
431
+ "prompts": {
432
+ "system": "prompts/system.md",
433
+ "subordinates": "prompts/subordinates.md"
434
+ }
435
+}
436
+```
437
+
438
+### System Prompt Template
439
+
440
+```markdown
441
+# System Prompt for Specialized Agent
442
+
443
+## Your Role
444
+You are a specialized agent focused on [domain].
445
+
446
+## Capabilities
447
+- Expertise in [specific area]
448
+- Use tools: code_execution_tool, search_engine
449
+
450
+## Process
451
+1. Analyze the request
452
+2. Choose appropriate tools
453
+3. Execute and verify results
454
+4. Return structured response
455
+
456
+## Output Format
457
+Always respond with valid JSON:
458
+```json
459
+{
460
+ "result": "your result here",
461
+ "confidence": 0.95
462
+}
463
+```
464
+```
465
+
466
+### Using Subordinates
467
+
468
+```python
469
+# Call from main agent
470
+call_subordinate(
471
+ profile="developer",
472
+ message="Implement a Python function to calculate Fibonacci",
473
+ reset="true"
474
+)
475
+```
476
+
477
+---
478
+
479
+## Creating Projects
480
+
481
+Projects provide isolated workspaces with custom configuration.
482
+
483
+### Project Structure
484
+
485
+```
486
+/usr/projects/<project-name>/
487
+├── .a0proj/
488
+│ ├── config.json # Project configuration
489
+│ ├── instructions.md # Project-specific instructions
490
+│ └── skills/ # Project-specific skills
491
+└── <project-files>/ # Your project files
492
+```
493
+
494
+### config.json
495
+
496
+```json
497
+{
498
+ "name": "My Project",
499
+ "description": "Project description",
500
+ "default_model": "anthropic/claude-sonnet-4-20250514",
501
+ "allowed_tools": ["*"],
502
+ "extensions": {
503
+ "enabled": ["custom_extension"]
504
+ },
505
+ "skills": {
506
+ "auto_load": ["project-specific-skill"]
507
+ }
508
+}
509
+```
510
+
511
+### instructions.md
512
+
513
+```markdown
514
+# Project: My Project
515
+
516
+## Overview
517
+This project does X, Y, Z.
518
+
519
+## Coding Standards
520
+- Use Python 3.12+ features
521
+- Follow PEP 8
522
+- Write tests for all functions
523
+
524
+## Architecture
525
+- API layer in `api/`
526
+- Business logic in `services/`
527
+- Models in `models/`
528
+```
529
+
530
+---
531
+
532
+## Framework Development Workflow
533
+
534
+When building features for Agent Zero itself, follow this workflow:
535
+
536
+### Phase 1: Brainstorming
537
+- Define the problem and solution
538
+- Identify extension points (tool, extension, skill, API)
539
+- Review existing patterns for consistency
540
+
541
+### Phase 2: Planning
542
+- Break work into small tasks (2-5 min each)
543
+- Identify dependencies and order
544
+- Write verification criteria for each task
545
+
546
+### Phase 3: Implementation
547
+- Create feature branch (use git worktrees)
548
+- Follow TDD: test first, then implement
549
+- Match existing code patterns
550
+
551
+### Phase 4: Code Review
552
+- Review against plan
553
+- Check pattern consistency
554
+- Verify tests pass
555
+
556
+### Phase 5: Integration
557
+- Merge to main
558
+- Update documentation
559
+- Test in production context
560
+
561
+---
562
+
563
+## Common Patterns Reference
564
+
565
+### Accessing Context Data
566
+
567
+```python
568
+# Shared across all agents in conversation
569
+context = self.agent.context
570
+data = context.data # dict-like shared memory
571
+
572
+# Store data
573
+data["my_key"] = my_value
574
+
575
+# Retrieve data
576
+value = data.get("my_key", default)
577
+```
578
+
579
+### Using Helpers
580
+
581
+```python
582
+from python.helpers import files, extension, print_style
583
+
584
+# File operations
585
+content = files.read_file("path/to/file")
586
+files.write_file("path/to/file", content)
587
+exists = files.exists("path/to/file")
588
+
589
+# Extensions
590
+await extension.call_extensions("hook_point", agent=agent, data=data)
591
+
592
+# Printing
593
+PrintStyle.hint("Hint message")
594
+PrintStyle.warning("Warning message")
595
+PrintStyle.error("Error message")
596
+```
597
+
598
+### Error Handling
599
+
600
+```python
601
+try:
602
+ result = await risky_operation()
603
+except Exception as e:
604
+ # Log for debugging
605
+ PrintStyle.error(f"Operation failed: {e}")
606
+ # Return graceful error to user
607
+ return Response(message=f"Error: {e}", break_loop=False)
608
+```
609
+
610
+### Async Patterns
611
+
612
+```python
613
+# Concurrent execution
614
+tasks = [process_item(item) for item in items]
615
+results = await asyncio.gather(*tasks)
616
+
617
+# Timeouts
618
+try:
619
+ result = await asyncio.wait_for(operation(), timeout=30)
620
+except asyncio.TimeoutError:
621
+ return Response(message="Operation timed out", break_loop=False)
622
+```
623
+
624
+---
625
+
626
+## Testing Your Extensions
627
+
628
+### Manual Testing
629
+
630
+1. **Restart the framework** after code changes
631
+2. **Test with minimal input** first
632
+3. **Check logs** for errors: `docker logs -f agent-zero`
633
+4. **Verify in UI** that changes appear correctly
634
+
635
+### Unit Testing (when available)
636
+
637
+```python
638
+# tests/tools/test_my_tool.py
639
+import pytest
640
+from python.tools.my_tool import MyTool
641
+
642
+@pytest.mark.asyncio
643
+async def test_my_tool():
644
+ tool = MyTool()
645
+ result = await tool.execute(operation="test", data="{}")
646
+ assert "success" in result.message
647
+```
648
+
649
+---
650
+
651
+## Scripts and Templates
652
+
653
+This skill includes helper scripts and templates:
654
+
655
+### Scripts
656
+
657
+| Script | Purpose | Usage |
658
+|--------|---------|-------|
659
+| `scripts/create_tool.py` | Generate tool boilerplate | `python scripts/create_tool.py ToolName` |
660
+| `scripts/create_extension.py` | Generate extension boilerplate | `python scripts/create_extension.py HookPoint ExtensionName` |
661
+| `scripts/create_skill.py` | Generate skill boilerplate | `python scripts/create_skill.py skill-name` |
662
+| `scripts/create_api.py` | Generate API endpoint boilerplate | `python scripts/create_api.py EndpointName` |
663
+
664
+### Templates
665
+
666
+| Template | Purpose |
667
+|----------|---------|
668
+| `templates/tool.py` | Tool boilerplate |
669
+| `templates/extension.py` | Extension boilerplate |
670
+| `templates/SKILL.md` | Skill boilerplate |
671
+| `templates/api.py` | API endpoint boilerplate |
672
+
673
+---
674
+
675
+## Best Practices Summary
676
+
677
+### DO
678
+- ✅ Follow existing patterns and conventions
679
+- ✅ Write clear docstrings and comments
680
+- ✅ Handle errors gracefully
681
+- ✅ Use type hints where applicable
682
+- ✅ Test your changes thoroughly
683
+- ✅ Update documentation
684
+- ✅ Use meaningful names
685
+
686
+### DON'T
687
+- ❌ Break existing functionality
688
+- ❌ Ignore error cases
689
+- ❌ Hardcode paths or values
690
+- ❌ Skip documentation
691
+- ❌ Mix sync and async code carelessly
692
+- ❌ Access internal structures directly when helpers exist
693
+
694
+---
695
+
696
+## Need Help?
697
+
698
+Use this skill by saying:
699
+- "Help me create a new tool for..."
700
+- "I want to add an extension that..."
701
+- "Create a skill for..."
702
+- "Build an API endpoint for..."
703
+- "How do I extend Agent Zero to..."
704
+
705
+I'll guide you through the appropriate patterns and generate boilerplate code!