Files
agent-maxim/bridge/adapters/local_echo_adapter.py
Anton 052591281d Initial clean version - Agent Maxim
- Complete agent system with planning and execution
- Bridge API with FastAPI server
- WhatsApp-style mobile dashboard
- Enhanced web search with query improvement
- Security guards and policy checks
- Comprehensive documentation
2026-04-09 18:07:43 +03:00

62 lines
1.8 KiB
Python

"""Local Echo adapter — REAL execution via subprocess.
Runs a real subprocess (Python interpreter) that receives the prompt
via stdin and echoes it back. Proves orchestration works with an
actual child process, no external API required.
This is the mandatory non-stub execution path for Bridge V1.1.
"""
from __future__ import annotations
import subprocess
import sys
from adapters.base import AdapterResult
MODE = "real"
# Script run inside the subprocess: reads stdin, prints back with metadata
_ECHO_SCRIPT = (
"import sys; "
"data = sys.stdin.read(); "
"print(f'[local_echo] received {len(data)} chars'); "
"print(data.strip()[:500])"
)
def execute(prompt: str) -> AdapterResult:
"""Run prompt through a real subprocess and return its stdout."""
print("=== THIS ADAPTER IS USED: local_echo_adapter ===")
try:
proc = subprocess.run(
[sys.executable, "-c", _ECHO_SCRIPT],
input=prompt,
capture_output=True,
text=True,
timeout=10,
shell=False,
)
if proc.returncode != 0:
return AdapterResult(
response=None,
error=f"subprocess exited {proc.returncode}: {proc.stderr.strip()}",
exit_code=proc.returncode,
mode=MODE,
)
return AdapterResult(
response=proc.stdout.strip(),
error=None,
exit_code=0,
mode=MODE,
)
except subprocess.TimeoutExpired:
return AdapterResult(response=None, error="subprocess timed out after 10s",
exit_code=1, mode=MODE)
except Exception as exc: # noqa: BLE001
return AdapterResult(response=None, error=f"{type(exc).__name__}: {exc}",
exit_code=1, mode=MODE)
def mode() -> str:
return MODE