nvidia-nat-crewai 1.3.dev0__py3-none-any.whl → 1.3.0rc1__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.
@@ -94,7 +94,7 @@ class CrewAIProfilerHandler(BaseProfilerCallback):
94
94
  if tool_info:
95
95
  tool_name = tool_info.name
96
96
  except Exception as e:
97
- logger.exception("Error getting tool name: %s", e, exc_info=True)
97
+ logger.exception("Error getting tool name: %s", e)
98
98
 
99
99
  try:
100
100
  # Pre-call usage event
@@ -132,7 +132,7 @@ class CrewAIProfilerHandler(BaseProfilerCallback):
132
132
  return result
133
133
 
134
134
  except Exception as e:
135
- logger.exception("ToolUsage._use error: %s", e)
135
+ logger.error("ToolUsage._use error: %s", e)
136
136
  raise
137
137
 
138
138
  return wrapped_tool_use
@@ -158,7 +158,7 @@ class CrewAIProfilerHandler(BaseProfilerCallback):
158
158
  for message in kwargs.get('messages', []):
159
159
  model_input += message.get('content', "")
160
160
  except Exception as e:
161
- logger.exception("Error getting model input: %s", e, exc_info=True)
161
+ logger.exception("Error getting model input: %s", e)
162
162
 
163
163
  # Record the start event
164
164
  input_stats = IntermediateStepPayload(
@@ -182,7 +182,7 @@ class CrewAIProfilerHandler(BaseProfilerCallback):
182
182
  msg = choice.model_extra["message"]
183
183
  model_output += msg.get('content', "")
184
184
  except Exception as e:
185
- logger.exception("Error getting model output: %s", e, exc_info=True)
185
+ logger.exception("Error getting model output: %s", e)
186
186
 
187
187
  now = time.time()
188
188
  # Record the end event
nat/plugins/crewai/llm.py CHANGED
@@ -14,67 +14,115 @@
14
14
  # limitations under the License.
15
15
 
16
16
  import os
17
+ from typing import TypeVar
17
18
 
18
19
  from nat.builder.builder import Builder
19
20
  from nat.builder.framework_enum import LLMFrameworkEnum
20
21
  from nat.cli.register_workflow import register_llm_client
22
+ from nat.data_models.llm import LLMBaseConfig
21
23
  from nat.data_models.retry_mixin import RetryMixin
24
+ from nat.data_models.thinking_mixin import ThinkingMixin
25
+ from nat.llm.azure_openai_llm import AzureOpenAIModelConfig
22
26
  from nat.llm.nim_llm import NIMModelConfig
23
27
  from nat.llm.openai_llm import OpenAIModelConfig
28
+ from nat.llm.utils.thinking import BaseThinkingInjector
29
+ from nat.llm.utils.thinking import FunctionArgumentWrapper
30
+ from nat.llm.utils.thinking import patch_with_thinking
24
31
  from nat.utils.exception_handlers.automatic_retries import patch_with_retry
32
+ from nat.utils.type_utils import override
25
33
 
34
+ ModelType = TypeVar("ModelType")
26
35
 
27
- @register_llm_client(config_type=NIMModelConfig, wrapper_type=LLMFrameworkEnum.CREWAI)
28
- async def nim_crewai(llm_config: NIMModelConfig, builder: Builder):
29
-
30
- from crewai import LLM
31
36
 
32
- config_obj = {
33
- **llm_config.model_dump(exclude={"type"}, by_alias=True),
34
- "model": f"nvidia_nim/{llm_config.model_name}",
35
- }
37
+ def _patch_llm_based_on_config(client: ModelType, llm_config: LLMBaseConfig) -> ModelType:
36
38
 
37
- # Because CrewAI 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 CrewAIThinkingInjector(BaseThinkingInjector):
39
40
 
40
- if ("NVIDIA_NIM_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")
45
-
46
- if (nvidai_api_key is not None):
47
- # Transfer the key to the correct environment variable for LiteLLM
48
- os.environ["NVIDIA_NIM_API_KEY"] = nvidai_api_key
49
-
50
- client = LLM(**config_obj)
41
+ @override
42
+ def inject(self, messages: list[dict[str, str]], *args, **kwargs) -> FunctionArgumentWrapper:
43
+ new_messages = [{"role": "system", "content": self.system_prompt}] + messages
44
+ return FunctionArgumentWrapper(new_messages, *args, **kwargs)
51
45
 
52
46
  if isinstance(llm_config, RetryMixin):
53
-
54
47
  client = patch_with_retry(client,
55
48
  retries=llm_config.num_retries,
56
49
  retry_codes=llm_config.retry_on_status_codes,
57
50
  retry_on_messages=llm_config.retry_on_errors)
58
51
 
59
- yield client
52
+ if isinstance(llm_config, ThinkingMixin) and llm_config.thinking_system_prompt is not None:
53
+ client = patch_with_thinking(
54
+ client, CrewAIThinkingInjector(
55
+ system_prompt=llm_config.thinking_system_prompt,
56
+ function_names=["call"],
57
+ ))
60
58
 
59
+ return client
61
60
 
62
- @register_llm_client(config_type=OpenAIModelConfig, wrapper_type=LLMFrameworkEnum.CREWAI)
63
- async def openai_crewai(llm_config: OpenAIModelConfig, builder: Builder):
61
+
62
+ @register_llm_client(config_type=AzureOpenAIModelConfig, wrapper_type=LLMFrameworkEnum.CREWAI)
63
+ async def azure_openai_crewai(llm_config: AzureOpenAIModelConfig, _builder: Builder):
64
64
 
65
65
  from crewai import LLM
66
66
 
67
- config_obj = {
68
- **llm_config.model_dump(exclude={"type"}, by_alias=True),
69
- }
67
+ # https://docs.crewai.com/en/concepts/llms#azure
68
+
69
+ api_key = llm_config.api_key or os.environ.get("AZURE_OPENAI_API_KEY") or os.environ.get("AZURE_API_KEY")
70
+ if api_key is None:
71
+ raise ValueError("Azure API key is not set")
72
+ os.environ["AZURE_API_KEY"] = api_key
73
+ api_base = (llm_config.azure_endpoint or os.environ.get("AZURE_OPENAI_ENDPOINT")
74
+ or os.environ.get("AZURE_API_BASE"))
75
+ if api_base is None:
76
+ raise ValueError("Azure endpoint is not set")
77
+ os.environ["AZURE_API_BASE"] = api_base
78
+
79
+ os.environ["AZURE_API_VERSION"] = llm_config.api_version
80
+ model = llm_config.azure_deployment or os.environ.get("AZURE_MODEL_DEPLOYMENT")
81
+ if model is None:
82
+ raise ValueError("Azure model deployment is not set")
83
+
84
+ client = LLM(
85
+ **llm_config.model_dump(
86
+ exclude={
87
+ "type",
88
+ "api_key",
89
+ "azure_endpoint",
90
+ "azure_deployment",
91
+ "thinking",
92
+ },
93
+ by_alias=True,
94
+ exclude_none=True,
95
+ ),
96
+ model=model,
97
+ )
98
+
99
+ yield _patch_llm_based_on_config(client, llm_config)
70
100
 
71
- client = LLM(**config_obj)
72
101
 
73
- if isinstance(llm_config, RetryMixin):
102
+ @register_llm_client(config_type=NIMModelConfig, wrapper_type=LLMFrameworkEnum.CREWAI)
103
+ async def nim_crewai(llm_config: NIMModelConfig, _builder: Builder):
74
104
 
75
- client = patch_with_retry(client,
76
- retries=llm_config.num_retries,
77
- retry_codes=llm_config.retry_on_status_codes,
78
- retry_on_messages=llm_config.retry_on_errors)
105
+ from crewai import LLM
106
+
107
+ # Because CrewAI uses a different environment variable for the API key, we need to set it here manually
108
+ if llm_config.api_key is None and "NVIDIA_NIM_API_KEY" not in os.environ:
109
+ nvidia_api_key = os.getenv("NVIDIA_API_KEY")
110
+ if nvidia_api_key is not None:
111
+ os.environ["NVIDIA_NIM_API_KEY"] = nvidia_api_key
112
+
113
+ client = LLM(
114
+ **llm_config.model_dump(exclude={"type", "model_name", "thinking"}, by_alias=True, exclude_none=True),
115
+ model=f"nvidia_nim/{llm_config.model_name}",
116
+ )
117
+
118
+ yield _patch_llm_based_on_config(client, llm_config)
119
+
120
+
121
+ @register_llm_client(config_type=OpenAIModelConfig, wrapper_type=LLMFrameworkEnum.CREWAI)
122
+ async def openai_crewai(llm_config: OpenAIModelConfig, _builder: Builder):
123
+
124
+ from crewai import LLM
125
+
126
+ client = LLM(**llm_config.model_dump(exclude={"type", "thinking"}, by_alias=True, exclude_none=True))
79
127
 
80
- yield client
128
+ yield _patch_llm_based_on_config(client, llm_config)
@@ -13,7 +13,6 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
- # pylint: disable=unused-import
17
16
  # flake8: noqa
18
17
  # isort:skip_file
19
18
 
@@ -1,13 +1,16 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nvidia-nat-crewai
3
- Version: 1.3.dev0
3
+ Version: 1.3.0rc1
4
4
  Summary: Subpackage for CrewAI integration in NeMo Agent toolkit
5
5
  Keywords: ai,rag,agents
6
6
  Classifier: Programming Language :: Python
7
- Requires-Python: <3.13,>=3.11
7
+ Classifier: Programming Language :: Python :: 3.11
8
+ Classifier: Programming Language :: Python :: 3.12
9
+ Classifier: Programming Language :: Python :: 3.13
10
+ Requires-Python: <3.14,>=3.11
8
11
  Description-Content-Type: text/markdown
9
- Requires-Dist: nvidia-nat==v1.3-dev
10
- Requires-Dist: crewai~=0.95.0
12
+ Requires-Dist: nvidia-nat[litellm]==v1.3.0-rc1
13
+ Requires-Dist: crewai~=0.193.2
11
14
 
12
15
  <!--
13
16
  SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
@@ -0,0 +1,11 @@
1
+ nat/meta/pypi.md,sha256=T68FnThRzDGFf1LR8u-okM-r11-skSnKqSyI6HOktQY,1107
2
+ nat/plugins/crewai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ nat/plugins/crewai/crewai_callback_handler.py,sha256=nBpWWpYQ-yrAG1-6G3kvcYrb0jJQzckd_ftojvGVWj4,8333
4
+ nat/plugins/crewai/llm.py,sha256=VKtRTCn4X5ReVD8F1mNCr4FYmcaE1vIcC3sKjvjmAXc,5079
5
+ nat/plugins/crewai/register.py,sha256=_R3bhGmz___696_NwyIcpw3koMBiWqIFoWEFJ0VAgXs,831
6
+ nat/plugins/crewai/tool_wrapper.py,sha256=BNKEPQQCLKtXNzGDAKBLCdmGJXe9lBOVI1hObha8hoI,1569
7
+ nvidia_nat_crewai-1.3.0rc1.dist-info/METADATA,sha256=2KEyyrpSbxCtfv0Zck6zc3hC2bOvzK1Bw-xKsv3lWJc,1605
8
+ nvidia_nat_crewai-1.3.0rc1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
+ nvidia_nat_crewai-1.3.0rc1.dist-info/entry_points.txt,sha256=YF5PUdQGr_OUDXB4TykElHJTsKT8yKkuE0bMX5n_RXs,58
10
+ nvidia_nat_crewai-1.3.0rc1.dist-info/top_level.txt,sha256=8-CJ2cP6-f0ZReXe5Hzqp-5pvzzHz-5Ds5H2bGqh1-U,4
11
+ nvidia_nat_crewai-1.3.0rc1.dist-info/RECORD,,
@@ -1,11 +0,0 @@
1
- nat/meta/pypi.md,sha256=T68FnThRzDGFf1LR8u-okM-r11-skSnKqSyI6HOktQY,1107
2
- nat/plugins/crewai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- nat/plugins/crewai/crewai_callback_handler.py,sha256=LDOctDQC9qdba1SVGoVkceCOSYuDj_mnl3HCuq2nIuQ,8382
4
- nat/plugins/crewai/llm.py,sha256=_ykUOFJCc9czWPGQZIfQerfqH_cGZfjZ09U297I4xuo,3000
5
- nat/plugins/crewai/register.py,sha256=RKXyuaXy4ftA5IL2RrCofIBjpie_-2lP9YZoHAiyPU0,863
6
- nat/plugins/crewai/tool_wrapper.py,sha256=BNKEPQQCLKtXNzGDAKBLCdmGJXe9lBOVI1hObha8hoI,1569
7
- nvidia_nat_crewai-1.3.dev0.dist-info/METADATA,sha256=BtcRz8pDXVcK_giQGeY0N8xmWPs9k5mP79aFwgIEYE0,1440
8
- nvidia_nat_crewai-1.3.dev0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
- nvidia_nat_crewai-1.3.dev0.dist-info/entry_points.txt,sha256=YF5PUdQGr_OUDXB4TykElHJTsKT8yKkuE0bMX5n_RXs,58
10
- nvidia_nat_crewai-1.3.dev0.dist-info/top_level.txt,sha256=8-CJ2cP6-f0ZReXe5Hzqp-5pvzzHz-5Ds5H2bGqh1-U,4
11
- nvidia_nat_crewai-1.3.dev0.dist-info/RECORD,,