Default token counter that approximates based on character count.
If tools are provided, the token count also includes stringified tool schemas.
countTokensApproximately(
messages: BaseMessage<MessageStructure<MessageToolSet>, MessageType>[],
tools: Record<string, any>[] | null
): number| Name | Type | Description |
|---|---|---|
messages* | BaseMessage<MessageStructure<MessageToolSet>, MessageType>[] | Messages to count tokens for |
tools | Record<string, any>[] | null | Optional list of tools to include in the token count. Each tool can be either a LangChain tool instance or a dict representing a tool schema. LangChain tool instances are converted to OpenAI tool format before counting. |