Skip to content

Commit 4a87d6c

Browse files
committed
fix(builder): an entry function two groups offer is ambiguous; document group functions as entry points
Signed-off-by: Somay-kousis <somaykaush@gmail.com>
1 parent 9e3ddac commit 4a87d6c

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

‎docs/source/build-workflows/functions-and-function-groups/function-groups.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,8 @@ function_groups:
458458
| `include: [add]` | ✓ (all functions) | ✓ (only `add`) | ✓ (only `add`) |
459459
| `exclude: [divide]` | ✓ (all functions) | ✗ | ✓ (except `divide`) |
460460

461+
A function that is available as an agent tool can also be the entry point of a workflow, even when it is not in the global registry. For example, `nat mcp serve` publishes each of them as an MCP tool, and a FastAPI endpoint can name one in `function_name`.
462+
461463
## Using Function Groups
462464

463465
### Creating Custom Function Groups

‎packages/nvidia_nat_core/src/nat/builder/per_user_workflow_builder.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ async def build(self, entry_function: str | None = None) -> Workflow:
703703
entry_fn_obj = await self.get_function(entry_function)
704704
except ValueError:
705705
entry_fn_obj = await _find_function_group_function(
706-
self._check_backwards_compatibility_function_name(entry_function),
706+
entry_function,
707707
[*self._per_user_function_groups.values(), *self._shared_builder._function_groups.values()])
708708
if entry_fn_obj is None:
709709
raise

‎packages/nvidia_nat_core/src/nat/builder/workflow_builder.py‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,15 @@ class ConfiguredTrajectoryBuilder:
191191

192192
async def _find_function_group_function(name: str, function_groups: list[ConfiguredFunctionGroup]) -> Function | None:
193193
"""A function one of the groups makes available as a tool (`group__fn`), even if it isn't globally registered."""
194+
matches = []
194195
for function_group in function_groups:
195196
accessible_functions = await function_group.instance.get_accessible_functions()
196197
if name in accessible_functions:
197-
return accessible_functions[name]
198-
return None
198+
matches.append(accessible_functions[name])
199+
if len(matches) > 1:
200+
# e.g. group `a` with function `b__c` and group `a__b` with function `c`
201+
raise ValueError(f"Function `{name}` is ambiguous: more than one function group makes it available")
202+
return matches[0] if matches else None
199203

200204

201205
def _log_build_failure(component_name: str,
@@ -717,8 +721,7 @@ async def _get_entry_function(self, name: str) -> Function:
717721
try:
718722
return await self.get_function(name)
719723
except ValueError:
720-
group_function = await _find_function_group_function(
721-
self._check_backwards_compatibility_function_name(name), list(self._function_groups.values()))
724+
group_function = await _find_function_group_function(name, list(self._function_groups.values()))
722725
if group_function is None:
723726
raise
724727
return group_function

0 commit comments

Comments
 (0)