Download agents/python_agent.py from tailot/codex-python: direct link, hf CLI and curl.
- Browser
- Download file 1.99 kB
-
https://huggingface.co/datasets/tailot/codex-python/resolve/main/agents/python_agent.py
- Command line
-
hf download hf://datasets/tailot/codex-python/agents/python_agent.py
-
curl -L -o python_agent.py https://huggingface.co/datasets/tailot/codex-python/resolve/main/agents/python_agent.py
1.99 kB
| #!/usr/bin/env python3 | |
| """External Python topology node executable built on LingoLOGOS codex. | |
| Reads one JSON envelope on stdin, injects the external PythonLanguageAdapter | |
| when no explicit adapter or spec is already set on the dossier, delegates the | |
| step to lingologos_codex.agents.run_step, and writes one JSON envelope to stdout. | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| import sys | |
| from pathlib import Path | |
| PYTHON_ROOT = Path(__file__).resolve().parent.parent | |
| if str(PYTHON_ROOT) not in sys.path: | |
| sys.path.insert(0, str(PYTHON_ROOT)) | |
| from lingologos_python._codex_bridge import ensure_codex_on_path # noqa: E402 | |
| ensure_codex_on_path(PYTHON_ROOT) | |
| from lingologos_codex import agents, envelope as _envelope # noqa: E402 | |
| def main() -> int: | |
| parser = argparse.ArgumentParser(description="External Python topology node") | |
| parser.add_argument("--role", required=True, choices=sorted(agents.STEPS)) | |
| parser.add_argument("--node-id", default=None) | |
| parser.add_argument( | |
| "--strict-tools", | |
| action="store_true", | |
| help="Use StrictPythonLanguageAdapter requiring mypy and ruff.", | |
| ) | |
| args, _ignored = parser.parse_known_args() | |
| incoming = json.loads(sys.stdin.read()) | |
| dossier = dict(_envelope.read_dossier(incoming)) | |
| if not dossier.get("adapter") and not dossier.get("spec"): | |
| dossier["adapter"] = ( | |
| "lingologos_python.adapter:StrictPythonLanguageAdapter" | |
| if args.strict_tools or dossier.get("strictTools") | |
| else "lingologos_python.adapter:PythonLanguageAdapter" | |
| ) | |
| incoming = dict(incoming) | |
| payload = dict(incoming.get("payload", {})) | |
| payload["abstractSyntaxTree"] = json.dumps(dossier, sort_keys=True) | |
| incoming["payload"] = payload | |
| outgoing = agents.run_step(args.role, incoming, args.node_id or args.role) | |
| sys.stdout.write(json.dumps(outgoing)) | |
| return 0 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |