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:
Yiling-J
2026-08-10 17:33:40 +08:00
committed by GitHub
parent 49ef48a74a
commit 1daeaf51ef
6 changed files with 361 additions and 12 deletions
+30 -11
View File
@@ -41,6 +41,11 @@ export type AgentWithProviderAndModel = Prisma.AgentGetPayload<{
include: {
provider: true
modelRef: true
skills: {
include: {
skill: true
}
}
}
}>
@@ -54,6 +59,7 @@ export interface AgentExecutionContext {
agent: AgentWithProviderAndModel
dbProviders: DbProviderWithModels[]
teamSkills: Skill[]
enabledSkillIds: string[]
allowedDomains: string[]
}
@@ -71,7 +77,7 @@ async function executeAgentPrompt(params: {
context: AgentExecutionContext
attachedAssets?: Array<{ id: string; name: string; type: string }>
}): Promise<{ text: string; usage: Usage; sessionId: string }> {
const { agent, dbProviders, teamSkills, allowedDomains } = params.context
const { agent, dbProviders, teamSkills, enabledSkillIds, allowedDomains } = params.context
if (!agent.provider) {
throw ApplicationFailure.create({
@@ -125,6 +131,7 @@ When creating a file or version, first use 'list_autofill_fields' to inspect the
name: s.name,
description: s.description,
})),
enabledSkillIds,
allowedDomains,
sessionId: params.sessionId,
userId: params.userId,
@@ -834,6 +841,11 @@ export async function getAgentChatContextActivity(params: {
include: {
provider: true,
modelRef: true,
skills: {
include: {
skill: true,
},
},
},
})
if (!agent) {
@@ -864,10 +876,10 @@ export async function getAgentChatContextActivity(params: {
include: { models: true },
})
// Fetch team skills
const teamSkills = await prisma.skill.findMany({
where: { teamId: params.teamId },
})
// Only advertise skills that are explicitly enabled for this agent (agent_skills).
// Disabled skills must not be listed in the system prompt nor loadable via read_skill.
const enabledSkills = (agent.skills ?? []).map((as) => as.skill)
const enabledSkillIds = enabledSkills.map((s) => s.id)
const sandbox = await prisma.sandbox.findUnique({
where: { teamId: params.teamId },
@@ -877,7 +889,8 @@ export async function getAgentChatContextActivity(params: {
return {
agent,
dbProviders,
teamSkills,
teamSkills: enabledSkills,
enabledSkillIds,
allowedDomains,
}
}
@@ -912,6 +925,11 @@ export async function getAgentAutofillContextActivity(params: {
include: {
provider: true,
modelRef: true,
skills: {
include: {
skill: true,
},
},
},
})
if (!agentWithDetails) {
@@ -938,10 +956,10 @@ export async function getAgentAutofillContextActivity(params: {
include: { models: true },
})
// Fetch team skills
const teamSkills = await prisma.skill.findMany({
where: { teamId: params.teamId },
})
// Only advertise skills that are explicitly enabled for this agent (agent_skills).
// Disabled skills must not be listed in the system prompt nor loadable via read_skill.
const enabledSkills = (agentWithDetails.skills ?? []).map((as) => as.skill)
const enabledSkillIds = enabledSkills.map((s) => s.id)
const sandbox = await prisma.sandbox.findUnique({
where: { teamId: params.teamId },
@@ -951,7 +969,8 @@ export async function getAgentAutofillContextActivity(params: {
return {
agent: agentWithDetails,
dbProviders,
teamSkills,
teamSkills: enabledSkills,
enabledSkillIds,
allowedDomains,
}
}