nvidia-nat 1.3.0a20250909__py3-none-any.whl → 1.3.0a20250917__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.
Files changed (103) hide show
  1. nat/agent/base.py +11 -6
  2. nat/agent/dual_node.py +2 -2
  3. nat/agent/prompt_optimizer/prompt.py +68 -0
  4. nat/agent/prompt_optimizer/register.py +149 -0
  5. nat/agent/react_agent/agent.py +1 -1
  6. nat/agent/react_agent/register.py +17 -7
  7. nat/agent/reasoning_agent/reasoning_agent.py +6 -1
  8. nat/agent/register.py +2 -0
  9. nat/agent/rewoo_agent/agent.py +6 -3
  10. nat/agent/rewoo_agent/register.py +16 -10
  11. nat/agent/router_agent/__init__.py +0 -0
  12. nat/agent/router_agent/agent.py +329 -0
  13. nat/agent/router_agent/prompt.py +48 -0
  14. nat/agent/router_agent/register.py +97 -0
  15. nat/agent/tool_calling_agent/agent.py +69 -7
  16. nat/agent/tool_calling_agent/register.py +17 -9
  17. nat/builder/builder.py +27 -4
  18. nat/builder/component_utils.py +7 -3
  19. nat/builder/function.py +167 -0
  20. nat/builder/function_info.py +1 -1
  21. nat/builder/workflow.py +5 -0
  22. nat/builder/workflow_builder.py +213 -16
  23. nat/cli/commands/optimize.py +90 -0
  24. nat/cli/commands/workflow/templates/config.yml.j2 +0 -1
  25. nat/cli/commands/workflow/workflow_commands.py +5 -8
  26. nat/cli/entrypoint.py +2 -0
  27. nat/cli/register_workflow.py +38 -4
  28. nat/cli/type_registry.py +71 -0
  29. nat/data_models/api_server.py +1 -1
  30. nat/data_models/component.py +2 -0
  31. nat/data_models/component_ref.py +11 -0
  32. nat/data_models/config.py +40 -16
  33. nat/data_models/function.py +34 -0
  34. nat/data_models/function_dependencies.py +8 -0
  35. nat/data_models/optimizable.py +119 -0
  36. nat/data_models/optimizer.py +149 -0
  37. nat/data_models/temperature_mixin.py +4 -3
  38. nat/data_models/top_p_mixin.py +4 -3
  39. nat/embedder/nim_embedder.py +1 -1
  40. nat/embedder/openai_embedder.py +1 -1
  41. nat/eval/config.py +1 -1
  42. nat/eval/evaluate.py +5 -1
  43. nat/eval/register.py +4 -0
  44. nat/eval/runtime_evaluator/__init__.py +14 -0
  45. nat/eval/runtime_evaluator/evaluate.py +123 -0
  46. nat/eval/runtime_evaluator/register.py +100 -0
  47. nat/experimental/test_time_compute/functions/plan_select_execute_function.py +5 -1
  48. nat/front_ends/fastapi/dask_client_mixin.py +43 -0
  49. nat/front_ends/fastapi/fastapi_front_end_config.py +14 -3
  50. nat/front_ends/fastapi/fastapi_front_end_plugin.py +111 -3
  51. nat/front_ends/fastapi/fastapi_front_end_plugin_worker.py +243 -228
  52. nat/front_ends/fastapi/job_store.py +518 -99
  53. nat/front_ends/fastapi/main.py +11 -19
  54. nat/front_ends/fastapi/utils.py +57 -0
  55. nat/front_ends/mcp/mcp_front_end_plugin_worker.py +3 -2
  56. nat/llm/aws_bedrock_llm.py +15 -4
  57. nat/llm/nim_llm.py +14 -3
  58. nat/llm/openai_llm.py +8 -1
  59. nat/observability/exporter/processing_exporter.py +29 -55
  60. nat/observability/mixin/redaction_config_mixin.py +5 -4
  61. nat/observability/mixin/tagging_config_mixin.py +26 -14
  62. nat/observability/mixin/type_introspection_mixin.py +401 -107
  63. nat/observability/processor/processor.py +3 -0
  64. nat/observability/processor/redaction/__init__.py +24 -0
  65. nat/observability/processor/redaction/contextual_redaction_processor.py +125 -0
  66. nat/observability/processor/redaction/contextual_span_redaction_processor.py +66 -0
  67. nat/observability/processor/redaction/redaction_processor.py +177 -0
  68. nat/observability/processor/redaction/span_header_redaction_processor.py +92 -0
  69. nat/observability/processor/span_tagging_processor.py +21 -14
  70. nat/profiler/decorators/framework_wrapper.py +9 -6
  71. nat/profiler/parameter_optimization/__init__.py +0 -0
  72. nat/profiler/parameter_optimization/optimizable_utils.py +93 -0
  73. nat/profiler/parameter_optimization/optimizer_runtime.py +67 -0
  74. nat/profiler/parameter_optimization/parameter_optimizer.py +149 -0
  75. nat/profiler/parameter_optimization/parameter_selection.py +108 -0
  76. nat/profiler/parameter_optimization/pareto_visualizer.py +380 -0
  77. nat/profiler/parameter_optimization/prompt_optimizer.py +384 -0
  78. nat/profiler/parameter_optimization/update_helpers.py +66 -0
  79. nat/profiler/utils.py +3 -1
  80. nat/tool/chat_completion.py +5 -2
  81. nat/tool/document_search.py +1 -1
  82. nat/tool/github_tools.py +450 -0
  83. nat/tool/register.py +2 -7
  84. nat/utils/callable_utils.py +70 -0
  85. nat/utils/exception_handlers/automatic_retries.py +103 -48
  86. nat/utils/type_utils.py +4 -0
  87. {nvidia_nat-1.3.0a20250909.dist-info → nvidia_nat-1.3.0a20250917.dist-info}/METADATA +8 -1
  88. {nvidia_nat-1.3.0a20250909.dist-info → nvidia_nat-1.3.0a20250917.dist-info}/RECORD +94 -74
  89. nat/observability/processor/header_redaction_processor.py +0 -123
  90. nat/observability/processor/redaction_processor.py +0 -77
  91. nat/tool/github_tools/create_github_commit.py +0 -133
  92. nat/tool/github_tools/create_github_issue.py +0 -87
  93. nat/tool/github_tools/create_github_pr.py +0 -106
  94. nat/tool/github_tools/get_github_file.py +0 -106
  95. nat/tool/github_tools/get_github_issue.py +0 -166
  96. nat/tool/github_tools/get_github_pr.py +0 -256
  97. nat/tool/github_tools/update_github_issue.py +0 -100
  98. /nat/{tool/github_tools → agent/prompt_optimizer}/__init__.py +0 -0
  99. {nvidia_nat-1.3.0a20250909.dist-info → nvidia_nat-1.3.0a20250917.dist-info}/WHEEL +0 -0
  100. {nvidia_nat-1.3.0a20250909.dist-info → nvidia_nat-1.3.0a20250917.dist-info}/entry_points.txt +0 -0
  101. {nvidia_nat-1.3.0a20250909.dist-info → nvidia_nat-1.3.0a20250917.dist-info}/licenses/LICENSE-3rd-party.txt +0 -0
  102. {nvidia_nat-1.3.0a20250909.dist-info → nvidia_nat-1.3.0a20250917.dist-info}/licenses/LICENSE.md +0 -0
  103. {nvidia_nat-1.3.0a20250909.dist-info → nvidia_nat-1.3.0a20250917.dist-info}/top_level.txt +0 -0
@@ -13,21 +13,36 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
+ import asyncio
16
17
  import logging
17
18
  import os
19
+ import sys
18
20
  import tempfile
19
21
  import typing
20
22
 
21
23
  from nat.builder.front_end import FrontEndBase
24
+ from nat.front_ends.fastapi.dask_client_mixin import DaskClientMixin
22
25
  from nat.front_ends.fastapi.fastapi_front_end_config import FastApiFrontEndConfig
23
26
  from nat.front_ends.fastapi.fastapi_front_end_plugin_worker import FastApiFrontEndPluginWorkerBase
24
27
  from nat.front_ends.fastapi.main import get_app
28
+ from nat.front_ends.fastapi.utils import get_class_name
25
29
  from nat.utils.io.yaml_tools import yaml_dump
26
30
 
31
+ if (typing.TYPE_CHECKING):
32
+ from nat.data_models.config import Config
33
+
27
34
  logger = logging.getLogger(__name__)
28
35
 
29
36
 
30
- class FastApiFrontEndPlugin(FrontEndBase[FastApiFrontEndConfig]):
37
+ class FastApiFrontEndPlugin(DaskClientMixin, FrontEndBase[FastApiFrontEndConfig]):
38
+
39
+ def __init__(self, full_config: "Config"):
40
+ super().__init__(full_config)
41
+
42
+ # This attribute is set if dask is installed, and an external cluster is not used (scheduler_address is None)
43
+ self._cluster = None
44
+ self._periodic_cleanup_future = None
45
+ self._scheduler_address = None
31
46
 
32
47
  def get_worker_class(self) -> type[FastApiFrontEndPluginWorkerBase]:
33
48
  from nat.front_ends.fastapi.fastapi_front_end_plugin_worker import FastApiFrontEndPluginWorker
@@ -42,7 +57,38 @@ class FastApiFrontEndPlugin(FrontEndBase[FastApiFrontEndConfig]):
42
57
 
43
58
  worker_class = self.get_worker_class()
44
59
 
45
- return f"{worker_class.__module__}.{worker_class.__qualname__}"
60
+ return get_class_name(worker_class)
61
+
62
+ @staticmethod
63
+ async def _periodic_cleanup(scheduler_address: str,
64
+ db_url: str,
65
+ sleep_time_sec: int = 300,
66
+ log_level: int = logging.INFO):
67
+ from nat.front_ends.fastapi.job_store import JobStore
68
+
69
+ job_store = JobStore(scheduler_address=scheduler_address, db_url=db_url)
70
+
71
+ logging.basicConfig(level=log_level)
72
+ logger.info("Starting periodic cleanup of expired jobs every %d seconds", sleep_time_sec)
73
+ while True:
74
+ await asyncio.sleep(sleep_time_sec)
75
+
76
+ try:
77
+ await job_store.cleanup_expired_jobs()
78
+ logger.debug("Expired jobs cleaned up")
79
+ except: # noqa: E722
80
+ logger.exception("Error during job cleanup")
81
+
82
+ async def _submit_cleanup_task(self, scheduler_address: str, db_url: str):
83
+ """Submit a cleanup task to the cluster to remove the job after expiry."""
84
+ logger.info("Submitting periodic cleanup task to Dask cluster at %s", scheduler_address)
85
+ async with self.client(self._scheduler_address) as client:
86
+ self._periodic_cleanup_future = client.submit(self._periodic_cleanup,
87
+ scheduler_address=self._scheduler_address,
88
+ db_url=db_url,
89
+ log_level=logger.getEffectiveLevel())
90
+
91
+ logger.info("Submitted periodic cleanup task to Dask cluster at %s", scheduler_address)
46
92
 
47
93
  async def run(self):
48
94
 
@@ -52,6 +98,45 @@ class FastApiFrontEndPlugin(FrontEndBase[FastApiFrontEndConfig]):
52
98
  # Get as dict
53
99
  config_dict = self.full_config.model_dump(mode="json", by_alias=True, round_trip=True)
54
100
 
101
+ # Three possible cases:
102
+ # 1. Dask is installed and scheduler_address is None, we create a LocalCluster
103
+ # 2. Dask is installed and scheduler_address is set, we use the existing cluster
104
+ # 3. Dask is not installed, we skip the cluster setup
105
+ self._scheduler_address = self.front_end_config.scheduler_address
106
+ if self._scheduler_address is None:
107
+ try:
108
+ from dask.distributed import LocalCluster
109
+
110
+ self._cluster = LocalCluster(n_workers=self.front_end_config.max_running_async_jobs,
111
+ threads_per_worker=1)
112
+
113
+ self._scheduler_address = self._cluster.scheduler.address
114
+ logger.info("Created local Dask cluster with scheduler at %s", self._scheduler_address)
115
+
116
+ except ImportError:
117
+ logger.warning("Dask is not installed, async execution and evaluation will not be available.")
118
+
119
+ if self._scheduler_address is not None:
120
+ # If we are here then either the user provided a scheduler address, or we created a LocalCluster
121
+
122
+ from nat.front_ends.fastapi.job_store import Base
123
+ from nat.front_ends.fastapi.job_store import get_db_engine
124
+
125
+ db_engine = get_db_engine(self.front_end_config.db_url, use_async=True)
126
+ async with db_engine.begin() as conn:
127
+ await conn.run_sync(Base.metadata.create_all, checkfirst=True) # create tables if they do not exist
128
+
129
+ # If self.front_end_config.db_url is None, then we need to get the actual url from the engine
130
+ db_url = str(db_engine.url)
131
+ await self._submit_cleanup_task(scheduler_address=self._scheduler_address, db_url=db_url)
132
+
133
+ # Set environment variabls such that the worker subprocesses will know how to connect to dask and to
134
+ # the database
135
+ os.environ.update({
136
+ "NAT_DASK_SCHEDULER_ADDRESS": self._scheduler_address,
137
+ "NAT_JOB_STORE_DB_URL": db_url,
138
+ })
139
+
55
140
  # Write to YAML file
56
141
  yaml_dump(config_dict, config_file)
57
142
 
@@ -70,13 +155,25 @@ class FastApiFrontEndPlugin(FrontEndBase[FastApiFrontEndConfig]):
70
155
 
71
156
  reload_excludes = ["./.*"]
72
157
 
158
+ # By default, Uvicorn uses "auto" event loop policy, which prefers `uvloop` if installed. However,
159
+ # uvloop’s event loop policy for macOS doesn’t provide a child watcher (which is needed for MCP server),
160
+ # so setting loop="asyncio" forces Uvicorn to use the standard event loop, which includes child-watcher
161
+ # support.
162
+ if sys.platform == "darwin" or sys.platform.startswith("linux"):
163
+ # For macOS
164
+ event_loop_policy = "asyncio"
165
+ else:
166
+ # For non-macOS platforms
167
+ event_loop_policy = "auto"
168
+
73
169
  uvicorn.run("nat.front_ends.fastapi.main:get_app",
74
170
  host=self.front_end_config.host,
75
171
  port=self.front_end_config.port,
76
172
  workers=self.front_end_config.workers,
77
173
  reload=self.front_end_config.reload,
78
174
  factory=True,
79
- reload_excludes=reload_excludes)
175
+ reload_excludes=reload_excludes,
176
+ loop=event_loop_policy)
80
177
 
81
178
  else:
82
179
  app = get_app()
@@ -110,6 +207,17 @@ class FastApiFrontEndPlugin(FrontEndBase[FastApiFrontEndConfig]):
110
207
  StandaloneApplication(app, options=options).run()
111
208
 
112
209
  finally:
210
+ logger.debug("Shutting down")
211
+ if self._periodic_cleanup_future is not None:
212
+ logger.info("Cancelling periodic cleanup task.")
213
+ # Use the scheduler address, because self._cluster is None if an external cluster is used
214
+ async with self.client(self._scheduler_address) as client:
215
+ await client.cancel([self._periodic_cleanup_future], asynchronous=True, force=True)
216
+
217
+ if self._cluster is not None:
218
+ # Only shut down the cluster if we created it
219
+ logger.info("Closing Local Dask cluster.")
220
+ self._cluster.close()
113
221
  try:
114
222
  os.remove(config_file_name)
115
223
  except OSError as e: