feat(agents): live OpenRouter integration test (slow) + GET /diag/agent
Browse filesAdds network-gated live test that skips without OPENROUTER_API_KEY (and
without the BBB model artifact, since explainer.py auto-loads .env at
import time). Adds /diag/agent diagnostic endpoint reporting key presence,
agent model, RAG index status, and registered tool names.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- src/api/main.py +37 -0
src/api/main.py
CHANGED
|
@@ -102,3 +102,40 @@ def diag_openrouter() -> dict:
|
|
| 102 |
out["probe"] = {"status": "ERR", "exception": type(e).__name__, "message": str(e)[:200]}
|
| 103 |
|
| 104 |
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
out["probe"] = {"status": "ERR", "exception": type(e).__name__, "message": str(e)[:200]}
|
| 103 |
|
| 104 |
return out
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
@app.get("/diag/agent")
|
| 108 |
+
def diag_agent() -> dict:
|
| 109 |
+
"""Reachability probe for the orchestrator agent surface.
|
| 110 |
+
|
| 111 |
+
Reports key presence (length + 12-char prefix only — never the full
|
| 112 |
+
secret), the configured agent model, knowledge-base index status,
|
| 113 |
+
and the registered tool names.
|
| 114 |
+
"""
|
| 115 |
+
import os as _os
|
| 116 |
+
from pathlib import Path as _Path
|
| 117 |
+
|
| 118 |
+
from src.agents.tools import build_default_tools
|
| 119 |
+
|
| 120 |
+
key = _os.environ.get("OPENROUTER_API_KEY") or ""
|
| 121 |
+
model = _os.environ.get("NEUROBRIDGE_AGENT_MODEL", "google/gemini-2.0-flash-exp:free")
|
| 122 |
+
|
| 123 |
+
rag_dir = _Path("data/processed/faiss_index")
|
| 124 |
+
rag_status: dict = {"index_dir": str(rag_dir), "exists": False, "chunk_count": 0}
|
| 125 |
+
if (rag_dir / "index.bin").exists() and (rag_dir / "chunks.json").exists():
|
| 126 |
+
rag_status["exists"] = True
|
| 127 |
+
try:
|
| 128 |
+
import json as _json
|
| 129 |
+
rag_status["chunk_count"] = len(_json.loads((rag_dir / "chunks.json").read_text()))
|
| 130 |
+
except Exception as e:
|
| 131 |
+
rag_status["error"] = f"chunks.json unreadable: {e}"
|
| 132 |
+
|
| 133 |
+
tools = build_default_tools(rag_index_dir=rag_dir if rag_status["exists"] else None)
|
| 134 |
+
return {
|
| 135 |
+
"has_key": bool(key),
|
| 136 |
+
"key_len": len(key),
|
| 137 |
+
"key_prefix": key[:12] if key else None,
|
| 138 |
+
"agent_model": model,
|
| 139 |
+
"rag": rag_status,
|
| 140 |
+
"tool_names": [t.name for t in tools],
|
| 141 |
+
}
|