Module toon

Module toon 

Source
Expand description

TOON (Token-Oriented Object Notation) encoding support

This module provides utilities for encoding data in TOON format, a compact, human-readable format that reduces token usage when sending structured data to LLMs.

TOON typically provides 30-60% token reduction compared to JSON, making it ideal for LLM prompts and tool descriptions.

See: https://github.com/toon-format/toon

§Example

use agents_core::toon::ToonEncoder;
use serde_json::json;

let encoder = ToonEncoder::default();
let data = json!({
    "users": [
        {"id": 1, "name": "Alice"},
        {"id": 2, "name": "Bob"}
    ]
});

let toon_str = encoder.encode(&data).unwrap();
// Output:
// users[2]{id,name}:
//   1,Alice
//   2,Bob

Structs§

ToonEncoder
TOON encoder for converting data to token-efficient format

Enums§

ToonEncodeError
Error type for TOON encoding

Functions§

format_tool_call_toon
Format tool call examples in TOON format (fallback to JSON)
tool_schema_to_toon
Convert a tool schema to TOON format (fallback)