fix: fixed tool filtering logic for skills and user functions in agents
This commit is contained in:
@@ -1229,7 +1229,11 @@ impl RequestContext {
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
if let Some(ref tool_names) = role_filter {
|
if let Some(ref tool_names) = role_filter {
|
||||||
agent_functions.retain(|v| tool_names.contains(&v.name));
|
agent_functions.retain(|v| {
|
||||||
|
tool_names.contains(&v.name)
|
||||||
|
|| v.name.starts_with(SKILL_FUNCTION_PREFIX)
|
||||||
|
|| v.name.starts_with(USER_FUNCTION_PREFIX)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let tool_names: HashSet<String> = agent_functions
|
let tool_names: HashSet<String> = agent_functions
|
||||||
|
|||||||
+19
-1
@@ -3,6 +3,7 @@ use super::structured;
|
|||||||
use super::types::LlmNode;
|
use super::types::LlmNode;
|
||||||
use crate::client::{Model, ModelType, call_chat_completions};
|
use crate::client::{Model, ModelType, call_chat_completions};
|
||||||
use crate::config::{Input, RequestContext, Role, RoleLike, SkillPolicy};
|
use crate::config::{Input, RequestContext, Role, RoleLike, SkillPolicy};
|
||||||
|
use crate::function::skill::skill_function_declarations;
|
||||||
use crate::utils::create_abort_signal;
|
use crate::utils::create_abort_signal;
|
||||||
use anyhow::{Context, Error, Result, anyhow, bail};
|
use anyhow::{Context, Error, Result, anyhow, bail};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
@@ -105,7 +106,7 @@ async fn run(
|
|||||||
let (regular_tools, mcp_servers) = categorize_tools(node.tools.as_deref());
|
let (regular_tools, mcp_servers) = categorize_tools(node.tools.as_deref());
|
||||||
validate_tools_subset(®ular_tools, &mcp_servers, parent_ctx)?;
|
validate_tools_subset(®ular_tools, &mcp_servers, parent_ctx)?;
|
||||||
|
|
||||||
let role = build_inline_role(
|
let mut role = build_inline_role(
|
||||||
node,
|
node,
|
||||||
instructions.as_deref(),
|
instructions.as_deref(),
|
||||||
®ular_tools,
|
®ular_tools,
|
||||||
@@ -121,6 +122,23 @@ async fn run(
|
|||||||
parent_ctx.agent.as_ref(),
|
parent_ctx.agent.as_ref(),
|
||||||
parent_ctx.session.as_ref(),
|
parent_ctx.session.as_ref(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
if policy.skills_enabled
|
||||||
|
&& node
|
||||||
|
.tools
|
||||||
|
.as_deref()
|
||||||
|
.map(|t| !t.is_empty())
|
||||||
|
.unwrap_or(false)
|
||||||
|
{
|
||||||
|
let mut tools = role.enabled_tools().map(|v| v.to_vec()).unwrap_or_default();
|
||||||
|
for decl in skill_function_declarations() {
|
||||||
|
if !tools.contains(&decl.name) {
|
||||||
|
tools.push(decl.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
role.set_enabled_tools(Some(tools));
|
||||||
|
}
|
||||||
|
|
||||||
let composed_role = parent_ctx.skill_registry.effective_role(&role, &policy);
|
let composed_role = parent_ctx.skill_registry.effective_role(&role, &policy);
|
||||||
|
|
||||||
let saved_role = parent_ctx.role.clone();
|
let saved_role = parent_ctx.role.clone();
|
||||||
|
|||||||
Reference in New Issue
Block a user