GTC Berlin side quest: one import hid 7 NVIDIA agent tools, so I made it lazy
Description and use
On a plain install of NVIDIA’s NeMo Agent Toolkit, seven built‑in tools failed to register because a module imported LangChain at import time. Moving the import into a method allows all tools to register, and validation succeeds.
Problem
On a plain install of NVIDIA’s NeMo Agent Toolkit, seven built‑in tools were not registered because a module imported a LangChain class at import time, causing a ModuleNotFoundError that stopped the plugin loader.
Outcome
The fix moved a LangChain import from module level to a method, allowing all built‑in tools to register on a plain install. Validation now succeeds and the warning disappears.
Workflow
- 1. Build a fresh virtual environment with only nvidia-nat-core and nvidia-nat-atif.
- 2. Run nat validate on a workflow using the code_execution tool.
- 3. Observe the validator error and the warning about missing langchain_core.
- 4. Inspect nat/tool/register.py to see the import order.
- 5. Identify that nvidia_rag.py imports langchain_core.Document at module level.
- 6. Move the import inside the to_document() method.
- 7. Add a regression test that mocks sys.modules to block langchain_core and verifies registration.
- 8. Run the full test suite; all tests pass.
- 9. Merge PR #2474, approved within 19 hours.
- 10. Verify that nat validate now succeeds and no warning is logged.
Evidence
Seven of the library's 12 built-in tools never registered, and the error message pointed somewhere else entirely.
The toolkit registers its built-in tools by importing a list of modules, one after another. One of those modules asked for a LangChain class the moment it was imported.
Move the import to the moment it is needed. Document is only used inside one method, the one that turns a RAG result into a LangChain document, so the import now lives inside that method.
The regression test plays the plain install on any machine: it blocks every langchain_core entry in sys.modules, imports nat.tool.nvidia_rag fresh against a mocked registry, and checks that the tool registers.
- Record date: 2026-11-01T18:59:21.799Z