lingologos-physics / agents /physics_agent
tailot's picture
rename library to lingologos_phys
fe28e0f verified
Raw History Blame Contribute Delete
1.78 kB
#!/usr/bin/env python3
"""Node executable of the physics topology.
The orchestrator starts this program once per turn, writes the incoming envelope as JSON on stdin and
reads the outgoing envelope from stdout. What the node does is chosen by --role, which the topology
sets to the node id (reader_a, reader_b, domain_a, domain_b, equivalence, coverage, invoker, boundary,
verifier, adversary or arbiter). Extra arguments the orchestrator adds are accepted and ignored.
All the thinking is in the package beside this file, so the same eleven agents also run inside one
process when a quick check is wanted (physics/tools/ask.py --in-process). The dossier moves as text
inside the natural language field of the envelope, which is the only channel a fixed chain has.
Faults are off unless LINGOLOGOS_PHYS_FAULTS names them, which is what the redundancy experiment uses.
"""
import argparse
import json
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from lingologos_phys import agents, faults, protocol # noqa: E402
def main() -> int:
parser = argparse.ArgumentParser(description="Physics topology node")
parser.add_argument("--role", required=True, choices=sorted(agents.ALL_AGENTS))
parser.add_argument("--node-id", default=None)
args, _ignored = parser.parse_known_args()
if hasattr(sys.stdin, "reconfigure"):
sys.stdin.reconfigure(encoding="utf-8")
sys.stdout.reconfigure(encoding="utf-8")
faults.from_env()
handed = json.loads(sys.stdin.read())
outgoing = protocol.respond(args.role, handed, args.node_id or args.role)
sys.stdout.write(json.dumps(outgoing, sort_keys=True, default=protocol.plain))
return 0
if __name__ == "__main__":
sys.exit(main())