feat(budget): make tool result persistence thresholds configurable

Add BudgetConfig dataclass to centralize and make overridable the
hardcoded constants (50K per-result, 200K per-turn, 2K preview) that
control when tool outputs get persisted to sandbox. Configurable at
the RL environment level via HermesAgentEnvConfig fields, threaded
through HermesAgentLoop to the storage layer.

Resolution: pinned (read_file=inf) > env config overrides > registry
per-tool > default. CLI override: --env.turn_budget_chars 80000
This commit is contained in:
alt-glitch
2026-04-07 22:31:06 -07:00
committed by Teknium
parent 65e24c942e
commit 77c5bc9da9
9 changed files with 131 additions and 9 deletions

View File

@@ -140,6 +140,7 @@ class HermesAgentLoop:
temperature: float = 1.0,
max_tokens: Optional[int] = None,
extra_body: Optional[Dict[str, Any]] = None,
budget_config: Optional["BudgetConfig"] = None,
):
"""
Initialize the agent loop.
@@ -156,7 +157,11 @@ class HermesAgentLoop:
extra_body: Extra parameters passed to the OpenAI client's create() call.
Used for OpenRouter provider preferences, transforms, etc.
e.g. {"provider": {"ignore": ["DeepInfra"]}}
budget_config: Tool result persistence budget. Controls per-tool
thresholds, per-turn aggregate budget, and preview size.
If None, uses DEFAULT_BUDGET (current hardcoded values).
"""
from tools.budget_config import DEFAULT_BUDGET
self.server = server
self.tool_schemas = tool_schemas
self.valid_tool_names = valid_tool_names
@@ -165,6 +170,7 @@ class HermesAgentLoop:
self.temperature = temperature
self.max_tokens = max_tokens
self.extra_body = extra_body
self.budget_config = budget_config or DEFAULT_BUDGET
async def run(self, messages: List[Dict[str, Any]]) -> AgentResult:
"""
@@ -455,6 +461,8 @@ class HermesAgentLoop:
tool_name=tool_name,
tool_use_id=tc_id,
env=get_active_env(self.task_id),
threshold=self.budget_config.resolve_threshold(tool_name),
preview_size=self.budget_config.preview_size,
)
except Exception:
pass # Persistence is best-effort in eval path
@@ -470,7 +478,12 @@ class HermesAgentLoop:
try:
num_tcs = len(assistant_msg.tool_calls)
if num_tcs > 0:
enforce_turn_budget(messages[-num_tcs:], env=get_active_env(self.task_id))
enforce_turn_budget(
messages[-num_tcs:],
env=get_active_env(self.task_id),
budget=self.budget_config.turn_budget,
preview_size=self.budget_config.preview_size,
)
except Exception:
pass