mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-30 04:44:28 +00:00
fix(agent): prevent agents from accessing disabled skills (#292)
Disabling a skill in the agent config dialog only removed it from the agent_skills join table, but the chat flow still advertised ALL team skills to the model in the <available_skills> system prompt section and the read_skill tool never checked per-agent enablement. - getAgentChatContextActivity / getAgentAutofillContextActivity now only return skills explicitly enabled for the agent (agent_skills), and expose enabledSkillIds in the execution context. - createReadSkillTool accepts enabledSkillIds and rejects read_skill calls for skills not enabled for the agent, even if the model knows the skill id from earlier conversation history. - Added unit tests for context filtering (chat + autofill), tool-level enforcement, and the zero-enabled-skills case.
This commit is contained in:
@@ -17,6 +17,7 @@ export const createReadSkillTool = (
|
||||
userId: string | undefined,
|
||||
onEnvsAdded: (envs: Record<string, string>) => void,
|
||||
onSkillLoaded?: () => Promise<void> | void,
|
||||
enabledSkillIds?: string[],
|
||||
): AgentTool<typeof readSkillSchema, { skillId: string }> => ({
|
||||
name: 'read_skill',
|
||||
label: 'Read Agent Skill',
|
||||
@@ -31,6 +32,12 @@ export const createReadSkillTool = (
|
||||
throw new Error(`Skill with ID ${params.skillId} not found.`)
|
||||
}
|
||||
|
||||
// Skills disabled for this agent must not be loadable, even if the model
|
||||
// somehow knows their ID (e.g. from earlier conversation history).
|
||||
if (enabledSkillIds && !enabledSkillIds.includes(params.skillId)) {
|
||||
throw new Error(`Skill with ID ${params.skillId} is not enabled for this agent.`)
|
||||
}
|
||||
|
||||
const requiredLevel = ROLE_HIERARCHY[skill.permission] || 1
|
||||
|
||||
if (userId) {
|
||||
|
||||
Reference in New Issue
Block a user