feat: the Inference Cooperative as the example upstream, and a live demo

- services.hermes-guest.reasoningEffort (and mkDarwin's): DeepSeek V4.1
  takes only low, high, xhigh or max, and rejects Hermes's default.
- The README's examples use gateway.inference.coop and
  deepseek-flash-tee, its TEE-hosted DeepSeek, which supports tool
  calling.
- demo.py takes an optional MODEL and PROXY command: each connection to
  Hermes's model port is handed to PROXY as its stdin, as launchd and
  systemd hand them to llm-proxy.py, and only the outcome is checked.

Generated-by: Claude Opus 5.5
This commit is contained in:
dckc committed 2026-11-29 16:58:56 -06:00
1 parent d58b77aa89
commit cfffe56cce
5 files changed
+68 -14

No files matched your search

+43 -9
View File
@@ -7,16 +7,24 @@ does (socat STDIO UNIX-CONNECT:host.sock). It also serves a scripted
model, so the run needs no API key and does the same thing every time.
Then it checks what the host received.
usage: demo.py HERMES SOCAT
With MODEL and PROXY, a real model drives it instead: each connection to
Hermes's model port is handed to PROXY as its stdin, as launchd and
systemd hand connections to llm-proxy.py. A real model needn't follow
the script, so only the outcome is checked: the pen comes back.
usage: demo.py HERMES SOCAT [MODEL PROXY...]
HERMES the hermes executable
SOCAT the socat executable
MODEL e.g. deepseek-flash-tee
PROXY e.g. python3 ../llm-proxy.py https://gateway.inference.coop/v1 KEY_FILE
"""
import json
import logging
import threading
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from socketserver import StreamRequestHandler, ThreadingUnixStreamServer
from socketserver import (BaseRequestHandler, StreamRequestHandler,
ThreadingTCPServer, ThreadingUnixStreamServer)
from fake_host import HostSide, Mailbox, Ref, handle_rpc
from fake_llm import chunks, completion, next_step
@@ -92,12 +100,20 @@ class LlmHandler(BaseHTTPRequestHandler):
logging.debug(format, *args)
def hermes_config(socat, host_sock, llm_port):
class InetdHandler(BaseRequestHandler):
"""One connection, handed to the proxy command as its stdin (inetd style)."""
def handle(self):
self.server.popen(self.server.command, stdin=self.request).wait()
def hermes_config(socat, host_sock, llm_port, model, extra=()):
"""config.yaml for the run (JSON is YAML): the deployed unit's settings."""
return json.dumps({
**dict(extra),
"model": {
"provider": "custom",
"default": MODEL,
"default": model,
"base_url": f"http://127.0.0.1:{llm_port}/v1",
"api_key": "held-by-proxy",
},
@@ -127,8 +143,19 @@ def check(host, mailbox, seen, stdout):
return [what for what, ok in expect.items() if not ok]
def check_outcome(host):
"""What a real model should have brought about; the failures, if any."""
expect = {
"the host got the pen back, as a reference": Ref("Pen") in host.received.values(),
"in a reply to message 0": any(m.get("replyTo") == 0 for m in host.inbox),
}
return [what for what, ok in expect.items() if not ok]
def main(argv, make_tmpdir, run, popen, timeout_expired, environ):
hermes, socat = argv[1:3]
live = argv[3:4]
model = argv[3] if live else MODEL
with make_tmpdir() as tmp:
host = HostSide(on_request=lambda description: Ref("Pen"))
mailbox = Mailbox(host)
@@ -137,8 +164,12 @@ def main(argv, make_tmpdir, run, popen, timeout_expired, environ):
host_sock = str(tmp / "host.sock")
mcp = ThreadingUnixStreamServer(host_sock, McpHandler)
mcp.mailbox = mailbox
llm = ThreadingHTTPServer(("127.0.0.1", 0), LlmHandler)
llm.script, llm.seen, llm.errors = SCRIPT, [], []
if live:
llm = ThreadingTCPServer(("127.0.0.1", 0), InetdHandler)
llm.popen, llm.command = popen, argv[4:]
else:
llm = ThreadingHTTPServer(("127.0.0.1", 0), LlmHandler)
llm.script, llm.seen, llm.errors = SCRIPT, [], []
for server in (mcp, llm):
threading.Thread(target=server.serve_forever, daemon=True).start()
@@ -146,7 +177,9 @@ def main(argv, make_tmpdir, run, popen, timeout_expired, environ):
hermes_home = home / ".hermes"
hermes_home.mkdir(parents=True)
(hermes_home / "config.yaml").write_text(
hermes_config(socat, host_sock, llm.server_address[1]))
hermes_config(socat, host_sock, llm.server_address[1], model,
# DeepSeek V4.1 takes low|high|xhigh|max, not Hermes's default
{"agent": {"reasoning_effort": "low"}} if live else ()))
env = dict(environ, HOME=str(home), HERMES_HOME=str(hermes_home))
# As in the deployed unit, the agent runs in `hermes gateway`, which
@@ -159,7 +192,7 @@ def main(argv, make_tmpdir, run, popen, timeout_expired, environ):
try:
done = run([hermes, "chat", "--oneshot", "-q",
"Check your messages and do what your host asks."],
env=env, capture_output=True, text=True, timeout=120)
env=env, capture_output=True, text=True, timeout=300 if live else 120)
stdout = done.stdout
logging.info("hermes exited %s\n--- stdout\n%s\n--- stderr\n%s",
done.returncode, done.stdout[-3000:], done.stderr[-3000:])
@@ -178,7 +211,8 @@ def main(argv, make_tmpdir, run, popen, timeout_expired, environ):
logging.info("--- gateway log (tail)\n%s",
(tmp / "gateway.log").read_text()[-2000:])
failures = check(host, mailbox, llm.seen, stdout) + llm.errors
failures = (check_outcome(host) if live
else check(host, mailbox, llm.seen, stdout) + llm.errors)
logging.info("host inbox: %s", json.dumps(host.inbox))
for what in failures:
logging.error("FAILED: %s", what)