Commit a5a305b
feat: Add structured I/O foundation (Output/Input Schemas)
Implements structured input/output schema support similar to Agno's
Pydantic-based approach, using JSON Schema for Rust.
## Changes
### Core Types (`aof-core/src/schema.rs`)
- **OutputSchema**: JSON Schema for validated LLM responses
- Schema validation with type checking
- LLM tool conversion for structured output
- System prompt instructions generation
- Format hints (table, list, json, yaml, auto)
- **InputSchema**: JSON Schema for input validation
- Type-safe input validation
- Runtime schema enforcement
- **Pre-built schemas** in `schemas::` module:
- `container_list()` - Docker/K8s container listings
- `resource_stats()` - CPU/memory statistics
- `simple_list()` - Generic list outputs
- `key_value()` - Key-value data structures
### Integration Points
- **AgentContext**: Added `output_schema` and `input_schema` fields
- `with_output_schema()` builder method
- `with_input_schema()` builder method
- **Error handling**: Added `AofError::Validation` variant
### Exports
- Exported `OutputSchema`, `InputSchema`, `FormatHint` from `aof-core`
## Design Principles
1. **Runtime flexibility**: Schemas specified per-execution, not per-agent
2. **Type safety**: Rust's compile-time guarantees + runtime validation
3. **LLM-driven**: Uses function calling or response_format for structure
4. **Format hints**: Guides CLI rendering (table vs list vs json)
5. **Graceful degradation**: Validation is strict by default, optional fallback
## Example Usage (Planned)
```rust
use aof_core::schema::schemas;
// Use pre-built schema
let schema = schemas::container_list();
// Execute with schema
runtime.execute_with_schema("agent", "list containers", Some(schema)).await?;
```
```bash
# CLI usage (to be implemented)
aofctl run agent docker-health.yaml --output-schema container-list
aofctl run agent docker-health.yaml --output-schema-file custom.json
```
## Related
- Issue: #74
- Inspired by: Agno's structured I/O
- https://docs.agno.com/basics/input-output/agent/usage/output-schema-on-run
- https://docs.agno.com/basics/input-output/agent/usage/structured-input
## Next Steps
- [ ] Update agent executor to use structured output
- [ ] Add CLI support for --output-schema flag
- [ ] Implement schema-based rendering in aofctl
- [ ] Write internal + user-facing docs
- [ ] Comprehensive tests
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>1 parent 10dd0be commit a5a305b
4 files changed
Lines changed: 433 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
157 | 163 | | |
158 | 164 | | |
159 | 165 | | |
| |||
212 | 218 | | |
213 | 219 | | |
214 | 220 | | |
| 221 | + | |
| 222 | + | |
215 | 223 | | |
216 | 224 | | |
217 | 225 | | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
218 | 238 | | |
219 | 239 | | |
220 | 240 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
51 | 54 | | |
52 | 55 | | |
53 | 56 | | |
| |||
100 | 103 | | |
101 | 104 | | |
102 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
103 | 111 | | |
104 | 112 | | |
105 | 113 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| 35 | + | |
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
| |||
0 commit comments