Skip to content

The agent that grows with you

fix(usage-window): suggest free models from this profile's own Portal

Tekniume65dc9268105
diff --git a/agent/plan_limits.py b/agent/plan_limits.py
index 40efd0821ce..e356e49b6fd 100644
--- a/agent/plan_limits.py
+++ b/agent/plan_limits.py
@@ -173,13 +173,14 @@ def _plan_usage() -> Any:
def _portal_free_models() -> list[str]:
- """The Portal's free picks, from what Hermes already holds (in-process, else the
- last copy on disk). Never fetches: this runs mid-turn."""
+ """The Portal's free picks, from what this profile already holds for its own Portal (in-process,
+ else its last copy on disk). Never fetches: this runs mid-turn."""
try:
from hermes_cli import models as m
- payload = next((data for data, _ts in reversed(list(m._nous_recommended_cache.values())) if data), None)
- if payload is None:
- disk = m._read_nous_recommended_disk(m._resolve_nous_portal_url())
+ base = m._resolve_nous_portal_url()
+ payload = (m._nous_recommended_cache.get((m._pricing_profile_key(), base)) or (None,))[0]
+ if not payload:
+ disk = m._read_nous_recommended_disk(base)
payload = disk[0] if disk else None
entries = payload.get("freeRecommendedModels") if isinstance(payload, dict) else None
return [n for e in (entries or []) if (n := m._extract_model_name(e))]
diff --git a/tests/agent/test_plan_limits.py b/tests/agent/test_plan_limits.py
index 7dfa48cb938..5028e390b2f 100644
--- a/tests/agent/test_plan_limits.py
+++ b/tests/agent/test_plan_limits.py
@@ -15,6 +15,7 @@ from agent.usage_gauges import SCOPE_ALL, SCOPE_TOP_TIER, WindowGauge
RESET = 4_000_000_000_000
_REAL_FITS_CONTEXT = pl._fits_context
+_REAL_PORTAL_FREE_MODELS = pl._portal_free_models
PRICING = {
"example/model-a": {"prompt": "0.00000001", "completion": "0.0000001", "name": "Model A"},
@@ -243,3 +244,19 @@ class TestNextSteps:
def test_a_malformed_payload_degrades_to_the_generic_line(self):
text = pl.limit_next_steps_from_payload({"suggestions": [{"label": "no model"}, "junk"], "credits": "junk"})
assert text == "Pick another model with /model."
+
+
+def test_free_picks_come_from_this_profiles_own_portal_entry(monkeypatch):
+ """One process holds several profiles' recommended lists side by side: a limit card offers only the
+ calling profile's own Portal picks, else its own disk copy; another profile's entry never answers."""
+ from hermes_cli import models as m
+ portal = "https://portal.example.test"
+ monkeypatch.setattr(m, "_resolve_nous_portal_url", lambda: portal)
+ other = {"freeRecommendedModels": [{"modelName": "other/profile:free"}]}
+ mine = {"freeRecommendedModels": [{"modelName": "mine/model:free"}]}
+ monkeypatch.setattr(m, "_nous_recommended_cache", {})
+ m._nous_recommended_cache[("other-profile", portal)] = (other, 0.0)
+ assert _REAL_PORTAL_FREE_MODELS() == [] # this profile holds nothing, in memory or on disk
+ m._nous_recommended_cache[(m._pricing_profile_key(), portal)] = (mine, 0.0)
+ m._nous_recommended_cache[("other-profile", "https://other-portal.test")] = (other, 0.0)
+ assert _REAL_PORTAL_FREE_MODELS() == ["mine/model:free"]