Skip to navigation

NeMo Relay LangChain Integration

View as Markdown

Use the nemo_relay.integrations.langchain package to add NeMo Relay observability to LangChain agents.

Setup

Install the LangChain integration extra in your application environment.

uv add "nemo-relay[langchain]"

The example below uses the NVIDIA LangChain provider. Install that provider extra too if you want to run the example as written:

uv add "nemo-relay[langchain,langchain-nvidia]"

Usage Example

import asyncio
import nemo_relay
from langchain.agents import create_agent
from langchain_core.tools import tool
from nemo_relay.integrations.langchain import NemoRelayCallbackHandler, NemoRelayMiddleware
@tool
def get_weather(location: str) -> str:
"""Get the current weather for a location."""
return f"The weather in {location} is sunny and 72 degrees."
agent = create_agent(
model="nvidia:nvidia/nemotron-3-nano-30b-a3b",
tools=[get_weather],
middleware=[NemoRelayMiddleware()],
system_prompt="Use tools when they are relevant. Keep the final answer brief.",
)
input_payload = {
"messages": [
{
"role": "user",
"content": "What is the weather in San Francisco?",
}
]
}
with nemo_relay.scope.scope("langchain-request", nemo_relay.ScopeType.Agent):
result = asyncio.run(
agent.ainvoke(input_payload, config={"callbacks": [NemoRelayCallbackHandler()]})
)
final_message = result["messages"][-1]
print(f"Final response: {final_message.content}")

Verify the Integration

The integration works correctly when:

  • The agent run completes and prints a final response.
  • The langchain-request scope contains the managed model call.
  • Tool activity appears under the same request when the agent decides to use get_weather.

Observability

Refer to Observability for details on exporting NeMo Relay observability data to third-party systems.