Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

GTC Berlin side quest: one import hid 7 NVIDIA agent tools, so I made it lazy

说明与用途

在 NVIDIA NeMo Agent Toolkit 的纯净安装中,七个内置工具因模块在导入时引入 LangChain 而未能注册。将导入移动到方法内部后,所有工具均能注册,验证通过。

问题

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.

结果

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.

工作流

  • 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.

证据

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.

来源

  • 记录日期: 2026-11-01T18:59:21.799Z