AttachmentSchema

Trait AttachmentSchema 

Source
pub trait AttachmentSchema {
    // Required method
    fn attachment_keys() -> &'static [&'static str];
}
Expand description

Trait for types that can declare their attachment schema at compile-time.

This trait is automatically implemented when deriving ToAttachments. It provides metadata about what attachment keys a type will produce, which is used by the Agent derive macro to augment the agent’s expertise.

§Design Philosophy

This trait intentionally does not include a descriptions() method. Instead, types implementing AttachmentSchema should also implement ToPrompt, which already provides prompt_schema() that includes field descriptions from doc comments.

Why not duplicate descriptions?

  • ToPrompt::prompt_schema() already includes field descriptions
  • Adding attachment_descriptions() would be redundant
  • Users who need schema + descriptions should use ToPrompt

§Examples

use llm_toolkit::attachment::AttachmentSchema;

struct MyOutput;

impl AttachmentSchema for MyOutput {
    fn attachment_keys() -> &'static [&'static str] {
        &["chart", "thumbnail"]
    }
}

assert_eq!(MyOutput::attachment_keys(), &["chart", "thumbnail"]);

§Integration with ToPrompt

For full schema with descriptions, implement both traits:

#[derive(ToPrompt, ToAttachments)]
struct ImageGeneratorOutput {
    /// Visual chart of the analysis results
    #[attachment(key = "analysis_chart")]
    pub chart_bytes: Vec<u8>,
}

// AttachmentSchema::attachment_keys() returns: ["analysis_chart"]
// ToPrompt::prompt_schema() returns full schema with descriptions

Required Methods§

Source

fn attachment_keys() -> &'static [&'static str]

Returns a static slice of attachment keys this type produces.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§