New router intelligence modules (26 files): alert_ingest/store, audit_store, architecture_pressure, backlog_generator/store, cost_analyzer, data_governance, dependency_scanner, drift_analyzer, incident_* (5 files), llm_enrichment, platform_priority_digest, provider_budget, release_check_runner, risk_* (6 files), signature_state_store, sofiia_auto_router, tool_governance New services: - sofiia-console: Dockerfile, adapters/, monitor/nodes/ops/voice modules, launchd, react static - memory-service: integration_endpoints, integrations, voice_endpoints, static UI - aurora-service: full app suite (analysis, job_store, orchestrator, reporting, schemas, subagents) - sofiia-supervisor: new supervisor service - aistalk-bridge-lite: Telegram bridge lite - calendar-service: CalDAV calendar service with reminders - mlx-stt-service / mlx-tts-service: Apple Silicon speech services - binance-bot-monitor: market monitor service - node-worker: STT/TTS memory providers New tools (9): agent_email, browser_tool, contract_tool, observability_tool, oncall_tool, pr_reviewer_tool, repo_tool, safe_code_executor, secure_vault New crews: agromatrix_crew (10 modules: depth_classifier, doc_facts, doc_focus, farm_state, light_reply, llm_factory, memory_manager, proactivity, reflection_engine, session_context, style_adapter, telemetry) Tests: 85+ test files for all new modules Made-with: Cursor
79 lines
2.4 KiB
Python
79 lines
2.4 KiB
Python
"""Call DAARION router: /v1/agents/{agent_id}/infer and /v1/tools/execute."""
|
|
import logging
|
|
from typing import Any, Dict, Optional
|
|
|
|
import httpx
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
async def infer(
|
|
base_url: str,
|
|
agent_id: str,
|
|
prompt: str,
|
|
*,
|
|
model: Optional[str] = None,
|
|
system_prompt: Optional[str] = None,
|
|
metadata: Optional[Dict[str, Any]] = None,
|
|
timeout: float = 120.0,
|
|
api_key: str = "",
|
|
) -> Dict[str, Any]:
|
|
"""POST /v1/agents/{agent_id}/infer. Returns { response, model, backend, ... }."""
|
|
url = f"{base_url.rstrip('/')}/v1/agents/{agent_id}/infer"
|
|
headers = {"Content-Type": "application/json"}
|
|
if api_key:
|
|
headers["Authorization"] = f"Bearer {api_key}"
|
|
body = {
|
|
"prompt": prompt,
|
|
"metadata": metadata or {},
|
|
"max_tokens": 2048,
|
|
"temperature": 0.4,
|
|
}
|
|
if model:
|
|
body["model"] = model
|
|
if system_prompt:
|
|
body["system_prompt"] = system_prompt
|
|
async with httpx.AsyncClient(timeout=timeout) as client:
|
|
r = await client.post(url, json=body, headers=headers)
|
|
r.raise_for_status()
|
|
return r.json()
|
|
|
|
|
|
async def execute_tool(
|
|
base_url: str,
|
|
tool: str,
|
|
action: str,
|
|
params: Optional[Dict[str, Any]] = None,
|
|
*,
|
|
agent_id: str = "sofiia",
|
|
timeout: float = 60.0,
|
|
api_key: str = "",
|
|
) -> Dict[str, Any]:
|
|
"""POST /v1/tools/execute. Returns { status, data, error }."""
|
|
url = f"{base_url.rstrip('/')}/v1/tools/execute"
|
|
headers = {"Content-Type": "application/json"}
|
|
if api_key:
|
|
headers["Authorization"] = f"Bearer {api_key}"
|
|
body = {
|
|
"tool": tool,
|
|
"action": action,
|
|
"agent_id": agent_id,
|
|
**(params or {}),
|
|
}
|
|
async with httpx.AsyncClient(timeout=timeout) as client:
|
|
r = await client.post(url, json=body, headers=headers)
|
|
r.raise_for_status()
|
|
return r.json()
|
|
|
|
|
|
async def health(base_url: str, timeout: float = 5.0) -> Dict[str, Any]:
|
|
"""GET /healthz or /health. Returns { ok, status?, ... }."""
|
|
for path in ("/healthz", "/health", "/"):
|
|
try:
|
|
async with httpx.AsyncClient(timeout=timeout) as client:
|
|
r = await client.get(f"{base_url.rstrip('/')}{path}")
|
|
return {"ok": r.status_code == 200, "status": r.status_code, "path": path}
|
|
except Exception as e:
|
|
logger.debug("health %s%s failed: %s", base_url, path, e)
|
|
return {"ok": False, "error": "unreachable"}
|