Skip to main content

TextFormat

Derive Macro TextFormat 

Source
#[derive(TextFormat)]
{
    // Attributes available to this derive:
    #[text_format]
}
Expand description

Derive macro for implementing the TextFormat trait.

By default, produces pretty-printed JSON. When markdown = true in TextOptions, wraps the JSON in a fenced code block.

§Usage

use agentic_tools_macros::TextFormat;

#[derive(TextFormat, serde::Serialize)]
struct MyOutput {
    message: String,
    count: usize,
}

§Attributes

  • #[text_format(with = "path::to_fn")]: Delegate formatting to a custom function. The function must have signature fn(&Self, &TextOptions) -> String.
fn format_my_output(output: &MyOutput, opts: &TextOptions) -> String {
    format!("Message: {} (count: {})", output.message, output.count)
}

#[derive(TextFormat, serde::Serialize)]
#[text_format(with = "format_my_output")]
struct MyOutput {
    message: String,
    count: usize,
}