fix: accidentally added back in full agent tools on LLM nodes

This commit is contained in:
2026-05-14 14:39:08 -06:00
parent fc7fdc98b4
commit f58f751c59
+62 -6
View File
@@ -990,9 +990,12 @@ impl RequestContext {
let app = self.app.config.as_ref(); let app = self.app.config.as_ref();
let mut functions = vec![]; let mut functions = vec![];
if app.function_calling_support { if app.function_calling_support {
if let Some(enabled_tools) = role.enabled_tools() { // Compute the set of tool names enabled by the role filter, drawn
let mut tool_names: HashSet<String> = Default::default(); // from BOTH the tool_scope pool and the agent's pool so that an
let declaration_names: HashSet<String> = self // explicit `enabled_tools` list (e.g. from a graph LLM node) can
// narrow the agent's own custom tools too.
let role_filter: Option<HashSet<String>> = role.enabled_tools().map(|enabled_tools| {
let mut declaration_names: HashSet<String> = self
.tool_scope .tool_scope
.functions .functions
.declarations() .declarations()
@@ -1004,11 +1007,30 @@ impl RequestContext {
}) })
.map(|v| v.name.to_string()) .map(|v| v.name.to_string())
.collect(); .collect();
if let Some(agent) = &self.agent {
declaration_names.extend(
agent
.functions()
.declarations()
.iter()
.filter(|v| {
!v.name.starts_with(MCP_INVOKE_META_FUNCTION_NAME_PREFIX)
&& !v.name.starts_with(MCP_SEARCH_META_FUNCTION_NAME_PREFIX)
&& !v.name.starts_with(MCP_DESCRIBE_META_FUNCTION_NAME_PREFIX)
})
.map(|v| v.name.to_string()),
);
}
let mut tool_names: HashSet<String> = Default::default();
if enabled_tools == "all" { if enabled_tools == "all" {
tool_names.extend(declaration_names); tool_names.extend(declaration_names);
} else { } else {
for item in enabled_tools.split(',') { for item in enabled_tools.split(',') {
let item = item.trim(); let item = item.trim();
if item.is_empty() {
continue;
}
if let Some(values) = app.mapping_tools.get(item) { if let Some(values) = app.mapping_tools.get(item) {
tool_names.extend( tool_names.extend(
values values
@@ -1021,6 +1043,10 @@ impl RequestContext {
} }
} }
} }
tool_names
});
if let Some(ref tool_names) = role_filter {
functions = self functions = self
.tool_scope .tool_scope
.functions .functions
@@ -1063,6 +1089,9 @@ impl RequestContext {
&& !v.name.starts_with(MCP_DESCRIBE_META_FUNCTION_NAME_PREFIX) && !v.name.starts_with(MCP_DESCRIBE_META_FUNCTION_NAME_PREFIX)
}) })
.collect(); .collect();
if let Some(ref tool_names) = role_filter {
agent_functions.retain(|v| tool_names.contains(&v.name));
}
let tool_names: HashSet<String> = agent_functions let tool_names: HashSet<String> = agent_functions
.iter() .iter()
.filter_map(|v| { .filter_map(|v| {
@@ -1089,9 +1118,9 @@ impl RequestContext {
let app = self.app.config.as_ref(); let app = self.app.config.as_ref();
let mut mcp_functions = vec![]; let mut mcp_functions = vec![];
if app.mcp_server_support { if app.mcp_server_support {
if let Some(enabled_mcp_servers) = role.enabled_mcp_servers() { let role_filter: Option<HashSet<String>> =
let mut server_names: HashSet<String> = Default::default(); role.enabled_mcp_servers().map(|enabled_mcp_servers| {
let mcp_declaration_names: HashSet<String> = self let mut mcp_declaration_names: HashSet<String> = self
.tool_scope .tool_scope
.functions .functions
.declarations() .declarations()
@@ -1103,11 +1132,31 @@ impl RequestContext {
}) })
.map(|v| v.name.to_string()) .map(|v| v.name.to_string())
.collect(); .collect();
if let Some(agent) = &self.agent {
mcp_declaration_names.extend(
agent
.functions()
.declarations()
.iter()
.filter(|v| {
v.name.starts_with(MCP_INVOKE_META_FUNCTION_NAME_PREFIX)
|| v.name.starts_with(MCP_SEARCH_META_FUNCTION_NAME_PREFIX)
|| v.name
.starts_with(MCP_DESCRIBE_META_FUNCTION_NAME_PREFIX)
})
.map(|v| v.name.to_string()),
);
}
let mut server_names: HashSet<String> = Default::default();
if enabled_mcp_servers == "all" { if enabled_mcp_servers == "all" {
server_names.extend(mcp_declaration_names); server_names.extend(mcp_declaration_names);
} else { } else {
for item in enabled_mcp_servers.split(',') { for item in enabled_mcp_servers.split(',') {
let item = item.trim(); let item = item.trim();
if item.is_empty() {
continue;
}
let item_invoke_name = let item_invoke_name =
format!("{}_{item}", MCP_INVOKE_META_FUNCTION_NAME_PREFIX); format!("{}_{item}", MCP_INVOKE_META_FUNCTION_NAME_PREFIX);
let item_search_name = let item_search_name =
@@ -1146,6 +1195,10 @@ impl RequestContext {
} }
} }
} }
server_names
});
if let Some(ref server_names) = role_filter {
mcp_functions = self mcp_functions = self
.tool_scope .tool_scope
.functions .functions
@@ -1173,6 +1226,9 @@ impl RequestContext {
|| v.name.starts_with(MCP_DESCRIBE_META_FUNCTION_NAME_PREFIX) || v.name.starts_with(MCP_DESCRIBE_META_FUNCTION_NAME_PREFIX)
}) })
.collect(); .collect();
if let Some(ref server_names) = role_filter {
agent_functions.retain(|v| server_names.contains(&v.name));
}
let tool_names: HashSet<String> = agent_functions let tool_names: HashSet<String> = agent_functions
.iter() .iter()
.filter_map(|v| { .filter_map(|v| {