nvidia-nat 1.3.0a20251008__py3-none-any.whl → 1.3.0a20251012__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/agent/react_agent/register.py +15 -24
- nat/agent/rewoo_agent/register.py +15 -24
- nat/agent/tool_calling_agent/register.py +9 -5
- nat/builder/function.py +4 -4
- nat/cli/entrypoint.py +4 -0
- nat/data_models/api_server.py +78 -9
- nat/front_ends/mcp/mcp_front_end_config.py +32 -0
- nat/runtime/runner.py +1 -2
- nat/utils/type_converter.py +8 -0
- {nvidia_nat-1.3.0a20251008.dist-info → nvidia_nat-1.3.0a20251012.dist-info}/METADATA +4 -3
- {nvidia_nat-1.3.0a20251008.dist-info → nvidia_nat-1.3.0a20251012.dist-info}/RECORD +16 -16
- {nvidia_nat-1.3.0a20251008.dist-info → nvidia_nat-1.3.0a20251012.dist-info}/WHEEL +0 -0
- {nvidia_nat-1.3.0a20251008.dist-info → nvidia_nat-1.3.0a20251012.dist-info}/entry_points.txt +0 -0
- {nvidia_nat-1.3.0a20251008.dist-info → nvidia_nat-1.3.0a20251012.dist-info}/licenses/LICENSE-3rd-party.txt +0 -0
- {nvidia_nat-1.3.0a20251008.dist-info → nvidia_nat-1.3.0a20251012.dist-info}/licenses/LICENSE.md +0 -0
- {nvidia_nat-1.3.0a20251008.dist-info → nvidia_nat-1.3.0a20251012.dist-info}/top_level.txt +0 -0
|
@@ -24,6 +24,7 @@ from nat.builder.function_info import FunctionInfo
|
|
|
24
24
|
from nat.cli.register_workflow import register_function
|
|
25
25
|
from nat.data_models.agent import AgentBaseConfig
|
|
26
26
|
from nat.data_models.api_server import ChatRequest
|
|
27
|
+
from nat.data_models.api_server import ChatRequestOrMessage
|
|
27
28
|
from nat.data_models.api_server import ChatResponse
|
|
28
29
|
from nat.data_models.api_server import Usage
|
|
29
30
|
from nat.data_models.component_ref import FunctionGroupRef
|
|
@@ -70,9 +71,6 @@ class ReActAgentWorkflowConfig(AgentBaseConfig, OptimizableMixin, name="react_ag
|
|
|
70
71
|
default=None,
|
|
71
72
|
description="Provides the SYSTEM_PROMPT to use with the agent") # defaults to SYSTEM_PROMPT in prompt.py
|
|
72
73
|
max_history: int = Field(default=15, description="Maximum number of messages to keep in the conversation history.")
|
|
73
|
-
use_openai_api: bool = Field(default=False,
|
|
74
|
-
description=("Use OpenAI API for the input/output types to the function. "
|
|
75
|
-
"If False, strings will be used."))
|
|
76
74
|
additional_instructions: str | None = OptimizableField(
|
|
77
75
|
default=None,
|
|
78
76
|
description="Additional instructions to provide to the agent in addition to the base prompt.",
|
|
@@ -118,21 +116,23 @@ async def react_agent_workflow(config: ReActAgentWorkflowConfig, builder: Builde
|
|
|
118
116
|
pass_tool_call_errors_to_agent=config.pass_tool_call_errors_to_agent,
|
|
119
117
|
normalize_tool_input_quotes=config.normalize_tool_input_quotes).build_graph()
|
|
120
118
|
|
|
121
|
-
async def _response_fn(
|
|
119
|
+
async def _response_fn(chat_request_or_message: ChatRequestOrMessage) -> ChatResponse | str:
|
|
122
120
|
"""
|
|
123
121
|
Main workflow entry function for the ReAct Agent.
|
|
124
122
|
|
|
125
123
|
This function invokes the ReAct Agent Graph and returns the response.
|
|
126
124
|
|
|
127
125
|
Args:
|
|
128
|
-
|
|
126
|
+
chat_request_or_message (ChatRequestOrMessage): The input message to process
|
|
129
127
|
|
|
130
128
|
Returns:
|
|
131
|
-
ChatResponse: The response from the agent or error message
|
|
129
|
+
ChatResponse | str: The response from the agent or error message
|
|
132
130
|
"""
|
|
133
131
|
try:
|
|
132
|
+
message = GlobalTypeConverter.get().convert(chat_request_or_message, to_type=ChatRequest)
|
|
133
|
+
|
|
134
134
|
# initialize the starting state with the user query
|
|
135
|
-
messages: list[BaseMessage] = trim_messages(messages=[m.model_dump() for m in
|
|
135
|
+
messages: list[BaseMessage] = trim_messages(messages=[m.model_dump() for m in message.messages],
|
|
136
136
|
max_tokens=config.max_history,
|
|
137
137
|
strategy="last",
|
|
138
138
|
token_counter=len,
|
|
@@ -153,25 +153,16 @@ async def react_agent_workflow(config: ReActAgentWorkflowConfig, builder: Builde
|
|
|
153
153
|
content = str(output_message.content)
|
|
154
154
|
|
|
155
155
|
# Create usage statistics for the response
|
|
156
|
-
prompt_tokens = sum(len(str(msg.content).split()) for msg in
|
|
156
|
+
prompt_tokens = sum(len(str(msg.content).split()) for msg in message.messages)
|
|
157
157
|
completion_tokens = len(content.split()) if content else 0
|
|
158
158
|
total_tokens = prompt_tokens + completion_tokens
|
|
159
159
|
usage = Usage(prompt_tokens=prompt_tokens, completion_tokens=completion_tokens, total_tokens=total_tokens)
|
|
160
|
-
|
|
161
|
-
|
|
160
|
+
response = ChatResponse.from_string(content, usage=usage)
|
|
161
|
+
if chat_request_or_message.is_string:
|
|
162
|
+
return GlobalTypeConverter.get().convert(response, to_type=str)
|
|
163
|
+
return response
|
|
162
164
|
except Exception as ex:
|
|
163
|
-
logger.
|
|
164
|
-
raise
|
|
165
|
-
|
|
166
|
-
if (config.use_openai_api):
|
|
167
|
-
yield FunctionInfo.from_fn(_response_fn, description=config.description)
|
|
168
|
-
else:
|
|
169
|
-
|
|
170
|
-
async def _str_api_fn(input_message: str) -> str:
|
|
171
|
-
oai_input = GlobalTypeConverter.get().try_convert(input_message, to_type=ChatRequest)
|
|
172
|
-
|
|
173
|
-
oai_output = await _response_fn(oai_input)
|
|
174
|
-
|
|
175
|
-
return GlobalTypeConverter.get().try_convert(oai_output, to_type=str)
|
|
165
|
+
logger.error("%s ReAct Agent failed with exception: %s", AGENT_LOG_PREFIX, str(ex))
|
|
166
|
+
raise
|
|
176
167
|
|
|
177
|
-
|
|
168
|
+
yield FunctionInfo.from_fn(_response_fn, description=config.description)
|
|
@@ -25,6 +25,7 @@ from nat.builder.function_info import FunctionInfo
|
|
|
25
25
|
from nat.cli.register_workflow import register_function
|
|
26
26
|
from nat.data_models.agent import AgentBaseConfig
|
|
27
27
|
from nat.data_models.api_server import ChatRequest
|
|
28
|
+
from nat.data_models.api_server import ChatRequestOrMessage
|
|
28
29
|
from nat.data_models.api_server import ChatResponse
|
|
29
30
|
from nat.data_models.api_server import Usage
|
|
30
31
|
from nat.data_models.component_ref import FunctionGroupRef
|
|
@@ -54,9 +55,6 @@ class ReWOOAgentWorkflowConfig(AgentBaseConfig, name="rewoo_agent"):
|
|
|
54
55
|
description="The number of retries before raising a tool call error.",
|
|
55
56
|
ge=1)
|
|
56
57
|
max_history: int = Field(default=15, description="Maximum number of messages to keep in the conversation history.")
|
|
57
|
-
use_openai_api: bool = Field(default=False,
|
|
58
|
-
description=("Use OpenAI API for the input/output types to the function. "
|
|
59
|
-
"If False, strings will be used."))
|
|
60
58
|
additional_planner_instructions: str | None = Field(
|
|
61
59
|
default=None,
|
|
62
60
|
validation_alias=AliasChoices("additional_planner_instructions", "additional_instructions"),
|
|
@@ -125,21 +123,23 @@ async def rewoo_agent_workflow(config: ReWOOAgentWorkflowConfig, builder: Builde
|
|
|
125
123
|
tool_call_max_retries=config.tool_call_max_retries,
|
|
126
124
|
raise_tool_call_error=config.raise_tool_call_error).build_graph()
|
|
127
125
|
|
|
128
|
-
async def _response_fn(
|
|
126
|
+
async def _response_fn(chat_request_or_message: ChatRequestOrMessage) -> ChatResponse | str:
|
|
129
127
|
"""
|
|
130
128
|
Main workflow entry function for the ReWOO Agent.
|
|
131
129
|
|
|
132
130
|
This function invokes the ReWOO Agent Graph and returns the response.
|
|
133
131
|
|
|
134
132
|
Args:
|
|
135
|
-
|
|
133
|
+
chat_request_or_message (ChatRequestOrMessage): The input message to process
|
|
136
134
|
|
|
137
135
|
Returns:
|
|
138
|
-
ChatResponse: The response from the agent or error message
|
|
136
|
+
ChatResponse | str: The response from the agent or error message
|
|
139
137
|
"""
|
|
140
138
|
try:
|
|
139
|
+
message = GlobalTypeConverter.get().convert(chat_request_or_message, to_type=ChatRequest)
|
|
140
|
+
|
|
141
141
|
# initialize the starting state with the user query
|
|
142
|
-
messages: list[BaseMessage] = trim_messages(messages=[m.model_dump() for m in
|
|
142
|
+
messages: list[BaseMessage] = trim_messages(messages=[m.model_dump() for m in message.messages],
|
|
143
143
|
max_tokens=config.max_history,
|
|
144
144
|
strategy="last",
|
|
145
145
|
token_counter=len,
|
|
@@ -160,25 +160,16 @@ async def rewoo_agent_workflow(config: ReWOOAgentWorkflowConfig, builder: Builde
|
|
|
160
160
|
output_message = str(output_message)
|
|
161
161
|
|
|
162
162
|
# Create usage statistics for the response
|
|
163
|
-
prompt_tokens = sum(len(str(msg.content).split()) for msg in
|
|
163
|
+
prompt_tokens = sum(len(str(msg.content).split()) for msg in message.messages)
|
|
164
164
|
completion_tokens = len(output_message.split()) if output_message else 0
|
|
165
165
|
total_tokens = prompt_tokens + completion_tokens
|
|
166
166
|
usage = Usage(prompt_tokens=prompt_tokens, completion_tokens=completion_tokens, total_tokens=total_tokens)
|
|
167
|
-
|
|
168
|
-
|
|
167
|
+
response = ChatResponse.from_string(output_message, usage=usage)
|
|
168
|
+
if chat_request_or_message.is_string:
|
|
169
|
+
return GlobalTypeConverter.get().convert(response, to_type=str)
|
|
170
|
+
return response
|
|
169
171
|
except Exception as ex:
|
|
170
|
-
logger.
|
|
171
|
-
raise
|
|
172
|
-
|
|
173
|
-
if (config.use_openai_api):
|
|
174
|
-
yield FunctionInfo.from_fn(_response_fn, description=config.description)
|
|
175
|
-
|
|
176
|
-
else:
|
|
177
|
-
|
|
178
|
-
async def _str_api_fn(input_message: str) -> str:
|
|
179
|
-
oai_input = GlobalTypeConverter.get().try_convert(input_message, to_type=ChatRequest)
|
|
180
|
-
oai_output = await _response_fn(oai_input)
|
|
181
|
-
|
|
182
|
-
return GlobalTypeConverter.get().try_convert(oai_output, to_type=str)
|
|
172
|
+
logger.error("ReWOO Agent failed with exception: %s", ex)
|
|
173
|
+
raise
|
|
183
174
|
|
|
184
|
-
|
|
175
|
+
yield FunctionInfo.from_fn(_response_fn, description=config.description)
|
|
@@ -23,8 +23,10 @@ from nat.builder.function_info import FunctionInfo
|
|
|
23
23
|
from nat.cli.register_workflow import register_function
|
|
24
24
|
from nat.data_models.agent import AgentBaseConfig
|
|
25
25
|
from nat.data_models.api_server import ChatRequest
|
|
26
|
+
from nat.data_models.api_server import ChatRequestOrMessage
|
|
26
27
|
from nat.data_models.component_ref import FunctionGroupRef
|
|
27
28
|
from nat.data_models.component_ref import FunctionRef
|
|
29
|
+
from nat.utils.type_converter import GlobalTypeConverter
|
|
28
30
|
|
|
29
31
|
logger = logging.getLogger(__name__)
|
|
30
32
|
|
|
@@ -81,21 +83,23 @@ async def tool_calling_agent_workflow(config: ToolCallAgentWorkflowConfig, build
|
|
|
81
83
|
handle_tool_errors=config.handle_tool_errors,
|
|
82
84
|
return_direct=return_direct_tools).build_graph()
|
|
83
85
|
|
|
84
|
-
async def _response_fn(
|
|
86
|
+
async def _response_fn(chat_request_or_message: ChatRequestOrMessage) -> str:
|
|
85
87
|
"""
|
|
86
88
|
Main workflow entry function for the Tool Calling Agent.
|
|
87
89
|
|
|
88
90
|
This function invokes the Tool Calling Agent Graph and returns the response.
|
|
89
91
|
|
|
90
92
|
Args:
|
|
91
|
-
|
|
93
|
+
chat_request_or_message (ChatRequestOrMessage): The input message to process
|
|
92
94
|
|
|
93
95
|
Returns:
|
|
94
96
|
str: The response from the agent or error message
|
|
95
97
|
"""
|
|
96
98
|
try:
|
|
99
|
+
message = GlobalTypeConverter.get().convert(chat_request_or_message, to_type=ChatRequest)
|
|
100
|
+
|
|
97
101
|
# initialize the starting state with the user query
|
|
98
|
-
messages: list[BaseMessage] = trim_messages(messages=[m.model_dump() for m in
|
|
102
|
+
messages: list[BaseMessage] = trim_messages(messages=[m.model_dump() for m in message.messages],
|
|
99
103
|
max_tokens=config.max_history,
|
|
100
104
|
strategy="last",
|
|
101
105
|
token_counter=len,
|
|
@@ -114,8 +118,8 @@ async def tool_calling_agent_workflow(config: ToolCallAgentWorkflowConfig, build
|
|
|
114
118
|
output_message = state.messages[-1]
|
|
115
119
|
return str(output_message.content)
|
|
116
120
|
except Exception as ex:
|
|
117
|
-
logger.
|
|
118
|
-
raise
|
|
121
|
+
logger.error("%s Tool Calling Agent failed with exception: %s", AGENT_LOG_PREFIX, ex)
|
|
122
|
+
raise
|
|
119
123
|
|
|
120
124
|
try:
|
|
121
125
|
yield FunctionInfo.from_fn(_response_fn, description=config.description)
|
nat/builder/function.py
CHANGED
|
@@ -159,8 +159,7 @@ class Function(FunctionBase[InputT, StreamingOutputT, SingleOutputT], ABC):
|
|
|
159
159
|
|
|
160
160
|
return result
|
|
161
161
|
except Exception as e:
|
|
162
|
-
|
|
163
|
-
logger.error("Error with ainvoke in function with input: %s. %s", value, err_msg)
|
|
162
|
+
logger.error("Error with ainvoke in function with input: %s. Error: %s", value, e)
|
|
164
163
|
raise
|
|
165
164
|
|
|
166
165
|
@typing.final
|
|
@@ -416,8 +415,9 @@ class FunctionGroup:
|
|
|
416
415
|
"""
|
|
417
416
|
if not name.strip():
|
|
418
417
|
raise ValueError("Function name cannot be empty or blank")
|
|
419
|
-
if not re.match(r"^[a-zA-Z0-9_
|
|
420
|
-
raise ValueError(
|
|
418
|
+
if not re.match(r"^[a-zA-Z0-9_.-]+$", name):
|
|
419
|
+
raise ValueError(
|
|
420
|
+
f"Function name can only contain letters, numbers, underscores, periods, and hyphens: {name}")
|
|
421
421
|
if name in self._functions:
|
|
422
422
|
raise ValueError(f"Function {name} already exists in function group {self._instance_name}")
|
|
423
423
|
|
nat/cli/entrypoint.py
CHANGED
|
@@ -29,6 +29,7 @@ import time
|
|
|
29
29
|
|
|
30
30
|
import click
|
|
31
31
|
import nest_asyncio
|
|
32
|
+
from dotenv import load_dotenv
|
|
32
33
|
|
|
33
34
|
from nat.utils.log_levels import LOG_LEVELS
|
|
34
35
|
|
|
@@ -45,6 +46,9 @@ from .commands.uninstall import uninstall_command
|
|
|
45
46
|
from .commands.validate import validate_command
|
|
46
47
|
from .commands.workflow.workflow import workflow_command
|
|
47
48
|
|
|
49
|
+
# Load environment variables from .env file, if it exists
|
|
50
|
+
load_dotenv()
|
|
51
|
+
|
|
48
52
|
# Apply at the beginning of the file to avoid issues with asyncio
|
|
49
53
|
nest_asyncio.apply()
|
|
50
54
|
|
nat/data_models/api_server.py
CHANGED
|
@@ -28,6 +28,7 @@ from pydantic import HttpUrl
|
|
|
28
28
|
from pydantic import conlist
|
|
29
29
|
from pydantic import field_serializer
|
|
30
30
|
from pydantic import field_validator
|
|
31
|
+
from pydantic import model_validator
|
|
31
32
|
from pydantic_core.core_schema import ValidationInfo
|
|
32
33
|
|
|
33
34
|
from nat.data_models.interactive import HumanPrompt
|
|
@@ -120,15 +121,7 @@ class Message(BaseModel):
|
|
|
120
121
|
role: UserMessageContentRoleType
|
|
121
122
|
|
|
122
123
|
|
|
123
|
-
class
|
|
124
|
-
"""
|
|
125
|
-
ChatRequest is a data model that represents a request to the NAT chat API.
|
|
126
|
-
Fully compatible with OpenAI Chat Completions API specification.
|
|
127
|
-
"""
|
|
128
|
-
|
|
129
|
-
# Required fields
|
|
130
|
-
messages: typing.Annotated[list[Message], conlist(Message, min_length=1)]
|
|
131
|
-
|
|
124
|
+
class ChatRequestOptionals(BaseModel):
|
|
132
125
|
# Optional fields (OpenAI Chat Completions API compatible)
|
|
133
126
|
model: str | None = Field(default=None, description="name of the model to use")
|
|
134
127
|
frequency_penalty: float | None = Field(default=0.0,
|
|
@@ -153,6 +146,16 @@ class ChatRequest(BaseModel):
|
|
|
153
146
|
parallel_tool_calls: bool | None = Field(default=True, description="Whether to enable parallel function calling")
|
|
154
147
|
user: str | None = Field(default=None, description="Unique identifier representing end-user")
|
|
155
148
|
|
|
149
|
+
|
|
150
|
+
class ChatRequest(ChatRequestOptionals):
|
|
151
|
+
"""
|
|
152
|
+
ChatRequest is a data model that represents a request to the NAT chat API.
|
|
153
|
+
Fully compatible with OpenAI Chat Completions API specification.
|
|
154
|
+
"""
|
|
155
|
+
|
|
156
|
+
# Required fields
|
|
157
|
+
messages: typing.Annotated[list[Message], conlist(Message, min_length=1)]
|
|
158
|
+
|
|
156
159
|
model_config = ConfigDict(extra="allow",
|
|
157
160
|
json_schema_extra={
|
|
158
161
|
"example": {
|
|
@@ -194,6 +197,42 @@ class ChatRequest(BaseModel):
|
|
|
194
197
|
top_p=top_p)
|
|
195
198
|
|
|
196
199
|
|
|
200
|
+
class ChatRequestOrMessage(ChatRequestOptionals):
|
|
201
|
+
"""
|
|
202
|
+
ChatRequestOrMessage is a data model that represents either a conversation or a string input.
|
|
203
|
+
This is useful for functions that can handle either type of input.
|
|
204
|
+
|
|
205
|
+
`messages` is compatible with the OpenAI Chat Completions API specification.
|
|
206
|
+
|
|
207
|
+
`input_string` is a string input that can be used for functions that do not require a conversation.
|
|
208
|
+
"""
|
|
209
|
+
|
|
210
|
+
messages: typing.Annotated[list[Message] | None, conlist(Message, min_length=1)] = Field(
|
|
211
|
+
default=None, description="The conversation messages to process.")
|
|
212
|
+
|
|
213
|
+
input_string: str | None = Field(default=None, alias="input_message", description="The input message to process.")
|
|
214
|
+
|
|
215
|
+
@property
|
|
216
|
+
def is_string(self) -> bool:
|
|
217
|
+
return self.input_string is not None
|
|
218
|
+
|
|
219
|
+
@property
|
|
220
|
+
def is_conversation(self) -> bool:
|
|
221
|
+
return self.messages is not None
|
|
222
|
+
|
|
223
|
+
@model_validator(mode="after")
|
|
224
|
+
def validate_messages_or_input_string(self):
|
|
225
|
+
if self.messages is not None and self.input_string is not None:
|
|
226
|
+
raise ValueError("Either messages or input_message/input_string must be provided, not both")
|
|
227
|
+
if self.messages is None and self.input_string is None:
|
|
228
|
+
raise ValueError("Either messages or input_message/input_string must be provided")
|
|
229
|
+
if self.input_string is not None:
|
|
230
|
+
extra_fields = self.model_dump(exclude={"input_string"}, exclude_none=True, exclude_unset=True)
|
|
231
|
+
if len(extra_fields) > 0:
|
|
232
|
+
raise ValueError("no extra fields are permitted when input_message/input_string is provided")
|
|
233
|
+
return self
|
|
234
|
+
|
|
235
|
+
|
|
197
236
|
class ChoiceMessage(BaseModel):
|
|
198
237
|
content: str | None = None
|
|
199
238
|
role: UserMessageContentRoleType | None = None
|
|
@@ -661,6 +700,36 @@ def _string_to_nat_chat_request(data: str) -> ChatRequest:
|
|
|
661
700
|
GlobalTypeConverter.register_converter(_string_to_nat_chat_request)
|
|
662
701
|
|
|
663
702
|
|
|
703
|
+
def _chat_request_or_message_to_chat_request(data: ChatRequestOrMessage) -> ChatRequest:
|
|
704
|
+
if data.input_string is not None:
|
|
705
|
+
return _string_to_nat_chat_request(data.input_string)
|
|
706
|
+
return ChatRequest(**data.model_dump(exclude={"input_string"}))
|
|
707
|
+
|
|
708
|
+
|
|
709
|
+
GlobalTypeConverter.register_converter(_chat_request_or_message_to_chat_request)
|
|
710
|
+
|
|
711
|
+
|
|
712
|
+
def _chat_request_to_chat_request_or_message(data: ChatRequest) -> ChatRequestOrMessage:
|
|
713
|
+
return ChatRequestOrMessage(**data.model_dump(by_alias=True))
|
|
714
|
+
|
|
715
|
+
|
|
716
|
+
GlobalTypeConverter.register_converter(_chat_request_to_chat_request_or_message)
|
|
717
|
+
|
|
718
|
+
|
|
719
|
+
def _chat_request_or_message_to_string(data: ChatRequestOrMessage) -> str:
|
|
720
|
+
return data.input_string or ""
|
|
721
|
+
|
|
722
|
+
|
|
723
|
+
GlobalTypeConverter.register_converter(_chat_request_or_message_to_string)
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+
def _string_to_chat_request_or_message(data: str) -> ChatRequestOrMessage:
|
|
727
|
+
return ChatRequestOrMessage(input_message=data)
|
|
728
|
+
|
|
729
|
+
|
|
730
|
+
GlobalTypeConverter.register_converter(_string_to_chat_request_or_message)
|
|
731
|
+
|
|
732
|
+
|
|
664
733
|
# ======== ChatResponse Converters ========
|
|
665
734
|
def _nat_chat_response_to_string(data: ChatResponse) -> str:
|
|
666
735
|
if data.choices and data.choices[0].message:
|
|
@@ -13,13 +13,17 @@
|
|
|
13
13
|
# See the License for the specific language governing permissions and
|
|
14
14
|
# limitations under the License.
|
|
15
15
|
|
|
16
|
+
import logging
|
|
16
17
|
from typing import Literal
|
|
17
18
|
|
|
18
19
|
from pydantic import Field
|
|
20
|
+
from pydantic import model_validator
|
|
19
21
|
|
|
20
22
|
from nat.authentication.oauth2.oauth2_resource_server_config import OAuth2ResourceServerConfig
|
|
21
23
|
from nat.data_models.front_end import FrontEndBaseConfig
|
|
22
24
|
|
|
25
|
+
logger = logging.getLogger(__name__)
|
|
26
|
+
|
|
23
27
|
|
|
24
28
|
class MCPFrontEndConfig(FrontEndBaseConfig, name="mcp"):
|
|
25
29
|
"""MCP front end configuration.
|
|
@@ -43,3 +47,31 @@ class MCPFrontEndConfig(FrontEndBaseConfig, name="mcp"):
|
|
|
43
47
|
|
|
44
48
|
server_auth: OAuth2ResourceServerConfig | None = Field(
|
|
45
49
|
default=None, description=("OAuth 2.0 Resource Server configuration for token verification."))
|
|
50
|
+
|
|
51
|
+
@model_validator(mode="after")
|
|
52
|
+
def validate_security_configuration(self):
|
|
53
|
+
"""Validate security configuration to prevent accidental misconfigurations."""
|
|
54
|
+
# Check if server is bound to a non-localhost interface without authentication
|
|
55
|
+
localhost_hosts = {"localhost", "127.0.0.1", "::1"}
|
|
56
|
+
if self.host not in localhost_hosts and self.server_auth is None:
|
|
57
|
+
logger.warning(
|
|
58
|
+
"MCP server is configured to bind to '%s' without authentication. "
|
|
59
|
+
"This may expose your server to unauthorized access. "
|
|
60
|
+
"Consider either: (1) binding to localhost for local-only access, "
|
|
61
|
+
"or (2) configuring server_auth for production deployments on public interfaces.",
|
|
62
|
+
self.host)
|
|
63
|
+
|
|
64
|
+
# Check if SSE transport is used (which doesn't support authentication)
|
|
65
|
+
if self.transport == "sse":
|
|
66
|
+
if self.server_auth is not None:
|
|
67
|
+
logger.warning("SSE transport does not support authentication. "
|
|
68
|
+
"The configured server_auth will be ignored. "
|
|
69
|
+
"For production use with authentication, use 'streamable-http' transport instead.")
|
|
70
|
+
elif self.host not in localhost_hosts:
|
|
71
|
+
logger.warning(
|
|
72
|
+
"SSE transport does not support authentication and is bound to '%s'. "
|
|
73
|
+
"This configuration is not recommended for production use. "
|
|
74
|
+
"For production deployments, use 'streamable-http' transport with server_auth configured.",
|
|
75
|
+
self.host)
|
|
76
|
+
|
|
77
|
+
return self
|
nat/runtime/runner.py
CHANGED
|
@@ -196,8 +196,7 @@ class Runner:
|
|
|
196
196
|
|
|
197
197
|
return result
|
|
198
198
|
except Exception as e:
|
|
199
|
-
|
|
200
|
-
logger.error("Error running workflow%s", err_msg)
|
|
199
|
+
logger.error("Error running workflow: %s", e)
|
|
201
200
|
event_stream = self._context_state.event_stream.get()
|
|
202
201
|
if event_stream:
|
|
203
202
|
event_stream.on_complete()
|
nat/utils/type_converter.py
CHANGED
|
@@ -93,6 +93,14 @@ class TypeConverter:
|
|
|
93
93
|
if to_type is None or decomposed.is_instance(data):
|
|
94
94
|
return data
|
|
95
95
|
|
|
96
|
+
# 2) If data is a union type, try to convert to each type in the union
|
|
97
|
+
if decomposed.is_union:
|
|
98
|
+
for union_type in decomposed.args:
|
|
99
|
+
result = self._convert(data, union_type)
|
|
100
|
+
if result is not None:
|
|
101
|
+
return result
|
|
102
|
+
return None
|
|
103
|
+
|
|
96
104
|
root = decomposed.root
|
|
97
105
|
|
|
98
106
|
# 2) Attempt direct in *this* converter
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: nvidia-nat
|
|
3
|
-
Version: 1.3.
|
|
3
|
+
Version: 1.3.0a20251012
|
|
4
4
|
Summary: NVIDIA NeMo Agent toolkit
|
|
5
5
|
Author: NVIDIA Corporation
|
|
6
6
|
Maintainer: NVIDIA Corporation
|
|
7
|
-
License
|
|
7
|
+
License: Apache-2.0
|
|
8
8
|
Project-URL: documentation, https://docs.nvidia.com/nemo/agent-toolkit/latest/
|
|
9
9
|
Project-URL: source, https://github.com/NVIDIA/NeMo-Agent-Toolkit
|
|
10
10
|
Keywords: ai,rag,agents
|
|
@@ -14,8 +14,8 @@ Classifier: Programming Language :: Python :: 3.12
|
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.13
|
|
15
15
|
Requires-Python: <3.14,>=3.11
|
|
16
16
|
Description-Content-Type: text/markdown
|
|
17
|
-
License-File: LICENSE.md
|
|
18
17
|
License-File: LICENSE-3rd-party.txt
|
|
18
|
+
License-File: LICENSE.md
|
|
19
19
|
Requires-Dist: aioboto3>=11.0.0
|
|
20
20
|
Requires-Dist: authlib~=1.5
|
|
21
21
|
Requires-Dist: click~=8.1
|
|
@@ -40,6 +40,7 @@ Requires-Dist: pkginfo~=1.12
|
|
|
40
40
|
Requires-Dist: platformdirs~=4.3
|
|
41
41
|
Requires-Dist: pydantic~=2.11
|
|
42
42
|
Requires-Dist: pymilvus~=2.4
|
|
43
|
+
Requires-Dist: python-dotenv~=1.1.1
|
|
43
44
|
Requires-Dist: PyYAML~=6.0
|
|
44
45
|
Requires-Dist: ragas~=0.2.14
|
|
45
46
|
Requires-Dist: rich~=13.9
|
|
@@ -10,16 +10,16 @@ nat/agent/react_agent/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3h
|
|
|
10
10
|
nat/agent/react_agent/agent.py,sha256=sWrg9WrglTKQQyG3EcjNm2JTEchCPEo9li-Po7TJKss,21294
|
|
11
11
|
nat/agent/react_agent/output_parser.py,sha256=m7K6wRwtckBBpAHqOf3BZ9mqZLwrP13Kxz5fvNxbyZE,4219
|
|
12
12
|
nat/agent/react_agent/prompt.py,sha256=N47JJrT6xwYQCv1jedHhlul2AE7EfKsSYfAbgJwWRew,1758
|
|
13
|
-
nat/agent/react_agent/register.py,sha256=
|
|
13
|
+
nat/agent/react_agent/register.py,sha256=qkPaK6AvXjolL-q_Z3waVobXDz24GMfuqGqCn-2un2Q,8991
|
|
14
14
|
nat/agent/reasoning_agent/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
15
|
nat/agent/reasoning_agent/reasoning_agent.py,sha256=k_0wEDqACQn1Rn1MAKxoXyqOKsthHCQ1gt990YYUqHU,9575
|
|
16
16
|
nat/agent/rewoo_agent/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
17
17
|
nat/agent/rewoo_agent/agent.py,sha256=XXgVXY9xwkyxnr093KXUtfgyNxAQbyGAecoGqN5mMLY,26199
|
|
18
18
|
nat/agent/rewoo_agent/prompt.py,sha256=B0JeL1xDX4VKcShlkkviEcAsOKAwzSlX8NcAQdmUUPw,3645
|
|
19
|
-
nat/agent/rewoo_agent/register.py,sha256=
|
|
19
|
+
nat/agent/rewoo_agent/register.py,sha256=XArlOR37QOBtAvsdKJUjRok5qTmx39S2mJHSteOwU58,9283
|
|
20
20
|
nat/agent/tool_calling_agent/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
21
21
|
nat/agent/tool_calling_agent/agent.py,sha256=4SIp29I56oznPRQu7B3HCoX53Ri3_o3BRRYNJjeBkF8,11006
|
|
22
|
-
nat/agent/tool_calling_agent/register.py,sha256=
|
|
22
|
+
nat/agent/tool_calling_agent/register.py,sha256=OucceyELA2xZL3KdANWK9w12fnVP75eVbZgzOnmXHys,7057
|
|
23
23
|
nat/authentication/__init__.py,sha256=Xs1JQ16L9btwreh4pdGKwskffAw1YFO48jKrU4ib_7c,685
|
|
24
24
|
nat/authentication/interfaces.py,sha256=1J2CWEJ_n6CLA3_HD3XV28CSbyfxrPAHzr7Q4kKDFdc,3511
|
|
25
25
|
nat/authentication/register.py,sha256=lFhswYUk9iZ53mq33fClR9UfjJPdjGIivGGNHQeWiYo,915
|
|
@@ -48,7 +48,7 @@ nat/builder/eval_builder.py,sha256=I-ScvupmorClYoVBIs_PhSsB7Xf9e2nGWe0rCZp3txo,6
|
|
|
48
48
|
nat/builder/evaluator.py,sha256=xWHMND2vcAUkdFP7FU3jnVki1rUHeTa0-9saFh2hWKs,1162
|
|
49
49
|
nat/builder/framework_enum.py,sha256=n7IaTQBxhFozIQqRMcX9kXntw28JhFzCj82jJ0C5tNU,901
|
|
50
50
|
nat/builder/front_end.py,sha256=FCJ87NSshVVuTg8zZrq3YAr_u0RaYVZVcibnqlRFy-M,2173
|
|
51
|
-
nat/builder/function.py,sha256=
|
|
51
|
+
nat/builder/function.py,sha256=eZZWLwhphgQTnPvbga8sGleX7HCP46usZPIegE7zFzs,27725
|
|
52
52
|
nat/builder/function_base.py,sha256=0Eg8RtjWhEU3Yme0CVxcRutobA0Qo8-YHZLI6L2qAgM,13116
|
|
53
53
|
nat/builder/function_info.py,sha256=7Rmrn-gOFrT2TIJklJwA_O-ycx_oimwZ0-qMYpbuZrU,25161
|
|
54
54
|
nat/builder/intermediate_step_manager.py,sha256=iOuMLWTaES0J0XzaLxhTUqFvuoCAChJu3V69T43K0k0,7599
|
|
@@ -58,7 +58,7 @@ nat/builder/user_interaction_manager.py,sha256=-Z2qbQes7a2cuXgT7KEbWeuok0HcCnRdw
|
|
|
58
58
|
nat/builder/workflow.py,sha256=bHrxK-VFsxUTw2wZgkWcCttpCMDeWNGPfmIGEW_bjZo,6908
|
|
59
59
|
nat/builder/workflow_builder.py,sha256=GgNkeBmG_q3YGnGliuzpYhkC869q_PdaP4RoqXH6HdI,58709
|
|
60
60
|
nat/cli/__init__.py,sha256=Xs1JQ16L9btwreh4pdGKwskffAw1YFO48jKrU4ib_7c,685
|
|
61
|
-
nat/cli/entrypoint.py,sha256=
|
|
61
|
+
nat/cli/entrypoint.py,sha256=vN9G8fe-7ITmsVciJU11Fk7JaSxFnN5A4FrD7WjYbxg,5105
|
|
62
62
|
nat/cli/main.py,sha256=LZMKvoHYR926mghMjVpfLiI2qraqtrhMY9hvuAQCRWk,2258
|
|
63
63
|
nat/cli/register_workflow.py,sha256=DOQQgUWB_NO9k7nlkP4cAx_RX03Cndk032K-kqyuvEs,23285
|
|
64
64
|
nat/cli/type_registry.py,sha256=HbPU-7lzSHZ4aepJ3qOgfnl5LzK6-KHwcerhFpWw6mU,48839
|
|
@@ -112,7 +112,7 @@ nat/control_flow/router_agent/prompt.py,sha256=fIAiNsAs1zXRAatButR76zSpHJNxSkXXK
|
|
|
112
112
|
nat/control_flow/router_agent/register.py,sha256=4RGmS9sy-QtIMmvh8mfMcR1VqxFPLpG4RckWCIExh40,4144
|
|
113
113
|
nat/data_models/__init__.py,sha256=Xs1JQ16L9btwreh4pdGKwskffAw1YFO48jKrU4ib_7c,685
|
|
114
114
|
nat/data_models/agent.py,sha256=IwDyb9Zc3R4Zd5rFeqt7q0EQswczAl5focxV9KozIzs,1625
|
|
115
|
-
nat/data_models/api_server.py,sha256=
|
|
115
|
+
nat/data_models/api_server.py,sha256=NWT1ChN2qaakD2DgyYCy_7MhfzvEBQX15qnUXnpCQmk,28883
|
|
116
116
|
nat/data_models/authentication.py,sha256=XPu9W8nh4XRSuxPv3HxO-FMQ_JtTEoK6Y02JwnzDwTg,8457
|
|
117
117
|
nat/data_models/common.py,sha256=nXXfGrjpxebzBUa55mLdmzePLt7VFHvTAc6Znj3yEv0,5875
|
|
118
118
|
nat/data_models/component.py,sha256=b_hXOA8Gm5UNvlFkAhsR6kEvf33ST50MKtr5kWf75Ao,1894
|
|
@@ -259,7 +259,7 @@ nat/front_ends/fastapi/html_snippets/__init__.py,sha256=GUJrgGtpvyMUCjUBvR3faAdv
|
|
|
259
259
|
nat/front_ends/fastapi/html_snippets/auth_code_grant_success.py,sha256=BNpWwzmA58UM0GK4kZXG4PHJy_5K9ihaVHu8SgCs5JA,1131
|
|
260
260
|
nat/front_ends/mcp/__init__.py,sha256=Xs1JQ16L9btwreh4pdGKwskffAw1YFO48jKrU4ib_7c,685
|
|
261
261
|
nat/front_ends/mcp/introspection_token_verifier.py,sha256=s7Q4Q6rWZJ0ZVujSxxpvVI6Bnhkg1LJQ3RLkvhzFIGE,2836
|
|
262
|
-
nat/front_ends/mcp/mcp_front_end_config.py,sha256=
|
|
262
|
+
nat/front_ends/mcp/mcp_front_end_config.py,sha256=m6z5qSz8YGnFnfu8hRID69suvO1YT_L6sxy1Ki64Ufw,4042
|
|
263
263
|
nat/front_ends/mcp/mcp_front_end_plugin.py,sha256=NiIIgApk1X2yAEwtG9tHaY6SexQMbZrd6Drs7uIJix8,5055
|
|
264
264
|
nat/front_ends/mcp/mcp_front_end_plugin_worker.py,sha256=jMclC0qEd910oTGCqd1kQ8WjP3WPdQKTl854-2bU_KI,10200
|
|
265
265
|
nat/front_ends/mcp/register.py,sha256=3aJtgG5VaiqujoeU1-Eq7Hl5pWslIlIwGFU2ASLTXgM,1173
|
|
@@ -406,7 +406,7 @@ nat/retriever/nemo_retriever/register.py,sha256=3XdrvEJzX2Zc8wpdm__4YYlEWBW-FK3t
|
|
|
406
406
|
nat/retriever/nemo_retriever/retriever.py,sha256=gi3_qJFqE-iqRh3of_cmJg-SwzaQ3z24zA9LwY_MSLY,6930
|
|
407
407
|
nat/runtime/__init__.py,sha256=Xs1JQ16L9btwreh4pdGKwskffAw1YFO48jKrU4ib_7c,685
|
|
408
408
|
nat/runtime/loader.py,sha256=obUdAgZVYCPGC0R8u3wcoKFJzzSPQgJvrbU4OWygtog,7953
|
|
409
|
-
nat/runtime/runner.py,sha256=
|
|
409
|
+
nat/runtime/runner.py,sha256=qa_AqtmB8TUHX6nVJ0TLEYCKUsm2L99kq5O72AuL3yc,11736
|
|
410
410
|
nat/runtime/session.py,sha256=E8RTbnAhPbY5KCoSfiHzOJksmBh7xWjsoX0BC7Rn1ck,9101
|
|
411
411
|
nat/runtime/user_metadata.py,sha256=ce37NRYJWnMOWk6A7VAQ1GQztjMmkhMOq-uYf2gNCwo,3692
|
|
412
412
|
nat/settings/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -448,7 +448,7 @@ nat/utils/metadata_utils.py,sha256=BSsiB6jIWd8oEuEynJi55qCG762UuTYFaiUH0OT9HdY,2
|
|
|
448
448
|
nat/utils/optional_imports.py,sha256=jQSVBc2fBSRw-2d6r8cEwvh5-di2EUUPakuuo9QbbwA,4039
|
|
449
449
|
nat/utils/producer_consumer_queue.py,sha256=AcSYkAMBxLx06A5Xdy960PP3AJ7YaSPGJ7rbN_hJsjI,6599
|
|
450
450
|
nat/utils/string_utils.py,sha256=71HuIzGx7rF8ocTmeoUBpnCi1Qf1yynYlNLLIKP4BVs,1415
|
|
451
|
-
nat/utils/type_converter.py,sha256
|
|
451
|
+
nat/utils/type_converter.py,sha256=vDZzrZ9ycWgZJdkWB1sHB2ivZX-E8fPfkrB-vAAxroI,10968
|
|
452
452
|
nat/utils/type_utils.py,sha256=SMo5hM4dKf2G3U_0J0wvdFX6-lzMVSh8vd-W34Oixow,14836
|
|
453
453
|
nat/utils/url_utils.py,sha256=UzDP_xaS6brWTu7vAws0B4jZyrITIK9Si3U6pZBZqDE,1028
|
|
454
454
|
nat/utils/data_models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -470,10 +470,10 @@ nat/utils/reactive/base/observer_base.py,sha256=6BiQfx26EMumotJ3KoVcdmFBYR_fnAss
|
|
|
470
470
|
nat/utils/reactive/base/subject_base.py,sha256=UQOxlkZTIeeyYmG5qLtDpNf_63Y7p-doEeUA08_R8ME,2521
|
|
471
471
|
nat/utils/settings/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
472
472
|
nat/utils/settings/global_settings.py,sha256=9JaO6pxKT_Pjw6rxJRsRlFCXdVKCl_xUKU2QHZQWWNM,7294
|
|
473
|
-
nvidia_nat-1.3.
|
|
474
|
-
nvidia_nat-1.3.
|
|
475
|
-
nvidia_nat-1.3.
|
|
476
|
-
nvidia_nat-1.3.
|
|
477
|
-
nvidia_nat-1.3.
|
|
478
|
-
nvidia_nat-1.3.
|
|
479
|
-
nvidia_nat-1.3.
|
|
473
|
+
nvidia_nat-1.3.0a20251012.dist-info/licenses/LICENSE-3rd-party.txt,sha256=fOk5jMmCX9YoKWyYzTtfgl-SUy477audFC5hNY4oP7Q,284609
|
|
474
|
+
nvidia_nat-1.3.0a20251012.dist-info/licenses/LICENSE.md,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
|
|
475
|
+
nvidia_nat-1.3.0a20251012.dist-info/METADATA,sha256=0lluHjvpalyT5y2KRVPW93RUp1APbdwJQ8kazjllphs,10228
|
|
476
|
+
nvidia_nat-1.3.0a20251012.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
477
|
+
nvidia_nat-1.3.0a20251012.dist-info/entry_points.txt,sha256=4jCqjyETMpyoWbCBf4GalZU8I_wbstpzwQNezdAVbbo,698
|
|
478
|
+
nvidia_nat-1.3.0a20251012.dist-info/top_level.txt,sha256=lgJWLkigiVZuZ_O1nxVnD_ziYBwgpE2OStdaCduMEGc,8
|
|
479
|
+
nvidia_nat-1.3.0a20251012.dist-info/RECORD,,
|
|
File without changes
|
{nvidia_nat-1.3.0a20251008.dist-info → nvidia_nat-1.3.0a20251012.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
|
File without changes
|
{nvidia_nat-1.3.0a20251008.dist-info → nvidia_nat-1.3.0a20251012.dist-info}/licenses/LICENSE.md
RENAMED
|
File without changes
|
|
File without changes
|