{"id":8365,"library":"nvidia-nat-langchain","title":"NVIDIA NeMo Agent Toolkit LangChain/LangGraph Integration","description":"The `nvidia-nat-langchain` package is a subpackage designed for integrating LangChain and LangGraph with the NVIDIA NeMo Agent Toolkit (NAT). NAT is a flexible, lightweight, and framework-agnostic library that enhances AI agents with enterprise-grade capabilities like observability, profiling, evaluation, and orchestration. It allows users to leverage existing LangChain/LangGraph agents while benefiting from NAT's advanced features without significant code changes. The library is actively maintained, with version 1.6.0 being the current release, and follows a rapid development and release cadence.","status":"active","version":"1.6.0","language":"en","source_language":"en","source_url":"https://github.com/NVIDIA/NeMo-Agent-Toolkit","tags":["ai","rag","agents","langchain","langgraph","nvidia","nemo-agent-toolkit","observability","profiling"],"install":[{"cmd":"pip install nvidia-nat-langchain","lang":"bash","label":"Recommended installation"},{"cmd":"pip install \"nvidia-nat[langchain]\"","lang":"bash","label":"Install as an extra with nvidia-nat"}],"dependencies":[{"reason":"Core NVIDIA NeMo Agent Toolkit library.","package":"nvidia-nat"},{"reason":"Provides core LangChain functionalities; specific versions might be required for compatibility with nvidia-nat-langchain.","package":"langchain","optional":false},{"reason":"Provides core LangGraph functionalities; specific versions might be required for compatibility with nvidia-nat-langchain.","package":"langgraph","optional":true}],"imports":[{"note":"Used to wrap LangChain chains or agents to enable automatic token counting, latency measurement, and tracing to observability platforms.","symbol":"add_profiling_callbacks","correct":"from nvidia_nat.langchain import add_profiling_callbacks"},{"note":"Used to specify the framework (e.g., LangChain) when configuring components with NAT's builder system.","symbol":"LLMFrameworkEnum","correct":"from nat.builder.framework_enum import LLMFrameworkEnum"},{"note":"Provides access to NAT's dependency injection system for configuring and retrieving LLMs and tools.","symbol":"SyncBuilder","correct":"from nat.builder.sync_builder import SyncBuilder"}],"quickstart":{"code":"import os\nfrom langchain_core.prompts import ChatPromptTemplate\nfrom langchain_nvidia_ai_endpoints import ChatNVIDIA\nfrom langchain_core.output_parsers import StrOutputParser\nfrom nvidia_nat.langchain import add_profiling_callbacks\n\n# Ensure NVIDIA_API_KEY is set in your environment\n# You can get one from https://build.nvidia.com/\n# os.environ[\"NVIDIA_API_KEY\"] = \"nvapi-xxxxxxxxxxxxxxxxxxxxxxxx\"\n\nif not os.getenv(\"NVIDIA_API_KEY\"):\n    print(\"Please set the NVIDIA_API_KEY environment variable.\")\n    exit()\n\n# 1. Define your LangChain components\nprompt = ChatPromptTemplate.from_messages([\n    (\"system\", \"You are a helpful AI assistant.\"),\n    (\"user\", \"{input}\")\n])\nllm = ChatNVIDIA(model=\"meta/llama-3-8b-instruct\")\noutput_parser = StrOutputParser()\n\n# 2. Create your LangChain chain\nchain = prompt | llm | output_parser\n\n# 3. Add NeMo Agent Toolkit profiling callbacks to your chain\nprofiled_chain = add_profiling_callbacks(chain)\n\n# 4. Invoke the profiled chain\nresponse = profiled_chain.invoke({\"input\": \"What is the capital of France?\"})\nprint(response)\n\n# In a real NAT setup, you would typically run this via the `nat` CLI\n# with a YAML configuration, which automatically applies these integrations.","lang":"python","description":"This quickstart demonstrates how to integrate `nvidia-nat-langchain` for basic profiling with a LangChain chain. It assumes `langchain-nvidia-ai-endpoints` is also installed for `ChatNVIDIA`. The core idea is to wrap your existing LangChain construct with `add_profiling_callbacks` to enable NAT's observability features. In a full NeMo Agent Toolkit workflow, this integration is often handled through YAML configurations and the `nat` CLI."},"warnings":[{"fix":"Consult the `nvidia-nat` GitHub repository or documentation for a compatibility matrix. For `nvidia-nat` versions before 1.5.0, you might need to pin `langchain` and its sub-packages to compatible versions. `nvidia-nat` version 1.5.0 and later aim to improve dependency management.","message":"Potential version incompatibility with `langchain` and `langgraph`. Older `nvidia-nat` versions (and implicitly `nvidia-nat-langchain`) might rely on specific, older `langchain` versions, leading to `ModuleNotFoundError` or other import issues if your project uses newer LangChain versions.","severity":"breaking","affected_versions":"<1.5.0 of nvidia-nat"},{"fix":"New projects should directly use `nvidia-nat-langchain`. If migrating an existing project, update your dependencies to `nvidia-nat-langchain` instead of `aiqtoolkit-langchain`.","message":"The `aiqtoolkit-langchain` package is a transitional package that is deprecated. It will be removed in future releases.","severity":"deprecated","affected_versions":"All versions of `aiqtoolkit-langchain`"},{"fix":"Obtain an API key from `build.nvidia.com` and set it as an environment variable: `export NVIDIA_API_KEY=\"nvapi-xxxxxxxxxxxxxxxxxxxxxxxx\"`. Also, ensure `NGC_CLI_API_KEY` is set for specific local NIM deployments.","message":"Many functionalities, especially those interacting with NVIDIA's hosted models or NIM microservices, require the `NVIDIA_API_KEY` environment variable to be set.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Check the `nvidia-nat` official documentation or GitHub for compatible LangChain versions. You may need to downgrade your `langchain` packages or upgrade `nvidia-nat` to a version that supports your desired `langchain` version. Using a `pyproject.toml` with strict dependency pinning is recommended.","cause":"This typically occurs due to a mismatch between the installed `nvidia-nat` (and `nvidia-nat-langchain`) version and the `langchain` version. `nvidia-nat` might be trying to import from an older LangChain structure that no longer exists in your installed LangChain version.","error":"ModuleNotFoundError: No module named 'langchain.agents' (or similar for other langchain sub-modules)"},{"fix":"Ensure that your `NVIDIA_API_KEY` (and potentially `NGC_CLI_API_KEY` for certain local deployments) environment variable is correctly set and contains a valid API key obtained from `build.nvidia.com`.","cause":"This error, or a similar 'Error: NGC_API_KEY is not set', indicates that the API key required for authentication with NVIDIA services (like NIM microservices or hosted LLMs) is either missing or invalid.","error":"ERROR: [401] Unauthorized invalid response from UAM Please check or regenerate your API key."},{"fix":"This is an internal `nvidia-nat` issue that was addressed in later versions. Ensure you are using the latest stable version of `nvidia-nat` (and thus `nvidia-nat-langchain`). If the problem persists, consult the `NVIDIA/NeMo-Agent-Toolkit` GitHub issues for potential workarounds or specific version recommendations for Python 3.11+.","cause":"This warning (and potential related issues) can arise in Python 3.11+ environments when using the `nat serve` command, often due to how event loops are managed.","error":"RuntimeWarning: coroutine 'Server.serve' was never awaited (when running `nat serve`)"}]}