From d22db07b43e2c039a721d64d98698903280d5be6 Mon Sep 17 00:00:00 2001 From: Barabashka Date: Tue, 21 Apr 2026 15:09:55 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D0=BA=D0=BB=D1=8E=D1=87?= =?UTF-8?q?=D0=B8=D1=82=D1=8C=20=D0=BB=D0=BE=D0=BA=D0=B0=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D1=83=D1=8E=20=D1=82=D1=80=D0=B0=D1=81=D1=81=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=BA=D1=83=20Phoenix=20=D0=B4=D0=BB=D1=8F=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=BF=D1=83=D1=81=D0=BA=D0=BE=D0=B2=20=D0=B0=D0=B3=D0=B5?= =?UTF-8?q?=D0=BD=D1=82=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Добавлена инициализация Phoenix/OpenInference в CLI и AgentOS, а также обновлены зависимости и документация, чтобы трассировка включалась через переменные окружения. --- .env.example | 3 +++ README.md | 24 +++++++++++++++++++++++- requirements.txt | 2 ++ src/agent_os.py | 4 +++- src/main.py | 2 ++ src/observability.py | 36 ++++++++++++++++++++++++++++++++++++ 6 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 src/observability.py diff --git a/.env.example b/.env.example index ecae3bd..48e2b5b 100644 --- a/.env.example +++ b/.env.example @@ -7,3 +7,6 @@ AGENT_DEBUG_MODE=true AGENT_INSTRUCTIONS=You are a helpful assistant. Answer briefly and clearly. AGENT_OS_HOST=127.0.0.1 AGENT_OS_PORT=7777 +PHOENIX_TRACING_ENABLED=false +PHOENIX_COLLECTOR_ENDPOINT=http://localhost:6006 +PHOENIX_PROJECT_NAME=prisma-platform diff --git a/README.md b/README.md index 2549282..ed6d15a 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,8 @@ prisma_platform/ ├── __init__.py ├── agent_os.py ├── agent_runner.py - └── main.py + ├── main.py + └── observability.py ``` ## Установка @@ -69,4 +70,25 @@ python -m src.agent_os - `AGENT_INSTRUCTIONS` (по умолчанию: `You are a helpful assistant. Answer briefly and clearly.`) - `AGENT_OS_HOST` (по умолчанию: `127.0.0.1`) - `AGENT_OS_PORT` (по умолчанию: `7777`) +- `PHOENIX_TRACING_ENABLED` (по умолчанию: `false`) +- `PHOENIX_COLLECTOR_ENDPOINT` (по умолчанию: `http://localhost:6006`) +- `PHOENIX_PROJECT_NAME` (по умолчанию: `prisma-platform`) + +## Phoenix трассировка (локально) + +1. Установите зависимости: + +```bash +pip install -r requirements.txt +``` + +2. Поднимите Phoenix (см. `docker-service/docker-compose.yml`) и включите трассировку в `.env`: + +```dotenv +PHOENIX_TRACING_ENABLED=true +PHOENIX_COLLECTOR_ENDPOINT=http://localhost:6006 +PHOENIX_PROJECT_NAME=prisma-platform +``` + +3. Запустите приложение как обычно (`python -m src.main` или `python -m src.agent_os`). diff --git a/requirements.txt b/requirements.txt index 63d5320..ef9f881 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,5 @@ python-dotenv ollama socksio openai +arize-phoenix-otel +openinference-instrumentation-agno diff --git a/src/agent_os.py b/src/agent_os.py index cc1aeaf..1aebe0a 100644 --- a/src/agent_os.py +++ b/src/agent_os.py @@ -5,11 +5,13 @@ from dotenv import load_dotenv from agno.os import AgentOS from src.agent_runner import get_agent +from src.observability import init_phoenix_tracing load_dotenv() +_tracing_enabled = init_phoenix_tracing() _agent = get_agent() -_agent_os = AgentOS(agents=[_agent]) +_agent_os = AgentOS(agents=[_agent], tracing=_tracing_enabled) app = _agent_os.get_app() diff --git a/src/main.py b/src/main.py index 109462a..69ac1ea 100644 --- a/src/main.py +++ b/src/main.py @@ -4,6 +4,7 @@ import asyncio from dotenv import load_dotenv from src.agent_runner import run_agent +from src.observability import init_phoenix_tracing def build_parser() -> argparse.ArgumentParser: @@ -19,6 +20,7 @@ def build_parser() -> argparse.ArgumentParser: async def _main() -> None: load_dotenv() + init_phoenix_tracing() args = build_parser().parse_args() if args.message: diff --git a/src/observability.py b/src/observability.py new file mode 100644 index 0000000..0659b95 --- /dev/null +++ b/src/observability.py @@ -0,0 +1,36 @@ +import os + +from phoenix.otel import register + +_initialized = False + + +def _env_bool(name: str, default: bool) -> bool: + value = os.getenv(name) + if value is None: + return default + return value.strip().lower() in {"1", "true", "yes", "on"} + + +def init_phoenix_tracing() -> bool: + global _initialized + + enabled = _env_bool("PHOENIX_TRACING_ENABLED", False) + if not enabled: + return False + + if _initialized: + return True + + os.environ["PHOENIX_COLLECTOR_ENDPOINT"] = os.getenv( + "PHOENIX_COLLECTOR_ENDPOINT", + "http://localhost:6006", + ) + + project_name = os.getenv("PHOENIX_PROJECT_NAME", "prisma-platform") + register( + project_name=project_name, + auto_instrument=True, + ) + _initialized = True + return True