Skip to main content

AgentBase AgentOps LangChain

agentbase-agentops-langchain 为用户现有的 LangChain Agent 增加 AppBase AgentOps 可观测能力。挂载一次 AgentOpsMiddleware 后,SDK 自动采集 Agent、Chain、LLM、Tool 和 Retriever 生命周期,并通过 OTLP/HTTP 发送到 AppBase AgentOps。

SDK 不创建或替换模型,不代理模型请求,也不改变应用现有的模型 Provider、模型凭据、 Prompt、Tool 或业务逻辑。

安装

python -m pip install agentbase-agentops-langchain

配置

export AGENTBASE_AGENTOPS_ENDPOINT="https://<appbase-host>"
export AGENTBASE_PROJECT_ID="<project-id>"
export AGENTBASE_API_KEY="<project-api-key>"

Project API Key 至少需要 observability.ingest.write 权限。SDK 会自动将 AppBase host 或 /v1 base URL 补齐为完整 OTLP Trace endpoint。

接入现有 Agent

from agentbase_agentops_langchain import AgentOpsMiddleware
from langchain.agents import create_agent


agentops = AgentOpsMiddleware()

agent = create_agent(
    model=model,
    tools=tools,
    middleware=[agentops],
)

result = agent.invoke(
    inputs,
    config={
        "metadata": {
            "session_id": conversation_id,
            "user_id": authenticated_user_id,
        },
        "tags": [environment, agent_name, agent_version],
    },
)

如果应用已经配置其他 LangChain middleware,请将 AgentOpsMiddleware 追加到原列表, 不要覆盖现有 middleware。后续 invokeainvokestreamastreambatchabatch 调用不需要手工传入 AgentOps callback。

短生命周期进程

CLI、Job 和测试脚本应在退出前主动 flush:

agentops.flush(timeout_millis=10_000)

flush() 表示同步尝试导出本地队列,不代表 AppBase 服务端已经完成持久化。需要确认接入 成功时,应通过 Console 或 Trace API 等待完整的 Agent、Generation 和 Tool 观测树。

内容采集

默认 AGENTBASE_AGENTOPS_CAPTURE_CONTENT=false,不会上传 Prompt、Response、Tool 参数 或 Retriever 文档正文。只有显式开启后才采集正文:

export AGENTBASE_AGENTOPS_CAPTURE_CONTENT=true

生产环境开启前应确认内容符合数据安全和脱敏要求。

NeMo Relay

已经使用 NVIDIA NeMo Relay 的应用不应再挂载 AgentOpsMiddleware。保留 NemoRelayMiddlewareNemoRelayCallbackHandler 和 Relay scope,将 Relay 的 OTLP/HTTP Trace endpoint 与鉴权 header 指向 AppBase AgentOps。

Session/User 关联需要同时满足:

  • plugins.toml 配置 promote_metadata_prefixes = ["langfuse."]
  • Relay scope metadata 传入 langfuse.session.idlangfuse.user.id

本页提供可直接完成安装和接入的最小配置。完整的配置、验证、隐私边界和排障说明, 请以 AppBase 官方客户文档为准。

兼容范围

  • Python >=3.10
  • LangChain >=1.0,<2.0
  • OTLP/HTTP Trace

当前不提供 OTLP/gRPC、Metrics 或 OpenTelemetry Logs 接入。

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agentbase_agentops_langchain-0.1.0.tar.gz (27.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agentbase_agentops_langchain-0.1.0-py3-none-any.whl (20.7 kB view details)

Uploaded Python 3

File details

Details for the file agentbase_agentops_langchain-0.1.0.tar.gz.

File metadata

File hashes

Hashes for agentbase_agentops_langchain-0.1.0.tar.gz
Algorithm Hash digest
SHA256 54cd444ce7483aabe9f7cfc42e2f3ddd70730b5adab7fd2373800c55692db1e3
MD5 0b3b9a850013093ee5a21eeb20156ffc
BLAKE2b-256 b7a5bac374053e455a44ec9f501c772cfbd5df04e58443679040710821c5832b

See more details on using hashes here.

File details

Details for the file agentbase_agentops_langchain-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for agentbase_agentops_langchain-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7160fd3a4e931c5657c8cda08ea4fa845b16456fe4445bf7bb466a5624e43895
MD5 e1a1de6641a1e93289d3a93387cfe708
BLAKE2b-256 725ec61a05d676e820ee70c21b658251da35cddfaaee37bbdaf84823244832cd

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

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