Catalog PyPI
PACKAGE EXPLORERView in registry

agent-observability-langchain

PyPI

LangChain integration for Agent Observability - structured logging, cost tracking, and compliance for AI agents

agentai-agentanalyticsauditcompliancecost-trackinglangchainllmloggingmonitoringobservabilitystructured-logging
Versions collected1
Direct dependencies8From release 1.2.1
Last observed20 Oct, 22:47 UTC

README

Version 1.2.1 documentation

Agent Observability for LangChain

PyPI version Python 3.9+ LangChain License: MIT

LangChain integration for the Agent Observability platform — structured logging, cost tracking, and compliance audit trails for production AI agents.

Installation

pip install agent-observability-langchain

Quick Start

Step 1: Get Your Free API Key (One-Time)

import requests

response = requests.post(
    "https://api-production-0c55.up.railway.app/v1/register",
    json={"agent_id": "my-langchain-agent"}
)
api_key = response.json()["api_key"]
print(f"Your API key: {api_key}")
# Save this! Example: ao_live_abc123...

Or via curl:

curl -X POST https://api-production-0c55.up.railway.app/v1/register \
  -H "Content-Type: application/json" \
  -d '{"agent_id": "my-langchain-agent"}'

Step 2: Set Environment Variable

export AGENT_OBS_API_KEY=ao_live_your_key_here

Step 3: Add to Your Agent

from langchain.agents import initialize_agent, AgentType
from langchain_openai import ChatOpenAI
from agent_observability_langchain import AgentObservabilityTool

# Create observability tool
obs_tool = AgentObservabilityTool()

# Create agent with observability
agent = initialize_agent(
    tools=[obs_tool],
    llm=ChatOpenAI(model="gpt-4"),
    agent=AgentType.OPENAI_FUNCTIONS,
    verbose=True
)

# Use your agent — it can now log events for compliance
result = agent.run(
    "Log an API call to OpenAI with cost $0.05 and latency 1200ms"
)

Features

FeatureDescription
Structured LoggingTrack all agent decisions and API calls with metadata
Cost TrackingMonitor spending per agent, task, and LLM provider
Performance AnalyticsLatency percentiles, error rates, throughput
Compliance ReadySOC 2, GDPR, HIPAA audit trail requirements
Queryable HistorySearch logs by agent, time, event type, severity
LangChain NativeWorks with agents, chains, and LangGraph

Use Cases

1. Cost Analysis

Track spending across all your agents and LLM providers:

from agent_observability_langchain import AgentObservabilityTool

tool = AgentObservabilityTool(agent_id="research-bot-v2")

# Log each API call with cost
tool.invoke({
    "event_type": "api_call",
    "metadata": {
        "provider": "openai",
        "model": "gpt-4",
        "cost_usd": 0.03,
        "latency_ms": 1250,
        "tokens": 1500
    }
})

2. Decision Auditing

For regulated industries (finance, healthcare, legal):

tool.invoke({
    "event_type": "decision",
    "metadata": {
        "decision": "approve_loan",
        "confidence": 0.92,
        "factors": ["credit_score", "income", "debt_ratio"],
        "customer_id": "cust_12345"
    },
    "severity": "info"
})

3. Error Tracking

tool.invoke({
    "event_type": "error",
    "metadata": {
        "error_type": "RateLimitError",
        "provider": "openai",
        "retry_count": 3,
        "resolved": False
    },
    "severity": "error"
})

4. With LangGraph

from langgraph.prebuilt import create_react_agent
from langchain_openai import ChatOpenAI
from agent_observability_langchain import AgentObservabilityTool

# Create agent with observability
agent = create_react_agent(
    ChatOpenAI(model="gpt-4"),
    tools=[AgentObservabilityTool()]
)

result = agent.invoke({
    "messages": [("user", "Research AI trends and log the costs")]
})

5. Custom Agent ID per Task

# Different agent IDs for different workflows
research_tool = AgentObservabilityTool(agent_id="research-agent")
writer_tool = AgentObservabilityTool(agent_id="writer-agent")
reviewer_tool = AgentObservabilityTool(agent_id="reviewer-agent")

API Reference

AgentObservabilityTool

AgentObservabilityTool(
    api_key: str = None,        # Or set AGENT_OBS_API_KEY env var
    agent_id: str = "langchain-agent",  # Your agent identifier
    api_base: str = None        # Override API URL (for self-hosted)
)

Input Schema

ParameterTypeRequiredDescription
event_typestrYesapi_call, decision, transaction, error, state_change
metadatadictNoEvent data (provider, cost_usd, latency_ms, etc.)
severitystrNodebug, info, warning, error, critical (default: info)

Common Metadata Fields

FieldTypeDescription
providerstrLLM provider (openai, anthropic, cohere, etc.)
modelstrModel name (gpt-4, claude-3-opus, etc.)
cost_usdfloatCost in USD
latency_msintResponse time in milliseconds
tokensintTotal token count
input_tokensintInput/prompt tokens
output_tokensintOutput/completion tokens
error_messagestrError details (for error events)
decisionstrDecision made (for decision events)
confidencefloatConfidence score (0-1)

Pricing

TierLogs/MonthPriceBest For
Free100,000$0Development, small projects
Starter1,000,000$29/monthProduction agents
Professional10,000,000$199/monthEnterprise, high-volume

Full pricing: https://api-production-0c55.up.railway.app/pricing.json

Convenience Function

from agent_observability_langchain import create_observability_tool

# Quick creation
tool = create_observability_tool(agent_id="my-agent")

Environment Variables

VariableDescriptionRequired
AGENT_OBS_API_KEYYour API keyYes (or pass to constructor)
AGENT_OBS_BASE_URLOverride API URLNo

Error Handling

The tool handles errors gracefully and returns error messages instead of raising exceptions:

result = tool.invoke({
    "event_type": "api_call",
    "metadata": {"provider": "openai"}
})

if "Failed" in result:
    print(f"Logging failed: {result}")
else:
    print(f"Success: {result}")

License

MIT License — see LICENSE for details.

Contributing

Contributions welcome! Please open an issue or submit a pull request.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
1.2.15 Jan 20268

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 22:47 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:1aec752b8eb67650714087c784d85f7de77ac1b597f1ac84f3faaca40f85d779