refactor: update risk levels in tool definitions and validation logic to remove sensitive level
This commit is contained in:
+1
-1
Submodule docs updated: ab3cb38eda...50814016a3
@@ -65,7 +65,7 @@ func (e *fakeMCPToolExecutor) Execute(_ context.Context, toolCode string, argume
|
|||||||
e.toolCode = toolCode
|
e.toolCode = toolCode
|
||||||
e.arguments = arguments
|
e.arguments = arguments
|
||||||
e.policy = policy
|
e.policy = policy
|
||||||
return aitooling.Definition{Code: toolCode, RiskLevel: aitooling.RiskLevelSensitive}, e.result, e.err
|
return aitooling.Definition{Code: toolCode, RiskLevel: aitooling.RiskLevelRead}, e.result, e.err
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ model.ToolCallingChatModel = (*scriptedToolCallingModel)(nil)
|
var _ model.ToolCallingChatModel = (*scriptedToolCallingModel)(nil)
|
||||||
|
|||||||
@@ -11,9 +11,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
RiskLevelRead = "read"
|
RiskLevelRead = "read"
|
||||||
RiskLevelWrite = "write"
|
RiskLevelWrite = "write"
|
||||||
RiskLevelSensitive = "sensitive"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Definition is the normalized, engine-independent description of a tool.
|
// Definition is the normalized, engine-independent description of a tool.
|
||||||
|
|||||||
@@ -248,7 +248,7 @@ func (s *aIAgentService) validatePublishableAgent(db *gorm.DB, agent *models.AIA
|
|||||||
return errorsx.InvalidParam("ai agent direct tool definition is unavailable")
|
return errorsx.InvalidParam("ai agent direct tool definition is unavailable")
|
||||||
}
|
}
|
||||||
if definition.RequireConfirmation {
|
if definition.RequireConfirmation {
|
||||||
return errorsx.InvalidParam("ai agent sensitive direct tools must be executed through a confirmed playbook")
|
return errorsx.InvalidParam("ai agent direct tool requires confirmation and cannot be executed directly")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -456,7 +456,7 @@ func (s *aIAgentService) normalizeToolPolicy(raw string) (string, error) {
|
|||||||
if level == "" {
|
if level == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if level != "read" && level != "write" && level != "sensitive" {
|
if level != "read" && level != "write" {
|
||||||
return "", errorsx.InvalidParam("ai agent tool policy contains an invalid risk level")
|
return "", errorsx.InvalidParam("ai agent tool policy contains an invalid risk level")
|
||||||
}
|
}
|
||||||
if _, exists := seen[level]; exists {
|
if _, exists := seen[level]; exists {
|
||||||
|
|||||||
@@ -185,13 +185,16 @@ func TestAIAgentServiceCreatesWorkflowDraftForHybrid(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAIAgentServiceNormalizesToolPolicy(t *testing.T) {
|
func TestAIAgentServiceNormalizesToolPolicy(t *testing.T) {
|
||||||
policy, err := AIAgentService.normalizeToolPolicy(`{"maxTotalCalls":2,"maxArgumentBytes":1024,"allowedRiskLevels":["READ","read","sensitive"]}`)
|
policy, err := AIAgentService.normalizeToolPolicy(`{"maxTotalCalls":2,"maxArgumentBytes":1024,"allowedRiskLevels":["READ","read","write"]}`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("normalizeToolPolicy: %v", err)
|
t.Fatalf("normalizeToolPolicy: %v", err)
|
||||||
}
|
}
|
||||||
if !strings.Contains(policy, `"maxTotalCalls":2`) || !strings.Contains(policy, `"allowedRiskLevels":["read","sensitive"]`) {
|
if !strings.Contains(policy, `"maxTotalCalls":2`) || !strings.Contains(policy, `"allowedRiskLevels":["read","write"]`) {
|
||||||
t.Fatalf("unexpected normalized policy: %s", policy)
|
t.Fatalf("unexpected normalized policy: %s", policy)
|
||||||
}
|
}
|
||||||
|
if _, err := AIAgentService.normalizeToolPolicy(`{"allowedRiskLevels":["sensitive"]}`); err == nil {
|
||||||
|
t.Fatal("expected removed sensitive risk level to be rejected")
|
||||||
|
}
|
||||||
if _, err := AIAgentService.normalizeToolPolicy(`{"allowedRiskLevels":["admin"]}`); err == nil {
|
if _, err := AIAgentService.normalizeToolPolicy(`{"allowedRiskLevels":["admin"]}`); err == nil {
|
||||||
t.Fatal("expected invalid risk level error")
|
t.Fatal("expected invalid risk level error")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user