Skip to main content

estimate_request_tokens

Function estimate_request_tokens 

Source
pub fn estimate_request_tokens(
    messages: &[ChatMessage],
    tools: &[ToolSchema],
) -> u64
Expand description

PARITY-18 D1 — the full wire-request token estimate: every message in messages (callers pass what crate::Agent::build_request_messages actually returns, which already carries the system prompt at index 0) PLUS the serialized tools schema array, which is a real part of the request body ([crate::provider::build_request_body]) but — before PARITY-18’s re-fix — was never counted by the preflight guard at all. A session whose messages alone fit comfortably could still carry a fat builtin/MCP tool-schema array that blows the real wire request; this is the fix.