holon 0.14.1

A headless, event-driven runtime for long-lived agents
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
use serde_json::Value;

pub(crate) fn estimate_text_tokens(text: &str) -> usize {
    let bytes = text.len();
    bytes.saturating_add(3) / 4
}

pub(crate) fn estimate_json_tokens(value: &Value) -> usize {
    match serde_json::to_string(value) {
        Ok(json) => estimate_text_tokens(&json),
        Err(_) => 1,
    }
}