Datasets:
Modalities:
Text
Formats:
json
Languages:
English
Size:
< 1K
Tags:
mathematics
formal-verification
symbolic-algebra
theorem-proving
multi-agent-systems
benchmark
Download lgmath/protocol.py from tailot/lingologos-math: direct link, hf CLI and curl.
- Browser
- Download file 2.17 kB
-
https://huggingface.co/datasets/tailot/lingologos-math/resolve/main/lgmath/protocol.py
- Command line
-
hf download hf://datasets/tailot/lingologos-math/lgmath/protocol.py
-
curl -L -o protocol.py https://huggingface.co/datasets/tailot/lingologos-math/resolve/main/lgmath/protocol.py
2.17 kB
| """Envelope helpers: the dossier travels inside payload.naturalLanguage. | |
| The orchestrator forwards only the payload of the previous message, so the growing record of | |
| a session (the dossier) is serialised as JSON after a marker line in ``naturalLanguage``. The | |
| text before the marker is a one line human summary. | |
| """ | |
| import json | |
| from typing import Any, Dict, List, Optional | |
| MARK = "@@DOSSIER@@" | |
| def encode(summary: str, dossier: Dict[str, Any]) -> str: | |
| return summary.replace("\n", " ") + "\n" + MARK + json.dumps(dossier, sort_keys=True, separators=(",", ":")) | |
| def decode(text: str) -> Dict[str, Any]: | |
| """Return the dossier, or a fresh one holding the raw text as the problem statement.""" | |
| if MARK in text: | |
| return json.loads(text.split(MARK, 1)[1]) | |
| return {"v": 1, "problem": text.strip()} | |
| def summary_of(text: str) -> str: | |
| return text.split("\n", 1)[0] | |
| def envelope( | |
| node_id: str, | |
| recipient: Optional[str], | |
| turn: int, | |
| tick: int, | |
| summary: str, | |
| ast: str, | |
| dossier: Dict[str, Any], | |
| decls: List[str], | |
| assertions: List[str], | |
| claimed: str, | |
| ) -> Dict[str, Any]: | |
| out: Dict[str, Any] = { | |
| "sender": node_id, | |
| "turn": turn, | |
| "volatileState": {"internalTimeTick": tick}, | |
| "payload": { | |
| "naturalLanguage": encode(summary, dossier), | |
| "abstractSyntaxTree": ast, | |
| "smtConstraints": {"declarations": decls, "assertions": assertions, "z3Status": claimed}, | |
| }, | |
| } | |
| if recipient: | |
| out["recipient"] = recipient | |
| return out | |
| def start(incoming: Dict[str, Any]): | |
| """Decode an incoming envelope into (dossier, turn, tick, sender).""" | |
| dossier = decode(incoming["payload"]["naturalLanguage"]) | |
| tick = int(incoming.get("volatileState", {}).get("internalTimeTick", 0)) | |
| return dossier, int(incoming["turn"]), tick, incoming["sender"] | |
| def out(node_id: str, rcpt: str, turn: int, tick: int, dossier: Dict[str, Any], summary: str, ast: str, | |
| decls: List[str], asserts: List[str], claimed: str) -> Dict[str, Any]: | |
| return envelope(node_id, rcpt, turn, tick, summary, ast, dossier, decls, asserts, claimed) | |