simple-agents-macros
Procedural macros for SimpleAgents framework.
Overview
This crate provides derive macros for automatic schema generation and partial type support for streaming LLM responses.
Macros
#[derive(PartialType)]
Generates a partial version of a struct with all fields wrapped in Option<T>. Useful for progressive emission during streaming responses.
Example
use PartialType;
use ;
// This generates a PartialUser type:
//
// #[derive(Debug, Clone, Default, Serialize, Deserialize)]
// pub struct PartialUser {
// pub id: Option<u64>,
// pub name: Option<String>,
// pub email: Option<String>,
// pub age: Option<u32>,
// }
//
// With methods:
// - PartialUser::merge(&mut self, other: PartialUser)
// - User::from_partial(partial: PartialUser) -> Result<User, String>
Streaming Usage
let mut partial = default;
// Chunk 1: {"id": 1, "name": "Alice"}
partial.merge;
// Chunk 2: {"email": "alice@example.com", "age": 30}
partial.merge;
// Convert to complete type
let user = from_partial?;
Field Attributes
#[partial(default)]- Use default value if field is missing in partial#[partial(skip)]- Exclude field from partial type (always uses default)
Generated Code
For each struct annotated with #[derive(PartialType)]:
-
Partial Struct:
Partial{TypeName}with all fields asOption<T>- Derives:
Debug,Clone,Default,Serialize,Deserialize
- Derives:
-
Conversion Method:
from_partial()on the original type- Signature:
fn from_partial(partial: PartialType) -> Result<Type, String> - Returns error if required fields are missing
- Signature:
-
Merge Method:
merge()on the partial type- Signature:
fn merge(&mut self, other: PartialType) - Merges two partial values (newer values take precedence)
- Signature:
Requirements
- Rust 1.70 or later
- Works with
serdefor JSON serialization/deserialization
License
MIT OR Apache-2.0