nemo-relay


توضیحات

Python bindings for the NeMo Relay agent runtime.
ویژگی مقدار
سیستم عامل -
نام فایل nemo-relay-0.9.4
نام nemo-relay
نسخه کتابخانه 0.9.4
نگهدارنده []
ایمیل نگهدارنده []
نویسنده NVIDIA Corporation & Affiliates
ایمیل نویسنده -
آدرس صفحه اصلی -
آدرس اینترنتی https://pypi.org/project/nemo-relay/
مجوز -
<!-- SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. SPDX-License-Identifier: Apache-2.0 --> [![License](https://img.shields.io/github/license/NVIDIA/NeMo-Relay)](https://github.com/NVIDIA/NeMo-Relay/blob/main/LICENSE) [![GitHub](https://img.shields.io/badge/github-repo-blue?logo=github)](https://github.com/NVIDIA/NeMo-Relay/) [![Release](https://img.shields.io/github/v/release/NVIDIA/NeMo-Relay?color=green)](https://github.com/NVIDIA/NeMo-Relay/releases) [![Codecov](https://codecov.io/gh/NVIDIA/NeMo-Relay/branch/main/graph/badge.svg)](https://app.codecov.io/gh/NVIDIA/NeMo-Relay) [![PyPI](https://img.shields.io/pypi/v/nemo-relay?color=4B8BBE&logo=pypi)](https://pypi.org/project/nemo-relay/) [![npm node](https://img.shields.io/npm/v/nemo-relay-node?label=nemo-relay-node&color=CC3534&logo=npm)](https://www.npmjs.com/package/nemo-relay-node) [![Crates.io](https://img.shields.io/crates/v/nemo-relay?label=nemo-relay&color=B7410E&logo=rust)](https://crates.io/crates/nemo-relay) [![Crates.io](https://img.shields.io/crates/v/nemo-relay-adaptive?label=nemo-relay-adaptive&color=B7410E&logo=rust)](https://crates.io/crates/nemo-relay-adaptive) [![Crates.io](https://img.shields.io/crates/v/nemo-relay-cli?label=nemo-relay-cli&color=B7410E&logo=rust)](https://crates.io/crates/nemo-relay-cli) [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/NVIDIA/NeMo-Relay) # NeMo Relay `nemo-relay` is the NeMo Relay package for Python applications. It gives Python code access to a portable agent runtime for execution scopes, middleware, plugins, lifecycle events, adaptive behavior, and observability around tool and LLM calls. The package wraps the shared Rust runtime, so Python applications use the same runtime semantics as the Rust and Node.js surfaces. ## Why Use It? Use the Python binding for the following tasks: - **Own execution context in Python**: Group agent, tool, and LLM work into one scope tree from Python application code. - **Package policy around callbacks**: Use guardrails and intercepts to block work, sanitize observability payloads, rewrite requests, or wrap execution. - **Emit one lifecycle stream**: Send runtime events to in-process subscribers, Agent Trajectory Interchange Format (ATIF), or typed OpenTelemetry workflows. - **Integrate without a framework migration**: Wrap framework or provider callbacks while preserving the application’s orchestration model. ## What You Get The Python package provides the following capabilities: - **Scope, tool, and LLM helpers**: Managed boundaries that emit lifecycle events and run middleware in a consistent order. - **Middleware APIs**: Guardrails and intercepts for tool and LLM requests, responses, and execution, plus mark and scope event sanitizers for `data`, `category_profile`, and `metadata`. - **Subscribers and exporters**: `OpenTelemetrySubscriber` exports traces; `OpenTelemetryLogSubscriber` and `OpenTelemetryMetricSubscriber` export severity-tagged marks and typed metric measurements. Bare OTLP/HTTP origins resolve to `/v1/traces`, `/v1/logs`, or `/v1/metrics` for the selected signal. Each direct OTLP subscriber exposes `runtime_diagnostics()` for bounded exporter and event-processing failure summaries. Trace export failures use `otel.traces_export_failed`; after a trace export fails, `force_flush()` continues to return an error until a later trace batch exports successfully. The `nemo_relay.observability` helpers configure plugin-owned endpoint fan-out. - **Plugin and typed helpers**: Public modules for plugins, codecs, typed wrappers, adaptive runtime behavior, and observability plugin configuration. - **Shared Rust runtime semantics**: Python behavior aligned with the Rust and Node.js surfaces. ## Installation Install the published package with `uv`: ```bash uv add nemo-relay ``` If you are not using `uv`, install it with `pip`: ```bash pip install nemo-relay ``` ### Optional Dependencies #### LangChain Integration [LangChain](https://www.langchain.com/langchain) integration is available with the `langchain` extra: ```bash # With uv uv add "nemo-relay[langchain]" # With pip pip install "nemo-relay[langchain]" ``` #### LangGraph Integration [LangGraph](https://www.langchain.com/langgraph) integration is available with the `langgraph` extra, this builds upon and includes the `langchain` extra as well. ```bash # With uv uv add "nemo-relay[langgraph]" # With pip pip install "nemo-relay[langgraph]" ``` #### Deep Agents Integration [Deep Agents](https://www.langchain.com/deep-agents) integration is available with the `deepagents` extra. This extra builds upon and includes the `langgraph` and `langchain` extras. ```bash # With uv uv add "nemo-relay[deepagents]" # With pip pip install "nemo-relay[deepagents]" ``` #### Google ADK Integration [Google Agent Development Kit](https://google.github.io/adk-docs/) integration is available with the `google-adk` extra: ```bash # With uv uv add "nemo-relay[google-adk]" # With pip pip install "nemo-relay[google-adk]" ``` Add `NemoRelayPlugin` to your ADK app to record agent runs, model calls, and tool calls. For setup steps and examples, follow the [Google ADK Integration Guide](https://docs.nvidia.com/nemo/relay/supported-integrations/google-adk). #### LangChain NVIDIA Integration The [LangChain NVIDIA](https://github.com/langchain-ai/langchain-nvidia) extra builds upon the `langchain` extra adding a compatible version of the `langchain-nvidia-ai-endpoints` package. ```bash # With uv uv add "nemo-relay[langchain-nvidia]" # With pip pip install "nemo-relay[langchain-nvidia]" ``` To install this along with the `langgraph` extra, use: ```bash # With uv uv add "nemo-relay[langgraph,langchain-nvidia]" # With pip pip install "nemo-relay[langgraph,langchain-nvidia]" ``` ## Getting Started Register a subscriber, create a scope, and emit a mark event: ```python import nemo_relay def on_event(event) -> None: print(f"{event.kind} {event.name}") nemo_relay.subscribers.register("printer", on_event) with nemo_relay.scope.scope("demo-agent", nemo_relay.ScopeType.Agent) as handle: nemo_relay.scope.event("initialized", handle=handle, data={"binding": "python"}) nemo_relay.subscribers.flush() nemo_relay.subscribers.deregister("printer") ``` Use `nemo_relay.scope.event(..., severity=nemo_relay.LogSeverity.Info)` for a mark intended for log export. Use `nemo_relay.scope.metric()` with `nemo_relay.MetricMeasurement` objects for metrics; Relay validates the complete measurement group before publishing it. ## OTLP Logs and Metrics For plugin-managed export, configure version 4 and enable `logs` and `metrics`. Omitting their endpoint lists derives `/v1/logs` and `/v1/metrics` from the trace endpoint: ```python from nemo_relay.observability import ( ComponentSpec, ObservabilityConfig, OpenTelemetryEndpointConfig, OpenTelemetryLogSectionConfig, OpenTelemetryMetricSectionConfig, OpenTelemetrySectionConfig, ) component = ComponentSpec( ObservabilityConfig( opentelemetry=OpenTelemetrySectionConfig( enabled=True, endpoints=[ OpenTelemetryEndpointConfig( type="gen_ai", endpoint="http://localhost:4318/v1/traces" ) ], logs=OpenTelemetryLogSectionConfig(enabled=True), metrics=OpenTelemetryMetricSectionConfig(enabled=True), ) ) ) ``` Emit a typed log mark and an atomically validated metric group with the public scope helpers: ```python from nemo_relay import DataSchema, LogSeverity, MetricKind, MetricMeasurement, MetricValueType from nemo_relay import scope scope.event( "cache-nearly-full", data={"entries": 900}, data_schema=DataSchema("example.cache", "1"), severity=LogSeverity.Warn, ) scope.metric( "cache-entries", [MetricMeasurement("example.cache.entries", MetricKind.Gauge, MetricValueType.U64, 900)], ) ``` Direct log and metric subscribers are independently managed. Register each before emitting marks, then deregister, force-flush, and shut it down during graceful teardown. Their `runtime_diagnostics()` snapshots contain bounded `code`, `message`, and `count` entries: A successful direct log or trace `force_flush()` also updates this snapshot with any queue drops observed so far; the diagnostic count remains cumulative through later flushes and shutdown. ```python from nemo_relay import ( OpenTelemetryLogConfig, OpenTelemetryLogSubscriber, OpenTelemetryMetricConfig, OpenTelemetryMetricSubscriber, ) # Equivalent explicit OTLP/HTTP paths are /v1/logs and /v1/metrics, respectively. logs = OpenTelemetryLogSubscriber(OpenTelemetryLogConfig("http://localhost:4318")) metrics = OpenTelemetryMetricSubscriber(OpenTelemetryMetricConfig("http://localhost:4318")) logs.register("otlp-logs") metrics.register("otlp-metrics") try: for diagnostic in logs.runtime_diagnostics().entries: print(diagnostic.code, diagnostic.message) finally: logs.deregister("otlp-logs") logs.force_flush() logs.shutdown() metrics.deregister("otlp-metrics") metrics.force_flush() metrics.shutdown() ``` Native subscriber delivery is asynchronous, so call `nemo_relay.subscribers.flush()` before you read subscriber output or exit. From an `asyncio` task, use `await nemo_relay.subscribers.flush_async()` so async event sanitizers can continue running on that event loop. For host integrations that need a serialized event shape, consume the canonical JSON payload from the subscriber event object: ```python import json import nemo_relay def on_event(event) -> None: payload = event.to_dict() print(payload["kind"], payload["name"]) assert json.loads(event.to_json()) == payload nemo_relay.subscribers.register("host-exporter", on_event) try: with nemo_relay.scope.scope("demo-agent", nemo_relay.ScopeType.Agent): nemo_relay.scope.event("initialized", data={"binding": "python"}) finally: nemo_relay.subscribers.flush() nemo_relay.subscribers.deregister("host-exporter") ``` ## Package Surface The public package modules are: - `nemo_relay.scope` - `nemo_relay.tools` - `nemo_relay.llm` - `nemo_relay.guardrails` - `nemo_relay.intercepts` - `nemo_relay.subscribers` - `nemo_relay.plugin` - `nemo_relay.adaptive` - `nemo_relay.observability` - `nemo_relay.typed` - `nemo_relay.codecs` ### Integrations - `nemo_relay.integrations.langchain` - `nemo_relay.integrations.langgraph` - `nemo_relay.integrations.deepagents` The compiled extension is exposed as `nemo_relay._native`. ## Documentation NeMo Relay Documentation: https://docs.nvidia.com/nemo/relay


نیازمندی

مقدار نام
xtr nemo-relay-cli-bin==0.11.0;
xtr nemo-relay[langgraph];
xtr cryptography>=50.0.0;
xtr deepagents<0.8.0,>=0.7.4;
xtr pyasn1>=0.6.4;
xtr google-adk<3.0.0,>=2.12.0;
xtr typing-extensions>=4.10.0;
xtr langchain<2.0.0,>=1.3.15;
xtr langchain-anthropic<2.0.0,>=1.4.8;
xtr langchain-core;
xtr langgraph<2.0.0,>=1.2.9;
xtr langgraph-checkpoint>=4.1.1;
xtr langgraph-sdk>=0.4.4;
xtr langsmith>=0.9.4;
xtr pydantic<3,>=2.11;
xtr nemo-relay[langchain];
xtr langchain-nvidia-ai-endpoints<2.0.0,>=1.4.2;
xtr aiohttp>=3.14.4;
xtr idna>=3.19;
xtr multidict>=6.9.1;
xtr nemo-relay[langchain];
xtr langgraph<2.0.0,>=1.2.9;


زبان مورد نیاز

مقدار نام
>=3.11 Python


نحوه نصب


نصب پکیج whl nemo-relay-0.9.4:

    pip install nemo-relay.whl


نصب پکیج tar.gz nemo-relay-0.9.4:

    pip install nemo-relay.tar.gz