Подключить локальную трассировку Phoenix для запусков агента.
Добавлена инициализация Phoenix/OpenInference в CLI и AgentOS, а также обновлены зависимости и документация, чтобы трассировка включалась через переменные окружения.
This commit is contained in:
@@ -7,3 +7,6 @@ AGENT_DEBUG_MODE=true
|
|||||||
AGENT_INSTRUCTIONS=You are a helpful assistant. Answer briefly and clearly.
|
AGENT_INSTRUCTIONS=You are a helpful assistant. Answer briefly and clearly.
|
||||||
AGENT_OS_HOST=127.0.0.1
|
AGENT_OS_HOST=127.0.0.1
|
||||||
AGENT_OS_PORT=7777
|
AGENT_OS_PORT=7777
|
||||||
|
PHOENIX_TRACING_ENABLED=false
|
||||||
|
PHOENIX_COLLECTOR_ENDPOINT=http://localhost:6006
|
||||||
|
PHOENIX_PROJECT_NAME=prisma-platform
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ prisma_platform/
|
|||||||
├── __init__.py
|
├── __init__.py
|
||||||
├── agent_os.py
|
├── agent_os.py
|
||||||
├── agent_runner.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_INSTRUCTIONS` (по умолчанию: `You are a helpful assistant. Answer briefly and clearly.`)
|
||||||
- `AGENT_OS_HOST` (по умолчанию: `127.0.0.1`)
|
- `AGENT_OS_HOST` (по умолчанию: `127.0.0.1`)
|
||||||
- `AGENT_OS_PORT` (по умолчанию: `7777`)
|
- `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`).
|
||||||
|
|
||||||
|
|||||||
@@ -5,3 +5,5 @@ python-dotenv
|
|||||||
ollama
|
ollama
|
||||||
socksio
|
socksio
|
||||||
openai
|
openai
|
||||||
|
arize-phoenix-otel
|
||||||
|
openinference-instrumentation-agno
|
||||||
|
|||||||
+3
-1
@@ -5,11 +5,13 @@ from dotenv import load_dotenv
|
|||||||
from agno.os import AgentOS
|
from agno.os import AgentOS
|
||||||
|
|
||||||
from src.agent_runner import get_agent
|
from src.agent_runner import get_agent
|
||||||
|
from src.observability import init_phoenix_tracing
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
_tracing_enabled = init_phoenix_tracing()
|
||||||
|
|
||||||
_agent = get_agent()
|
_agent = get_agent()
|
||||||
_agent_os = AgentOS(agents=[_agent])
|
_agent_os = AgentOS(agents=[_agent], tracing=_tracing_enabled)
|
||||||
app = _agent_os.get_app()
|
app = _agent_os.get_app()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import asyncio
|
|||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
from src.agent_runner import run_agent
|
from src.agent_runner import run_agent
|
||||||
|
from src.observability import init_phoenix_tracing
|
||||||
|
|
||||||
|
|
||||||
def build_parser() -> argparse.ArgumentParser:
|
def build_parser() -> argparse.ArgumentParser:
|
||||||
@@ -19,6 +20,7 @@ def build_parser() -> argparse.ArgumentParser:
|
|||||||
|
|
||||||
async def _main() -> None:
|
async def _main() -> None:
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
init_phoenix_tracing()
|
||||||
args = build_parser().parse_args()
|
args = build_parser().parse_args()
|
||||||
|
|
||||||
if args.message:
|
if args.message:
|
||||||
|
|||||||
@@ -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
|
||||||
Reference in New Issue
Block a user