nvidia-nat-agno 1.3.0a20250826__py3-none-any.whl → 1.3.0a20250828__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
nat/plugins/agno/llm.py CHANGED
@@ -13,75 +13,89 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
- import os
16
+ from typing import TypeVar
17
17
 
18
18
  from nat.builder.builder import Builder
19
19
  from nat.builder.framework_enum import LLMFrameworkEnum
20
20
  from nat.cli.register_workflow import register_llm_client
21
+ from nat.data_models.llm import LLMBaseConfig
21
22
  from nat.data_models.retry_mixin import RetryMixin
23
+ from nat.data_models.thinking_mixin import ThinkingMixin
22
24
  from nat.llm.nim_llm import NIMModelConfig
23
25
  from nat.llm.openai_llm import OpenAIModelConfig
26
+ from nat.llm.utils.thinking import BaseThinkingInjector
27
+ from nat.llm.utils.thinking import FunctionArgumentWrapper
28
+ from nat.llm.utils.thinking import patch_with_thinking
24
29
  from nat.utils.exception_handlers.automatic_retries import patch_with_retry
30
+ from nat.utils.type_utils import override
25
31
 
32
+ ModelType = TypeVar("ModelType")
26
33
 
27
- @register_llm_client(config_type=NIMModelConfig, wrapper_type=LLMFrameworkEnum.AGNO)
28
- async def nim_agno(llm_config: NIMModelConfig, builder: Builder):
29
34
 
30
- from agno.models.nvidia import Nvidia
35
+ def _patch_llm_based_on_config(client: ModelType, llm_config: LLMBaseConfig) -> ModelType:
31
36
 
32
- config_obj = {
33
- **llm_config.model_dump(exclude={"type", "model_name"}, by_alias=True),
34
- "id": f"{llm_config.model_name}",
35
- }
37
+ from agno.models.message import Message
36
38
 
37
- # Because Agno uses a different environment variable for the API key, we need to set it here manually
38
- if ("api_key" not in config_obj or config_obj["api_key"] is None):
39
+ class AgnoThinkingInjector(BaseThinkingInjector):
39
40
 
40
- if ("NVIDIA_API_KEY" in os.environ):
41
- # Dont need to do anything. User has already set the correct key
42
- pass
43
- else:
44
- nvidai_api_key = os.getenv("NVIDIA_API_KEY")
41
+ from agno.models.message import Message
45
42
 
46
- if (nvidai_api_key is not None):
47
- # Transfer the key to the correct environment variable
48
- os.environ["NVIDIA_API_KEY"] = nvidai_api_key
43
+ @override
44
+ def inject(self, messages: list[Message], *args, **kwargs) -> FunctionArgumentWrapper:
45
+ new_messages = [Message(role="system", content=self.system_prompt)] + messages
46
+ return FunctionArgumentWrapper(new_messages, *args, **kwargs)
49
47
 
50
- # Create Nvidia instance with conditional base_url
51
- kwargs = {"id": config_obj.get("id")}
52
- if "base_url" in config_obj and config_obj.get("base_url") is not None:
53
- kwargs["base_url"] = config_obj.get("base_url")
54
-
55
- client = Nvidia(**kwargs) # type: ignore[arg-type]
56
-
57
- if isinstance(client, RetryMixin):
48
+ if isinstance(llm_config, ThinkingMixin) and llm_config.thinking_system_prompt is not None:
49
+ client = patch_with_thinking(
50
+ client,
51
+ AgnoThinkingInjector(system_prompt=llm_config.thinking_system_prompt,
52
+ function_names=[
53
+ "invoke_stream",
54
+ "invoke",
55
+ "ainvoke",
56
+ "ainvoke_stream",
57
+ ]))
58
58
 
59
+ if isinstance(llm_config, RetryMixin):
59
60
  client = patch_with_retry(client,
60
61
  retries=llm_config.num_retries,
61
62
  retry_codes=llm_config.retry_on_status_codes,
62
63
  retry_on_messages=llm_config.retry_on_errors)
63
64
 
64
- yield client
65
+ return client
65
66
 
66
67
 
67
- @register_llm_client(config_type=OpenAIModelConfig, wrapper_type=LLMFrameworkEnum.AGNO)
68
- async def openai_agno(llm_config: OpenAIModelConfig, builder: Builder):
68
+ @register_llm_client(config_type=NIMModelConfig, wrapper_type=LLMFrameworkEnum.AGNO)
69
+ async def nim_agno(llm_config: NIMModelConfig, _builder: Builder):
69
70
 
70
- from agno.models.openai import OpenAIChat
71
+ from agno.models.nvidia import Nvidia
72
+
73
+ config_obj = {
74
+ **llm_config.model_dump(
75
+ exclude={"type", "model_name"},
76
+ by_alias=True,
77
+ exclude_none=True,
78
+ ),
79
+ }
71
80
 
72
- # Use model_dump to get the proper field values with correct types
73
- kwargs = llm_config.model_dump(exclude={"type"}, by_alias=True)
81
+ client = Nvidia(**config_obj, id=llm_config.model_name)
74
82
 
75
- # AGNO uses 'id' instead of 'model' for the model name
76
- if "model" in kwargs:
77
- kwargs["id"] = kwargs.pop("model")
83
+ yield _patch_llm_based_on_config(client, llm_config)
78
84
 
79
- client = OpenAIChat(**kwargs)
80
85
 
81
- if isinstance(llm_config, RetryMixin):
82
- client = patch_with_retry(client,
83
- retries=llm_config.num_retries,
84
- retry_codes=llm_config.retry_on_status_codes,
85
- retry_on_messages=llm_config.retry_on_errors)
86
+ @register_llm_client(config_type=OpenAIModelConfig, wrapper_type=LLMFrameworkEnum.AGNO)
87
+ async def openai_agno(llm_config: OpenAIModelConfig, _builder: Builder):
88
+
89
+ from agno.models.openai import OpenAIChat
90
+
91
+ config_obj = {
92
+ **llm_config.model_dump(
93
+ exclude={"type", "model_name"},
94
+ by_alias=True,
95
+ exclude_none=True,
96
+ ),
97
+ }
98
+
99
+ client = OpenAIChat(**config_obj, id=llm_config.model_name)
86
100
 
87
- yield client
101
+ yield _patch_llm_based_on_config(client, llm_config)
@@ -1,12 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nvidia-nat-agno
3
- Version: 1.3.0a20250826
3
+ Version: 1.3.0a20250828
4
4
  Summary: Subpackage for Agno integration in NeMo Agent toolkit
5
5
  Keywords: ai,rag,agents
6
6
  Classifier: Programming Language :: Python
7
7
  Requires-Python: <3.13,>=3.11
8
8
  Description-Content-Type: text/markdown
9
- Requires-Dist: nvidia-nat==v1.3.0a20250826
9
+ Requires-Dist: nvidia-nat==v1.3.0a20250828
10
10
  Requires-Dist: agno~=1.2.3
11
11
  Requires-Dist: openai~=1.66
12
12
  Requires-Dist: google-search-results~=2.4.2
@@ -1,13 +1,13 @@
1
1
  nat/meta/pypi.md,sha256=tZD7hiOSYWgiAdddD1eIJ8T5ipZwEIjnd8ilgmasdmw,1198
2
2
  nat/plugins/agno/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- nat/plugins/agno/llm.py,sha256=hvPu0-gkRasnWZY5kwHOiA6rZ1ZIGlnaH3nPPfqrFJ8,3434
3
+ nat/plugins/agno/llm.py,sha256=QWJAQopnsb51efVkTHYsyolvkBB09dFSLpwjn847qTY,3804
4
4
  nat/plugins/agno/register.py,sha256=q-es1KVb_PTHOFszltym7e7Pj2jmyieih_Ve-cguHI8,788
5
5
  nat/plugins/agno/tool_wrapper.py,sha256=VEslkY_jerrgZDyVnW5WSjC3xl2gt8-afSMODZ1HMzU,15856
6
6
  nat/plugins/agno/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  nat/plugins/agno/tools/register.py,sha256=mpNgD1r51EoYlQiEAqPX15wCtx2alDcMIQiR8F_ub-M,743
8
8
  nat/plugins/agno/tools/serp_api_tool.py,sha256=AJQH6-1iEUUrk_nzfZ3zZqutEKhJ_LMOUJi_iol65Sc,4442
9
- nvidia_nat_agno-1.3.0a20250826.dist-info/METADATA,sha256=PQu4UAZSW7251-3tlC_n9PN_cP6Lt09aS4SDmzMpi34,1609
10
- nvidia_nat_agno-1.3.0a20250826.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
- nvidia_nat_agno-1.3.0a20250826.dist-info/entry_points.txt,sha256=qRhuHKj2WmdJkLpbVXpYkdtc2cZdG4LPlBsABG2ImVI,103
12
- nvidia_nat_agno-1.3.0a20250826.dist-info/top_level.txt,sha256=8-CJ2cP6-f0ZReXe5Hzqp-5pvzzHz-5Ds5H2bGqh1-U,4
13
- nvidia_nat_agno-1.3.0a20250826.dist-info/RECORD,,
9
+ nvidia_nat_agno-1.3.0a20250828.dist-info/METADATA,sha256=9TeTsXNymJBQapUI9eBcFtT9nVsm_X0GvXc7tpRbcLI,1609
10
+ nvidia_nat_agno-1.3.0a20250828.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
+ nvidia_nat_agno-1.3.0a20250828.dist-info/entry_points.txt,sha256=qRhuHKj2WmdJkLpbVXpYkdtc2cZdG4LPlBsABG2ImVI,103
12
+ nvidia_nat_agno-1.3.0a20250828.dist-info/top_level.txt,sha256=8-CJ2cP6-f0ZReXe5Hzqp-5pvzzHz-5Ds5H2bGqh1-U,4
13
+ nvidia_nat_agno-1.3.0a20250828.dist-info/RECORD,,