Skip to content

Hermes Agent context engine: the main model writes the compaction handoff on its cached prompt prefix

fix: send a User-Agent on the warm request

HopeValentinedce581bd2ae6
diff --git a/tests/test_wc_warm.py b/tests/test_wc_warm.py
index 3006d28..ac97fd2 100644
--- a/tests/test_wc_warm.py
+++ b/tests/test_wc_warm.py
@@ -689,6 +689,16 @@ class SendTest(unittest.TestCase):
extra_headers={"X-Title": "Hermes Agent"})
self.assertEqual((calls[0][2]["X-Title"], calls[0][2]["Authorization"]), ("Hermes Agent", "Bearer k"))
+ def test_the_warm_request_sends_a_user_agent(self):
+ # Python urllib adds "Python-urllib/x.y" when the request sets no User-Agent.
+ # Cloudflare-fronted routes refuse that signature with HTTP 403 (error 1010).
+ calls = []
+ payload = {"choices": [{"message": {"content": "text"}, "finish_reason": "stop"}], "usage": {}}
+ send({"messages": []}, "http://h/v1", "k", post=fake_post(200, payload, calls))
+ agent = calls[0][2]["User-Agent"]
+ self.assertTrue(agent, "the warm request must set a User-Agent")
+ self.assertNotIn("urllib", agent.lower(), "the library User-Agent is refused by a bot rule")
+
def test_reads_the_reply_and_the_usage(self):
calls = []
payload = {"choices": [{"message": {"content": "text"}, "finish_reason": "stop"}],
diff --git a/warm_compaction/warm.py b/warm_compaction/warm.py
index 71fc66e..23d722d 100644
--- a/warm_compaction/warm.py
+++ b/warm_compaction/warm.py
@@ -25,6 +25,9 @@ DEFAULT_RESERVE = 4096
HANDOFF_MIN_TOKENS = 2048
HANDOFF_MAX_TOKENS = 8192
TIMEOUT_S = 120.0
+# Cloudflare-fronted routes reject Python's default "Python-urllib/x.y" User-Agent with
+# HTTP 403 (error 1010). Send an explicit one, as the Hermes SDK client does.
+USER_AGENT = "hermes-warm-compaction/0.2"
SAFETY = 1.1
SYSTEM_ROLES = ("system", "developer")
UNSUPPORTED_SETTINGS = ("response_format", "functions", "function_call", "modalities", "audio")
@@ -585,7 +588,8 @@ def send(body: dict[str, Any], base_url: str, api_key: Any, timeout_s: float = T
extra_headers are the client default headers of the route (route_headers); they win, as in the SDK."""
if not base_url:
raise WarmRefusal("provider_error")
- headers = {"Content-Type": "application/json", "Accept": "application/json"}
+ headers = {"Content-Type": "application/json", "Accept": "application/json",
+ "User-Agent": USER_AGENT}
key = api_key_text(api_key)
if key and api_mode != "anthropic_messages":
headers["Authorization"] = f"Bearer {key}"