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§
- Erased
Fmt - Type-erased formatter captured at tool registration time.
- Text
Options - Options controlling text formatting behavior.
Enums§
- Text
Style - Text rendering style.
Traits§
- Text
Format - 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.