Skip to main content

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

Metadata

Release files for kpi-agentes 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kpi-agentes 0.1.0
File Size Uploaded Provenance
kpi_agentes-0.1.0.tar.gz 5.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for kpi-agentes 0.1.0
File Interpreter ABI Platform
kpi_agentes-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.9 kB

Release files / kpi_agentes-0.1.0.tar.gz

Download URL kpi_agentes-0.1.0.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
020d6d816e8b3e7c25aca9c1c979e67e17ffd0c972021a31a7c9acfe3e0bd71c
BLAKE2b-256 checksum
How to use checksums
37d13253c6ea3007d28f864e6e0ddd711afd5cbfb8eeddf8157eaebd62dcc7d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Release files / kpi_agentes-0.1.0-py3-none-any.whl

Download URL kpi_agentes-0.1.0-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a6a3264d1f6f6cea2d98dbb6379a441b32b70c8f07bd1c397fc09b27274ef061
BLAKE2b-256 checksum
How to use checksums
fe9d2e705f6277f2513c233452a31f2d5af7fef34f033c404e77a503b85c54b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Security for kpi-agentes 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page