Skip to main content

Module fmt

Module fmt 

Source
Expand description

Transport-agnostic text formatting for tool outputs.

This module provides the TextFormat trait for converting tool outputs to human-readable text, along with supporting types and helpers.

§Usage

Tool outputs must implement TextFormat. The trait provides a default implementation that returns pretty-printed JSON via the Serialize supertrait. Types can override fmt_text for custom human-friendly formatting:

use agentic_tools_core::fmt::{TextFormat, TextOptions};
use serde::Serialize;

#[derive(Serialize)]
struct MyOutput {
    count: usize,
    items: Vec<String>,
}

// Use default (pretty JSON):
impl TextFormat for MyOutput {}

// Or provide custom formatting:
impl TextFormat for MyOutput {
    fn fmt_text(&self, opts: &TextOptions) -> String {
        format!("Found {} items:\n{}", self.count, self.items.join("\n"))
    }
}

§Default TextFormat Fallback

The TextFormat trait requires Serialize and provides a default fmt_text implementation that produces pretty-printed JSON. This means:

  • Types with custom formatting override fmt_text()
  • Types wanting JSON fallback use an empty impl: impl TextFormat for T {}
  • The registry always calls fmt_text() on the native output—no detection needed

Structs§

ErasedFmt
Type-erased formatter captured at tool registration time.
TextOptions
Options controlling text formatting behavior.

Enums§

TextStyle
Text rendering style.

Traits§

TextFormat
Transport-agnostic text formatting for tool outputs.

Functions§

build_formatter_for_textformat
Build a formatter for a type that implements TextFormat.
fallback_text_from_json
Pretty JSON fallback used when a type does not implement TextFormat.