55 lines
2.0 KiB
Python
55 lines
2.0 KiB
Python
"""Tool health check — exercise every agent tool and print PASS/FAIL.
|
|
|
|
Confirms internet access, market-data APIs, the sandbox, and (critically) that the sandbox
|
|
CANNOT read account secrets. Run anytime: uv run python scripts/check_tools.py
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pathlib
|
|
import sys
|
|
|
|
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent.parent))
|
|
|
|
from tools.market_data import get_bars, get_quote # noqa: E402
|
|
from tools.options import get_option_chain # noqa: E402
|
|
from tools.python_exec import run_python # noqa: E402
|
|
from tools.sandbox import run_analysis # noqa: E402
|
|
from tools.web import web_fetch, web_search # noqa: E402
|
|
|
|
|
|
def _check(name: str, fn) -> bool:
|
|
try:
|
|
r = str(fn())
|
|
ok = not r.startswith("ERROR")
|
|
print(f"[{'PASS' if ok else 'FAIL'}] {name}: {r[:80].strip()}")
|
|
return ok
|
|
except Exception as e:
|
|
print(f"[FAIL] {name}: {type(e).__name__}: {e}")
|
|
return False
|
|
|
|
|
|
def main() -> int:
|
|
checks = [
|
|
("run_python (calc)", lambda: run_python.invoke({"code": "print(2 + 2)"})),
|
|
("web_search (INTERNET)", lambda: web_search.invoke({"query": "stock market news"})),
|
|
("web_fetch (INTERNET)", lambda: web_fetch.invoke({"url": "https://example.com"})),
|
|
("get_quote", lambda: get_quote.invoke({"ticker": "AAPL"})),
|
|
("get_bars", lambda: get_bars.invoke({"ticker": "AAPL"})),
|
|
("get_option_chain", lambda: get_option_chain.invoke({"underlying": "AAPL", "right": "call"})),
|
|
("run_analysis (sandbox)", lambda: run_analysis.invoke({"code": "import pandas, numpy; print('libs ok')"})),
|
|
(
|
|
"sandbox SECRET-SCRUB",
|
|
lambda: "PASS"
|
|
if "None" in run_analysis.invoke({"code": "import os; print(os.environ.get('ALPACA_NOVA_SECRET'))"})
|
|
else "ERROR: secret leaked into sandbox!",
|
|
),
|
|
]
|
|
results = [_check(n, f) for n, f in checks]
|
|
print(f"\n{sum(results)}/{len(results)} tools OK")
|
|
return 0 if all(results) else 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|