refactor(agents): implement token count adjustment for Claude model messages

Added a method to adjust token counts for messages processed by the Claude model, applying a correction factor to align with API expectations. This enhancement improves the accuracy of token counting, ensuring reliable functionality when interacting with the Claude model.
This commit is contained in:
Danny Avila 2026-03-13 23:01:13 -04:00
parent b58aa164dd
commit 39b8db00cd
No known key found for this signature in database
GPG key ID: BF31EEB2C5CA0956

View file

@ -1230,6 +1230,21 @@ class AgentClient extends BaseClient {
const encoding = this.getEncoding();
return Tokenizer.getTokenCount(text, encoding);
}
/** @type {number} Anthropic message framing correction factor. */
static CLAUDE_TOKEN_CORRECTION = 1.1;
/**
* @param {object} message
* @returns {number}
*/
getTokenCountForMessage(message) {
const count = super.getTokenCountForMessage(message);
if (this.getEncoding() === 'claude') {
return Math.ceil(count * AgentClient.CLAUDE_TOKEN_CORRECTION);
}
return count;
}
}
module.exports = AgentClient;