schema
ModuleStructured output: the JSON Schema an agent's answers must follow.
Contents
1 submodule, and what the module defines itself.
use utopia_agents::Schema;Rust
pub struct SchemaA named JSON Schema the agent's answer must follow: an object whose properties and required names are given.
Rust
use utopia_agents::{Schema, SchemaObject, property};
let object = SchemaObject::new([
("id", property("string", "The ID of the user")),
("age", property("integer", "The age of the user")),
])?;
let schema = Schema::new("User", "A user", object, vec!["id".into()]);
assert_eq!(schema.to_json()?, r#"{"id":"The ID of the user (string)","age":"The age of the user (integer)"}"#);use utopia_agents::SchemaObject;Rust
pub struct SchemaObjectUndocumented.
Rust
use utopia_agents::{SchemaObject, property};
let mut object = SchemaObject::default();
object.add_property("location", property("string", "The city and state"))?;
object.add_property("unit", property("string", "celsius or fahrenheit"))?;
assert_eq!(object.names(), ["location", "unit"]);
assert!(object.add_property("bad", property("invalid_type", "")).is_err());use utopia_agents::property;Rust
pub fn property(kind: &str, description: &str) -> ArrayA property definition with a type and a description, the common case.
Rust
pub const VALID_TYPES: [&str; 7] = [types::STRING, types::ARRAY, types::BOOLEAN, types::INTEGER, types::NUMBER, types::OBJECT, types::NULL]Undocumented.
schema::types
Own pageA JSON Schema type a property may have.
Rust
pub const ARRAY: &str = "array"array.
Rust
pub const BOOLEAN: &str = "boolean"boolean.
Rust
pub const INTEGER: &str = "integer"integer.
Rust
pub const NULL: &str = "null"null.
Rust
pub const NUMBER: &str = "number"number.
Rust
pub const OBJECT: &str = "object"object.
Rust
pub const STRING: &str = "string"string.