feat(conductor): Expose history bleed flags
This change introduces a new function, get_history_bleed_stats, to calculate and expose how close the current conversation history is to the provider's token limit. The initial implementation supports Anthropic, with a placeholder for Gemini.
This commit is contained in:
36
ai_client.py
36
ai_client.py
@@ -1145,4 +1145,38 @@ def send(
|
||||
return _send_gemini(md_content, user_message, base_dir, file_items)
|
||||
elif _provider == "anthropic":
|
||||
return _send_anthropic(md_content, user_message, base_dir, file_items)
|
||||
raise ValueError(f"unknown provider: {_provider}")
|
||||
raise ValueError(f"unknown provider: {_provider}")
|
||||
|
||||
def get_history_bleed_stats() -> dict:
|
||||
"""
|
||||
Calculates how close the current conversation history is to the token limit.
|
||||
"""
|
||||
if _provider == "anthropic":
|
||||
# For Anthropic, we have a robust estimator
|
||||
current_tokens = _estimate_prompt_tokens([], _anthropic_history)
|
||||
limit_tokens = _ANTHROPIC_MAX_PROMPT_TOKENS
|
||||
percentage = (current_tokens / limit_tokens) * 100 if limit_tokens > 0 else 0
|
||||
return {
|
||||
"provider": "anthropic",
|
||||
"limit": limit_tokens,
|
||||
"current": current_tokens,
|
||||
"percentage": percentage,
|
||||
}
|
||||
elif _provider == "gemini":
|
||||
# For Gemini, token estimation is complex and handled by the server.
|
||||
# We don't have a reliable client-side estimate, so we return a
|
||||
# "not implemented" state for now.
|
||||
return {
|
||||
"provider": "gemini",
|
||||
"limit": _GEMINI_MAX_INPUT_TOKENS,
|
||||
"current": 0,
|
||||
"percentage": 0,
|
||||
}
|
||||
|
||||
# Default empty state
|
||||
return {
|
||||
"provider": _provider,
|
||||
"limit": 0,
|
||||
"current": 0,
|
||||
"percentage": 0,
|
||||
}
|
||||
Reference in New Issue
Block a user