mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-08 03:01:47 +00:00
fix(agent): honor configured model max tokens
This commit is contained in:
parent
52e2777821
commit
a78e622dfe
4 changed files with 102 additions and 2 deletions
29
run_agent.py
29
run_agent.py
|
|
@ -1901,8 +1901,35 @@ class AIAgent:
|
|||
_aux_context_config = None
|
||||
self._aux_compression_context_length_config = _aux_context_config
|
||||
|
||||
# Read explicit context_length override from model config
|
||||
# Read explicit model output-token override from config when the
|
||||
# caller did not pass one directly.
|
||||
_model_cfg = _agent_cfg.get("model", {})
|
||||
if self.max_tokens is None and isinstance(_model_cfg, dict):
|
||||
_config_max_tokens = _model_cfg.get("max_tokens")
|
||||
if _config_max_tokens is not None:
|
||||
try:
|
||||
if isinstance(_config_max_tokens, bool):
|
||||
raise ValueError
|
||||
_parsed_max_tokens = int(_config_max_tokens)
|
||||
if _parsed_max_tokens <= 0:
|
||||
raise ValueError
|
||||
self.max_tokens = _parsed_max_tokens
|
||||
except (TypeError, ValueError):
|
||||
logger.warning(
|
||||
"Invalid model.max_tokens in config.yaml: %r — "
|
||||
"must be a positive integer (e.g. 4096). "
|
||||
"Falling back to provider default.",
|
||||
_config_max_tokens,
|
||||
)
|
||||
print(
|
||||
f"\n⚠ Invalid model.max_tokens in config.yaml: {_config_max_tokens!r}\n"
|
||||
f" Must be a positive integer (e.g. 4096).\n"
|
||||
f" Falling back to provider default.\n",
|
||||
file=sys.stderr,
|
||||
)
|
||||
self._session_init_model_config["max_tokens"] = self.max_tokens
|
||||
|
||||
# Read explicit context_length override from model config
|
||||
if isinstance(_model_cfg, dict):
|
||||
_config_context_length = _model_cfg.get("context_length")
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue