nvidia-nat 1.3.0a20250910__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 (100) hide show
  1. nat/agent/base.py +9 -4
  2. nat/agent/prompt_optimizer/prompt.py +68 -0
  3. nat/agent/prompt_optimizer/register.py +149 -0
  4. nat/agent/react_agent/agent.py +1 -1
  5. nat/agent/react_agent/register.py +15 -5
  6. nat/agent/reasoning_agent/reasoning_agent.py +6 -1
  7. nat/agent/register.py +2 -0
  8. nat/agent/rewoo_agent/agent.py +4 -2
  9. nat/agent/rewoo_agent/register.py +8 -3
  10. nat/agent/router_agent/__init__.py +0 -0
  11. nat/agent/router_agent/agent.py +329 -0
  12. nat/agent/router_agent/prompt.py +48 -0
  13. nat/agent/router_agent/register.py +97 -0
  14. nat/agent/tool_calling_agent/agent.py +69 -7
  15. nat/agent/tool_calling_agent/register.py +11 -3
  16. nat/builder/builder.py +27 -4
  17. nat/builder/component_utils.py +7 -3
  18. nat/builder/function.py +167 -0
  19. nat/builder/function_info.py +1 -1
  20. nat/builder/workflow.py +5 -0
  21. nat/builder/workflow_builder.py +213 -16
  22. nat/cli/commands/optimize.py +90 -0
  23. nat/cli/commands/workflow/templates/config.yml.j2 +0 -1
  24. nat/cli/commands/workflow/workflow_commands.py +4 -7
  25. nat/cli/entrypoint.py +2 -0
  26. nat/cli/register_workflow.py +38 -4
  27. nat/cli/type_registry.py +71 -0
  28. nat/data_models/component.py +2 -0
  29. nat/data_models/component_ref.py +11 -0
  30. nat/data_models/config.py +40 -16
  31. nat/data_models/function.py +34 -0
  32. nat/data_models/function_dependencies.py +8 -0
  33. nat/data_models/optimizable.py +119 -0
  34. nat/data_models/optimizer.py +149 -0
  35. nat/data_models/temperature_mixin.py +4 -3
  36. nat/data_models/top_p_mixin.py +4 -3
  37. nat/embedder/nim_embedder.py +1 -1
  38. nat/embedder/openai_embedder.py +1 -1
  39. nat/eval/config.py +1 -1
  40. nat/eval/evaluate.py +5 -1
  41. nat/eval/register.py +4 -0
  42. nat/eval/runtime_evaluator/__init__.py +14 -0
  43. nat/eval/runtime_evaluator/evaluate.py +123 -0
  44. nat/eval/runtime_evaluator/register.py +100 -0
  45. nat/experimental/test_time_compute/functions/plan_select_execute_function.py +5 -1
  46. nat/front_ends/fastapi/dask_client_mixin.py +43 -0
  47. nat/front_ends/fastapi/fastapi_front_end_config.py +14 -3
  48. nat/front_ends/fastapi/fastapi_front_end_plugin.py +111 -3
  49. nat/front_ends/fastapi/fastapi_front_end_plugin_worker.py +243 -228
  50. nat/front_ends/fastapi/job_store.py +518 -99
  51. nat/front_ends/fastapi/main.py +11 -19
  52. nat/front_ends/fastapi/utils.py +57 -0
  53. nat/front_ends/mcp/mcp_front_end_plugin_worker.py +3 -2
  54. nat/llm/aws_bedrock_llm.py +14 -3
  55. nat/llm/nim_llm.py +14 -3
  56. nat/llm/openai_llm.py +8 -1
  57. nat/observability/exporter/processing_exporter.py +29 -55
  58. nat/observability/mixin/redaction_config_mixin.py +5 -4
  59. nat/observability/mixin/tagging_config_mixin.py +26 -14
  60. nat/observability/mixin/type_introspection_mixin.py +401 -107
  61. nat/observability/processor/processor.py +3 -0
  62. nat/observability/processor/redaction/__init__.py +24 -0
  63. nat/observability/processor/redaction/contextual_redaction_processor.py +125 -0
  64. nat/observability/processor/redaction/contextual_span_redaction_processor.py +66 -0
  65. nat/observability/processor/redaction/redaction_processor.py +177 -0
  66. nat/observability/processor/redaction/span_header_redaction_processor.py +92 -0
  67. nat/observability/processor/span_tagging_processor.py +21 -14
  68. nat/profiler/decorators/framework_wrapper.py +9 -6
  69. nat/profiler/parameter_optimization/__init__.py +0 -0
  70. nat/profiler/parameter_optimization/optimizable_utils.py +93 -0
  71. nat/profiler/parameter_optimization/optimizer_runtime.py +67 -0
  72. nat/profiler/parameter_optimization/parameter_optimizer.py +149 -0
  73. nat/profiler/parameter_optimization/parameter_selection.py +108 -0
  74. nat/profiler/parameter_optimization/pareto_visualizer.py +380 -0
  75. nat/profiler/parameter_optimization/prompt_optimizer.py +384 -0
  76. nat/profiler/parameter_optimization/update_helpers.py +66 -0
  77. nat/profiler/utils.py +3 -1
  78. nat/tool/chat_completion.py +4 -1
  79. nat/tool/github_tools.py +450 -0
  80. nat/tool/register.py +2 -7
  81. nat/utils/callable_utils.py +70 -0
  82. nat/utils/exception_handlers/automatic_retries.py +103 -48
  83. nat/utils/type_utils.py +4 -0
  84. {nvidia_nat-1.3.0a20250910.dist-info → nvidia_nat-1.3.0a20250917.dist-info}/METADATA +8 -1
  85. {nvidia_nat-1.3.0a20250910.dist-info → nvidia_nat-1.3.0a20250917.dist-info}/RECORD +91 -71
  86. nat/observability/processor/header_redaction_processor.py +0 -123
  87. nat/observability/processor/redaction_processor.py +0 -77
  88. nat/tool/github_tools/create_github_commit.py +0 -133
  89. nat/tool/github_tools/create_github_issue.py +0 -87
  90. nat/tool/github_tools/create_github_pr.py +0 -106
  91. nat/tool/github_tools/get_github_file.py +0 -106
  92. nat/tool/github_tools/get_github_issue.py +0 -166
  93. nat/tool/github_tools/get_github_pr.py +0 -256
  94. nat/tool/github_tools/update_github_issue.py +0 -100
  95. /nat/{tool/github_tools → agent/prompt_optimizer}/__init__.py +0 -0
  96. {nvidia_nat-1.3.0a20250910.dist-info → nvidia_nat-1.3.0a20250917.dist-info}/WHEEL +0 -0
  97. {nvidia_nat-1.3.0a20250910.dist-info → nvidia_nat-1.3.0a20250917.dist-info}/entry_points.txt +0 -0
  98. {nvidia_nat-1.3.0a20250910.dist-info → nvidia_nat-1.3.0a20250917.dist-info}/licenses/LICENSE-3rd-party.txt +0 -0
  99. {nvidia_nat-1.3.0a20250910.dist-info → nvidia_nat-1.3.0a20250917.dist-info}/licenses/LICENSE.md +0 -0
  100. {nvidia_nat-1.3.0a20250910.dist-info → nvidia_nat-1.3.0a20250917.dist-info}/top_level.txt +0 -0
nat/agent/base.py CHANGED
@@ -27,6 +27,7 @@ from langchain_core.language_models import BaseChatModel
27
27
  from langchain_core.messages import AIMessage
28
28
  from langchain_core.messages import BaseMessage
29
29
  from langchain_core.messages import ToolMessage
30
+ from langchain_core.runnables import Runnable
30
31
  from langchain_core.runnables import RunnableConfig
31
32
  from langchain_core.tools import BaseTool
32
33
  from langgraph.graph.state import CompiledStateGraph
@@ -107,21 +108,25 @@ class BaseAgent(ABC):
107
108
 
108
109
  return AIMessage(content=output_message)
109
110
 
110
- async def _call_llm(self, messages: list[BaseMessage]) -> AIMessage:
111
+ async def _call_llm(self, llm: Runnable, inputs: dict[str, Any], config: RunnableConfig | None = None) -> AIMessage:
111
112
  """
112
113
  Call the LLM directly. Retry logic is handled automatically by the underlying LLM client.
113
114
 
114
115
  Parameters
115
116
  ----------
116
- messages : list[BaseMessage]
117
- The messages to send to the LLM
117
+ llm : Runnable
118
+ The LLM runnable (prompt | llm or similar)
119
+ inputs : dict[str, Any]
120
+ The inputs to pass to the runnable
121
+ config : RunnableConfig | None
122
+ The config to pass to the runnable (should include callbacks)
118
123
 
119
124
  Returns
120
125
  -------
121
126
  AIMessage
122
127
  The LLM response
123
128
  """
124
- response = await self.llm.ainvoke(messages)
129
+ response = await llm.ainvoke(inputs, config=config)
125
130
  return AIMessage(content=str(response.content))
126
131
 
127
132
  async def _call_tool(self,
@@ -0,0 +1,68 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ # flake8: noqa W291
16
+
17
+ mutator_prompt = """
18
+
19
+ ## CORE DIRECTIVES
20
+ - **Preserve the original objective and task.** Do not change what the prompt is meant to accomplish.
21
+ - **Keep the intent intact.** The improved prompt must solve the same problem as the original.
22
+ - **Do not invent new goals.** Only improve clarity, structure, constraints, and usability.
23
+ - **Do not drop critical instructions.** Everything essential from the original prompt must remain.
24
+ - **Return only the mutated prompt text.** No rationale, no diffs, no explanations.
25
+ - **Be Creative within bounds.** You may rephrase, reorganize, and enhance, but not alter meaning.
26
+ - **DO NOT use curly braces in your prompt** for anything other than existing variables in the prompt as the string
27
+ will be treated as an f-string.
28
+ - **Examples are a good idea** if the original prompt lacks them. They help clarify expected output.
29
+
30
+ ---
31
+
32
+ ## IMPROVEMENT HINTS
33
+ When modifying, apply these principles:
34
+ 1. **Clarity & Precision** – remove vague language, strengthen directives.
35
+ 2. **Structure & Flow** – order sections as: *Objective → Constraints → Tools → Steps → Output Schema → Examples*.
36
+ 3. **Schema Adherence** – enforce a single canonical output schema (JSON/XML) with `schema_version`.
37
+ 4. **Tool Governance** – clarify when/how tools are used, their inputs/outputs, and fallback behavior.
38
+ 5. **Error Handling** – specify behavior if tools fail or inputs are insufficient.
39
+ 6. **Budget Awareness** – minimize verbosity, respect token/latency limits.
40
+ 7. **Safety** – include refusals for unsafe requests, enforce compliance with rules.
41
+ 8. **Consistency** – avoid format drift; always maintain the same schema.
42
+ 9. **Integrity** – confirm the task, objective, and intent are preserved.
43
+
44
+ ---
45
+
46
+ ## MUTATION OPERATORS
47
+ You may:
48
+ - **Tighten** (remove fluff, redundancies)
49
+ - **Reorder** (improve logical flow)
50
+ - **Constrain** (add explicit rules/limits)
51
+ - **Harden** (improve error handling/fallbacks)
52
+ - **Defuse** (replace ambiguous verbs with measurable actions)
53
+ - **Format-lock** (wrap outputs in JSON/XML fenced blocks)
54
+ - **Example-ify** (add examples if missing or weak)
55
+
56
+ ---
57
+
58
+ ## INPUT
59
+ Here is the prompt to mutate:
60
+ {original_prompt}
61
+
62
+ ## OBJECTIVE
63
+ The prompt must acheive the following objective:
64
+ {objective}
65
+
66
+ The modified prompt is: \n
67
+
68
+ """
@@ -0,0 +1,149 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2021-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ from pydantic import Field
17
+
18
+ from nat.builder.builder import Builder
19
+ from nat.builder.framework_enum import LLMFrameworkEnum
20
+ from nat.builder.function_info import FunctionInfo
21
+ from nat.cli.register_workflow import register_function
22
+ from nat.data_models.component_ref import LLMRef
23
+ from nat.data_models.function import FunctionBaseConfig
24
+ from nat.profiler.parameter_optimization.prompt_optimizer import PromptOptimizerInputSchema
25
+
26
+
27
+ class PromptOptimizerConfig(FunctionBaseConfig, name="prompt_init"):
28
+
29
+ optimizer_llm: LLMRef = Field(description="LLM to use for prompt optimization")
30
+ optimizer_prompt: str = Field(
31
+ description="Prompt template for the optimizer",
32
+ default=(
33
+ "You are an expert at optimizing prompts for LLMs. "
34
+ "Your task is to take a given prompt and suggest an optimized version of it. "
35
+ "Note that the prompt might be a template with variables and curly braces. Remember to always keep the "
36
+ "variables and curly braces in the prompt the same. Only modify the instructions in the prompt that are"
37
+ "not variables. The system is meant to achieve the following objective\n"
38
+ "{system_objective}\n Of which, the prompt is one part. The details of the prompt and context as below.\n"))
39
+ system_objective: str = Field(description="Objective of the workflow")
40
+
41
+
42
+ @register_function(config_type=PromptOptimizerConfig, framework_wrappers=[LLMFrameworkEnum.LANGCHAIN])
43
+ async def prompt_optimizer_function(config: PromptOptimizerConfig, builder: Builder):
44
+ """
45
+ Function to optimize prompts for LLMs.
46
+ """
47
+
48
+ try:
49
+ from langchain_core.prompts import PromptTemplate
50
+
51
+ from .prompt import mutator_prompt
52
+ except ImportError as exc:
53
+ raise ImportError("langchain-core is not installed. Please install it to use MultiLLMPlanner.\n"
54
+ "This error can be resolve by installing nvidia-nat[langchain]") from exc
55
+
56
+ llm = await builder.get_llm(config.optimizer_llm, wrapper_type=LLMFrameworkEnum.LANGCHAIN)
57
+
58
+ template = PromptTemplate(template=config.optimizer_prompt,
59
+ input_variables=["system_objective"],
60
+ validate_template=True)
61
+
62
+ base_prompt: str = (await template.ainvoke(input={"system_objective": config.system_objective})).to_string()
63
+ prompt_extension_template = PromptTemplate(template=mutator_prompt,
64
+ input_variables=["original_prompt", "objective"],
65
+ validate_template=True)
66
+
67
+ async def _inner(input_message: PromptOptimizerInputSchema) -> str:
68
+ """
69
+ Optimize the prompt using the provided LLM.
70
+ """
71
+
72
+ original_prompt = input_message.original_prompt
73
+ prompt_objective = input_message.objective
74
+
75
+ prompt_extension = (await prompt_extension_template.ainvoke(input={
76
+ "original_prompt": original_prompt,
77
+ "objective": prompt_objective,
78
+ })).to_string()
79
+
80
+ prompt = f"{base_prompt}\n\n{prompt_extension}"
81
+
82
+ optimized_prompt = await llm.ainvoke(prompt)
83
+ return optimized_prompt.content
84
+
85
+ yield FunctionInfo.from_fn(
86
+ fn=_inner,
87
+ description="Optimize prompts for LLMs using a feedback LLM.",
88
+ )
89
+
90
+
91
+ class PromptRecombinerConfig(FunctionBaseConfig, name="prompt_recombiner"):
92
+
93
+ optimizer_llm: LLMRef = Field(description="LLM to use for prompt recombination")
94
+ optimizer_prompt: str = Field(
95
+ description="Prompt template for the recombiner",
96
+ default=("You are an expert at combining prompt instructions for LLMs. "
97
+ "Your task is to merge two prompts for the same objective into a single, stronger prompt. "
98
+ "Do not introduce new variables or modify existing placeholders."),
99
+ )
100
+ system_objective: str = Field(description="Objective of the workflow")
101
+
102
+
103
+ @register_function(config_type=PromptRecombinerConfig, framework_wrappers=[LLMFrameworkEnum.LANGCHAIN])
104
+ async def prompt_recombiner_function(config: PromptRecombinerConfig, builder: Builder):
105
+ """
106
+ Function to recombine two parent prompts into a child prompt using the optimizer LLM.
107
+ Uses the same base template and objective instructions.
108
+ """
109
+
110
+ try:
111
+ from langchain_core.prompts import PromptTemplate
112
+ except ImportError as exc:
113
+ raise ImportError("langchain-core is not installed. Please install it to use MultiLLMPlanner.\n"
114
+ "This error can be resolve by installing nvidia-nat[langchain].") from exc
115
+
116
+ llm = await builder.get_llm(config.optimizer_llm, wrapper_type=LLMFrameworkEnum.LANGCHAIN)
117
+
118
+ template = PromptTemplate(template=config.optimizer_prompt,
119
+ input_variables=["system_objective"],
120
+ validate_template=True)
121
+
122
+ base_prompt: str = (await template.ainvoke(input={"system_objective": config.system_objective})).to_string()
123
+
124
+ class RecombineSchema(PromptOptimizerInputSchema):
125
+ parent_b: str | None = None
126
+
127
+ async def _inner(input_message: RecombineSchema) -> str:
128
+ parent_a = input_message.original_prompt
129
+ parent_b = input_message.parent_b or ""
130
+ prompt_objective = input_message.objective
131
+
132
+ prompt = (
133
+ f"{base_prompt}\n\n"
134
+ "We are performing genetic recombination between two prompts that satisfy the same objective.\n"
135
+ f"Objective: {prompt_objective}\n\n"
136
+ f"Parent A:\n{parent_a}\n\n"
137
+ f"Parent B:\n{parent_b}\n\n"
138
+ "Combine the strongest instructions and phrasing from both parents to produce a single, coherent child "
139
+ "prompt.\n"
140
+ "Maintain variables and placeholders unchanged.\n"
141
+ "Return only the child prompt text, with no additional commentary.")
142
+
143
+ child_prompt = await llm.ainvoke(prompt)
144
+ return child_prompt.content
145
+
146
+ yield FunctionInfo.from_fn(
147
+ fn=_inner,
148
+ description="Recombine two prompts into a stronger child prompt.",
149
+ )
@@ -360,7 +360,7 @@ class ReActAgentGraph(DualNodeAgent):
360
360
  if errors:
361
361
  error_text = "\n".join(errors)
362
362
  logger.error("%s %s", AGENT_LOG_PREFIX, error_text)
363
- raise ValueError(error_text)
363
+ return False
364
364
  return True
365
365
 
366
366
 
@@ -25,22 +25,26 @@ from nat.builder.function_info import FunctionInfo
25
25
  from nat.cli.register_workflow import register_function
26
26
  from nat.data_models.api_server import ChatRequest
27
27
  from nat.data_models.api_server import ChatResponse
28
+ from nat.data_models.component_ref import FunctionGroupRef
28
29
  from nat.data_models.component_ref import FunctionRef
29
30
  from nat.data_models.component_ref import LLMRef
30
31
  from nat.data_models.function import FunctionBaseConfig
32
+ from nat.data_models.optimizable import OptimizableField
33
+ from nat.data_models.optimizable import OptimizableMixin
34
+ from nat.data_models.optimizable import SearchSpace
31
35
  from nat.utils.type_converter import GlobalTypeConverter
32
36
 
33
37
  logger = logging.getLogger(__name__)
34
38
 
35
39
 
36
- class ReActAgentWorkflowConfig(FunctionBaseConfig, name="react_agent"):
40
+ class ReActAgentWorkflowConfig(FunctionBaseConfig, OptimizableMixin, name="react_agent"):
37
41
  """
38
42
  Defines a NAT function that uses a ReAct Agent performs reasoning inbetween tool calls, and utilizes the
39
43
  tool names and descriptions to select the optimal tool.
40
44
  """
41
45
 
42
- tool_names: list[FunctionRef] = Field(default_factory=list,
43
- description="The list of tools to provide to the react agent.")
46
+ tool_names: list[FunctionRef | FunctionGroupRef] = Field(
47
+ default_factory=list, description="The list of tools to provide to the react agent.")
44
48
  llm_name: LLMRef = Field(description="The LLM model to use with the react agent.")
45
49
  verbose: bool = Field(default=False, description="Set the verbosity of the react agent's logging.")
46
50
  retry_agent_response_parsing_errors: bool = Field(
@@ -75,8 +79,14 @@ class ReActAgentWorkflowConfig(FunctionBaseConfig, name="react_agent"):
75
79
  use_openai_api: bool = Field(default=False,
76
80
  description=("Use OpenAI API for the input/output types to the function. "
77
81
  "If False, strings will be used."))
78
- additional_instructions: str | None = Field(
79
- default=None, description="Additional instructions to provide to the agent in addition to the base prompt.")
82
+ additional_instructions: str | None = OptimizableField(
83
+ default=None,
84
+ description="Additional instructions to provide to the agent in addition to the base prompt.",
85
+ space=SearchSpace(
86
+ is_prompt=True,
87
+ prompt="No additional instructions.",
88
+ prompt_purpose="Additional instructions to provide to the agent in addition to the base prompt.",
89
+ ))
80
90
 
81
91
 
82
92
  @register_function(config_type=ReActAgentWorkflowConfig, framework_wrappers=[LLMFrameworkEnum.LANGCHAIN])
@@ -113,7 +113,12 @@ async def build_reasoning_function(config: ReasoningFunctionConfig, builder: Bui
113
113
  f"function without a description.")
114
114
 
115
115
  # Get the function dependencies of the augmented function
116
- function_used_tools = builder.get_function_dependencies(config.augmented_fn).functions
116
+ function_dependencies = builder.get_function_dependencies(config.augmented_fn)
117
+ function_used_tools = set()
118
+ function_used_tools.update(function_dependencies.functions)
119
+ for function_group in function_dependencies.function_groups:
120
+ function_used_tools.update(builder.get_function_group_dependencies(function_group).functions)
121
+
117
122
  tool_names_with_desc: list[tuple[str, str]] = []
118
123
 
119
124
  for tool in function_used_tools:
nat/agent/register.py CHANGED
@@ -16,7 +16,9 @@
16
16
  # flake8: noqa
17
17
 
18
18
  # Import any workflows which need to be automatically registered here
19
+ from .prompt_optimizer import register as prompt_optimizer
19
20
  from .react_agent import register as react_agent
20
21
  from .reasoning_agent import reasoning_agent
21
22
  from .rewoo_agent import register as rewoo_agent
23
+ from .router_agent import register as router_agent
22
24
  from .tool_calling_agent import register as tool_calling_agent
@@ -68,7 +68,8 @@ class ReWOOAgentGraph(BaseAgent):
68
68
  use_tool_schema: bool = True,
69
69
  callbacks: list[AsyncCallbackHandler] | None = None,
70
70
  detailed_logs: bool = False,
71
- log_response_max_chars: int = 1000):
71
+ log_response_max_chars: int = 1000,
72
+ tool_call_max_retries: int = 3):
72
73
  super().__init__(llm=llm,
73
74
  tools=tools,
74
75
  callbacks=callbacks,
@@ -94,6 +95,7 @@ class ReWOOAgentGraph(BaseAgent):
94
95
  self.planner_prompt = planner_prompt.partial(tools=tool_names_and_descriptions, tool_names=tool_names)
95
96
  self.solver_prompt = solver_prompt
96
97
  self.tools_dict = {tool.name: tool for tool in tools}
98
+ self.tool_call_max_retries = tool_call_max_retries
97
99
 
98
100
  logger.debug("%s Initialized ReWOO Agent Graph", AGENT_LOG_PREFIX)
99
101
 
@@ -269,7 +271,7 @@ class ReWOOAgentGraph(BaseAgent):
269
271
  tool_response = await self._call_tool(requested_tool,
270
272
  tool_input_parsed,
271
273
  RunnableConfig(callbacks=self.callbacks),
272
- max_retries=3)
274
+ max_retries=self.tool_call_max_retries)
273
275
 
274
276
  if self.detailed_logs:
275
277
  self._log_tool_response(requested_tool.name, tool_input_parsed, str(tool_response))
@@ -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.api_server import ChatRequest
27
27
  from nat.data_models.api_server import ChatResponse
28
+ from nat.data_models.component_ref import FunctionGroupRef
28
29
  from nat.data_models.component_ref import FunctionRef
29
30
  from nat.data_models.component_ref import LLMRef
30
31
  from nat.data_models.function import FunctionBaseConfig
@@ -39,8 +40,8 @@ class ReWOOAgentWorkflowConfig(FunctionBaseConfig, name="rewoo_agent"):
39
40
  tool names and descriptions to select the optimal tool.
40
41
  """
41
42
 
42
- tool_names: list[FunctionRef] = Field(default_factory=list,
43
- description="The list of tools to provide to the rewoo agent.")
43
+ tool_names: list[FunctionRef | FunctionGroupRef] = Field(
44
+ default_factory=list, description="The list of tools to provide to the rewoo agent.")
44
45
  llm_name: LLMRef = Field(description="The LLM model to use with the rewoo agent.")
45
46
  verbose: bool = Field(default=False, description="Set the verbosity of the rewoo agent's logging.")
46
47
  include_tool_input_schema_in_tool_description: bool = Field(
@@ -52,6 +53,9 @@ class ReWOOAgentWorkflowConfig(FunctionBaseConfig, name="rewoo_agent"):
52
53
  solver_prompt: str | None = Field(
53
54
  default=None,
54
55
  description="Provides the SOLVER_PROMPT to use with the agent") # defaults to SOLVER_PROMPT in prompt.py
56
+ tool_call_max_retries: PositiveInt = Field(default=3,
57
+ description="The number of retries before raising a tool call error.",
58
+ ge=1)
55
59
  max_history: int = Field(default=15, description="Maximum number of messages to keep in the conversation history.")
56
60
  log_response_max_chars: PositiveInt = Field(
57
61
  default=1000, description="Maximum number of characters to display in logs when logging tool responses.")
@@ -118,7 +122,8 @@ async def rewoo_agent_workflow(config: ReWOOAgentWorkflowConfig, builder: Builde
118
122
  tools=tools,
119
123
  use_tool_schema=config.include_tool_input_schema_in_tool_description,
120
124
  detailed_logs=config.verbose,
121
- log_response_max_chars=config.log_response_max_chars).build_graph()
125
+ log_response_max_chars=config.log_response_max_chars,
126
+ tool_call_max_retries=config.tool_call_max_retries).build_graph()
122
127
 
123
128
  async def _response_fn(input_message: ChatRequest) -> ChatResponse:
124
129
  try:
File without changes