SDK para monitoramento e observabilidade de agentes de IA — KPI Agentes
Project description
kpi-agentes
SDK Python para monitoramento e observabilidade de agentes de IA.
Integre qualquer agente LLM em segundos e acompanhe Faithfulness, Relevancy, latência, custo por token e muito mais no painel KPI Agentes.
Instalação
pip install kpi-agentes
Início rápido
import time
import asyncio
from kpi_agentes import KPIReporter
# Inicialize uma vez (após as configs globais do seu app)
kpi = KPIReporter(
agent_id = "uuid-do-seu-agente", # obtido no painel KPI Agentes
base_url = "https://seu-servidor.com",
)
# No endpoint de chat — fire-and-forget, não atrasa a resposta
@app.post("/chat")
async def chat(request):
_t0 = time.monotonic()
result = await run_agent(request.message)
asyncio.create_task(kpi.report(
question = request.message,
answer = result["reply"],
context_chunks = result.get("context_chunks", []), # habilita RAG metrics
provider = "gemini",
model = "gemini-2.5-flash",
total_latency_ms = int((time.monotonic() - _t0) * 1000),
status = "completed",
))
return result
Parâmetros do KPIReporter
| Parâmetro | Tipo | Obrigatório | Descrição |
|---|---|---|---|
agent_id |
str |
✅ | UUID do agente no painel KPI |
agent_version_id |
str |
❌ | UUID da versão (para comparação A/B) |
base_url |
str |
❌ | URL do backend KPI (padrão: http://localhost:8001) |
timeout |
float |
❌ | Timeout HTTP em segundos (padrão: 8.0) |
enabled |
bool |
❌ | False desativa sem remover código (padrão: True) |
Parâmetros do kpi.report()
| Parâmetro | Tipo | Descrição |
|---|---|---|
question |
str |
Pergunta do usuário |
answer |
str |
Resposta do agente |
context_chunks |
list[str] |
Trechos do RAG (habilita Faithfulness/Relevancy) |
provider |
str |
Ex: "gemini", "openai", "groq" |
model |
str |
Ex: "gemini-2.5-flash", "gpt-4o-mini" |
total_latency_ms |
int |
Latência total em ms |
ttft_ms |
int |
Time to First Token em ms |
prompt_tokens |
int |
Tokens de entrada |
completion_tokens |
int |
Tokens de saída |
tool_results |
list[dict] |
Resultados de tool calls |
user_guid |
str |
ID do usuário (anonimizado) |
session_id |
str |
ID da sessão |
status |
str |
"completed" | "error" | "timeout" |
metadata |
dict |
Dados adicionais livres |
KPIs monitorados
- Faithfulness — fidelidade da resposta ao contexto RAG
- Relevancy — relevância da resposta à pergunta
- Latência — p50, p95, p99 e média
- TTFT — Time to First Token
- Custo por interação — baseado em token usage
- Success Rate — taxa de resoluções bem-sucedidas
- Error Rate — taxa de erros
- Tool Calls — rastreamento de chamadas de ferramentas
Requisitos
- Python 3.10+
httpx(instalado automaticamente)- Backend KPI Agentes rodando e acessível
Licença
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
kpi_agentes-0.1.0.tar.gz
(5.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kpi_agentes-0.1.0.tar.gz.
File metadata
- Download URL: kpi_agentes-0.1.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
020d6d816e8b3e7c25aca9c1c979e67e17ffd0c972021a31a7c9acfe3e0bd71c
|
|
| MD5 |
70a9f6039dc1255b87d8265696a6e082
|
|
| BLAKE2b-256 |
37d13253c6ea3007d28f864e6e0ddd711afd5cbfb8eeddf8157eaebd62dcc7d2
|
File details
Details for the file kpi_agentes-0.1.0-py3-none-any.whl.
File metadata
- Download URL: kpi_agentes-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6a3264d1f6f6cea2d98dbb6379a441b32b70c8f07bd1c397fc09b27274ef061
|
|
| MD5 |
96e6286011b003fb036766fe58f5d130
|
|
| BLAKE2b-256 |
fe9d2e705f6277f2513c233452a31f2d5af7fef34f033c404e77a503b85c54b4
|