feat: Add Agent Evaluation System and Refactor AI Modules (#16111)

## Summary

This PR introduces a comprehensive agent evaluation system and refactors
the AI module structure for better organization.

## Key Changes

### 🎯 Agent Evaluation System
- Added **Agent Turn Evaluation** entities, DTOs, and database schema
- New GraphQL mutations: `evaluateAgentTurn` and `runEvaluationInput`
- Added `evaluationInputs` field to Agent entity for storing test inputs
- New `AgentTurnGraderService` for automatic turn evaluation
- Added evaluation UI with new **Evals** and **Logs** tabs in agent
detail pages

### 🏗️ Entity & Module Refactoring
- Renamed `AgentChatMessage` → `AgentMessage` for clarity
- Consolidated chat entities: `AgentMessage`, `AgentTurn`, and
`AgentChatThread`
- Reorganized AI modules under `ai/` subdirectory structure
- Updated imports across codebase to reflect new module paths

### 🤖 New Agents & Roles
- Added **Dashboard Builder Agent** for dashboard creation and
management
- Added **Dashboard Manager Role** with appropriate permissions
- Updated role permissions to be more granular (users vs agents vs API
keys)

### 🔐 Permission System Updates
- Added `HTTP_REQUEST_TOOL` permission flag
- Updated Workflow Manager role permissions (restricted tool access)
- Enhanced permission flag types to differentiate between user/agent/API
key contexts
- Added `isRelevantForAgents`, `isRelevantForApiKeys`,
`isRelevantForUsers` to permission flags

### 📨 Message Role Enhancement
- Added `system` role to `AgentMessageRole` enum (alongside
user/assistant)
- Updated message handling to support system prompts

### 🎨 UI/UX Improvements
- New tabs in agent detail: **Evals** and **Logs**
- Added turn detail page: `/ai/agents/:agentId/turns/:turnId`
- Fixed text overflow in `SettingsListItemCardContent`
- Updated role applicability labels ("Assignable to Workspace Members")

### 🛠️ Technical Improvements
- Fixed Zod schema validation for UUID and Date fields (use string
validators)
- Updated `ToolRegistryService` to properly register HTTP tool with
permission flag
- Enhanced error handling in agent execution services
- Updated database migrations for new entity schema

## Database Migrations
- `1764210000000-add-system-role-to-agent-message.ts`
- `1764220000000-add-evaluation-inputs-to-agent.ts`
- `1764200000000-add-agent-turn-evaluation.ts`
- `1764100000000-refactor-agent-chat-entities.ts`

## Testing
- [ ] Agent evaluation flow tested
- [ ] Dashboard Builder agent tested
- [ ] Permission system validated
- [ ] UI tabs and navigation tested
- [ ] Database migrations run successfully

## Breaking Changes
⚠️ **Entity Rename**: `AgentChatMessage` renamed to `AgentMessage` -
GraphQL queries need updating

## Related Issues
<!-- Link any related issues here -->

## Screenshots
<!-- Add screenshots if applicable -->
This commit is contained in:
Félix Malfait
2025-11-27 08:25:40 +01:00
committed by GitHub
parent 35f81805b8
commit 4f20fd35c5
158 changed files with 2954 additions and 556 deletions
@@ -33,9 +33,17 @@ const StyledRightContainer = styled.div`
`;
const StyledContent = styled.div`
flex: 1 0 auto;
flex: 1 1 0;
display: flex;
gap: ${({ theme }) => theme.spacing(1)};
min-width: 0;
overflow: hidden;
`;
const StyledLabel = styled.span`
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
`;
const StyledDescription = styled.span`
@@ -81,7 +89,7 @@ export const SettingsListItemCardContent = ({
/>
)}
<StyledContent>
{label}
<StyledLabel>{label}</StyledLabel>
{!!description && <StyledDescription>{description}</StyledDescription>}
</StyledContent>
<StyledRightContainer>
@@ -68,78 +68,117 @@ export const SettingsRolePermissionsSettingsSection = ({
name: t`API Keys & Webhooks`,
description: t`Manage API keys and webhooks`,
Icon: IconCode,
isRelevantForAgents: true,
isRelevantForApiKeys: true,
isRelevantForUsers: true,
},
{
key: PermissionFlagType.WORKSPACE,
name: t`Workspace`,
description: t`Set global workspace preferences`,
Icon: IconSettings,
isRelevantForAgents: true,
isRelevantForApiKeys: true,
isRelevantForUsers: true,
},
{
key: PermissionFlagType.WORKSPACE_MEMBERS,
name: t`Users`,
description: t`Add or remove users`,
Icon: IconUsers,
isRelevantForAgents: true,
isRelevantForApiKeys: true,
isRelevantForUsers: true,
},
{
key: PermissionFlagType.ROLES,
name: t`Roles`,
description: t`Define user roles and access levels`,
Icon: IconLockOpen,
isRelevantForAgents: true,
isRelevantForApiKeys: true,
isRelevantForUsers: true,
},
{
key: PermissionFlagType.DATA_MODEL,
name: t`Data Model`,
description: t`Edit data structure and fields`,
Icon: IconHierarchy,
isRelevantForAgents: true,
isRelevantForApiKeys: true,
isRelevantForUsers: true,
},
{
key: PermissionFlagType.SECURITY,
name: t`Security`,
description: t`Manage security policies`,
Icon: IconKey,
isRelevantForAgents: true,
isRelevantForApiKeys: true,
isRelevantForUsers: true,
},
{
key: PermissionFlagType.WORKFLOWS,
name: t`Workflows`,
description: t`Manage workflows`,
Icon: IconSettingsAutomation,
isRelevantForAgents: true,
isRelevantForApiKeys: true,
isRelevantForUsers: true,
},
{
key: PermissionFlagType.SSO_BYPASS,
name: t`SSO Bypass`,
description: t`Enable bypass options`,
Icon: IconShield,
isRelevantForAgents: false,
isRelevantForApiKeys: false,
isRelevantForUsers: true,
},
{
key: PermissionFlagType.IMPERSONATE,
name: t`Impersonate`,
description: t`Impersonate workspace users`,
Icon: IconSpy,
isRelevantForAgents: false,
isRelevantForApiKeys: false,
isRelevantForUsers: true,
},
{
key: PermissionFlagType.APPLICATIONS,
name: t`Applications`,
description: t`Install and manage applications`,
Icon: IconApps,
isRelevantForAgents: true,
isRelevantForApiKeys: true,
isRelevantForUsers: true,
},
{
key: PermissionFlagType.LAYOUTS,
name: t`Layouts`,
description: t`Customize page layouts and UI structure`,
Icon: IconLayoutSidebarRightCollapse,
isRelevantForAgents: true,
isRelevantForApiKeys: true,
isRelevantForUsers: true,
},
{
key: PermissionFlagType.BILLING,
name: t`Billing`,
description: t`Manage billing and subscriptions`,
Icon: IconCreditCard,
isRelevantForAgents: false,
isRelevantForApiKeys: false,
isRelevantForUsers: true,
},
{
key: PermissionFlagType.AI_SETTINGS,
name: t`AI`,
description: t`Create and configure AI agents`,
Icon: IconSparkles,
isRelevantForAgents: true,
isRelevantForApiKeys: true,
isRelevantForUsers: true,
},
];
@@ -153,30 +192,67 @@ export const SettingsRolePermissionsSettingsSection = ({
) {
return false;
}
// Filter based on role assignment capabilities
const canBeAssignedOnlyToAgents =
settingsDraftRole.canBeAssignedToAgents &&
!settingsDraftRole.canBeAssignedToUsers &&
!settingsDraftRole.canBeAssignedToApiKeys;
const canBeAssignedOnlyToApiKeys =
settingsDraftRole.canBeAssignedToApiKeys &&
!settingsDraftRole.canBeAssignedToUsers &&
!settingsDraftRole.canBeAssignedToAgents;
const canBeAssignedOnlyToUsers =
settingsDraftRole.canBeAssignedToUsers &&
!settingsDraftRole.canBeAssignedToAgents &&
!settingsDraftRole.canBeAssignedToApiKeys;
if (canBeAssignedOnlyToAgents && !permission.isRelevantForAgents) {
return false;
}
if (canBeAssignedOnlyToApiKeys && !permission.isRelevantForApiKeys) {
return false;
}
if (canBeAssignedOnlyToUsers && !permission.isRelevantForUsers) {
return false;
}
return true;
});
}, [isAIEnabled, isApplicationEnabled]);
}, [isAIEnabled, isApplicationEnabled, settingsDraftRole]);
const shouldShowAllAccessToggle =
!settingsDraftRole.canBeAssignedToAgents ||
settingsDraftRole.canBeAssignedToUsers;
return (
<Section>
<H2Title title={t`Settings`} description={t`Settings permissions`} />
<StyledCard rounded>
<SettingsOptionCardContentToggle
Icon={IconSettings}
title={t`Settings All Access`}
description={t`Ability to edit all settings`}
checked={settingsDraftRole.canUpdateAllSettings}
disabled={!isEditable}
onChange={() => {
setSettingsDraftRole({
...settingsDraftRole,
canUpdateAllSettings: !settingsDraftRole.canUpdateAllSettings,
});
}}
/>
</StyledCard>
{shouldShowAllAccessToggle && (
<StyledCard rounded>
<SettingsOptionCardContentToggle
Icon={IconSettings}
title={t`Settings All Access`}
description={t`Ability to edit all settings`}
checked={settingsDraftRole.canUpdateAllSettings}
disabled={!isEditable}
onChange={() => {
setSettingsDraftRole({
...settingsDraftRole,
canUpdateAllSettings: !settingsDraftRole.canUpdateAllSettings,
});
}}
/>
</StyledCard>
)}
<AnimatedExpandableContainer
isExpanded={!settingsDraftRole.canUpdateAllSettings}
isExpanded={
!shouldShowAllAccessToggle || !settingsDraftRole.canUpdateAllSettings
}
dimension="height"
animationDurations={{
opacity: 0.2,
@@ -10,6 +10,7 @@ import { useRecoilState } from 'recoil';
import {
H2Title,
IconApi,
IconAt,
IconDownload,
IconFileExport,
@@ -62,6 +63,9 @@ export const SettingsRolePermissionsToolSection = ({
description: t`Chat with AI agents and use AI features`,
Icon: IconSparkles,
isToolPermission: true,
isRelevantForAgents: false,
isRelevantForApiKeys: true,
isRelevantForUsers: true,
},
{
key: PermissionFlagType.UPLOAD_FILE,
@@ -69,6 +73,9 @@ export const SettingsRolePermissionsToolSection = ({
description: t`Allow uploading files and attachments`,
Icon: IconFileUpload,
isToolPermission: true,
isRelevantForAgents: false,
isRelevantForApiKeys: true,
isRelevantForUsers: true,
},
{
key: PermissionFlagType.DOWNLOAD_FILE,
@@ -76,6 +83,9 @@ export const SettingsRolePermissionsToolSection = ({
description: t`Allow downloading files and attachments`,
Icon: IconDownload,
isToolPermission: true,
isRelevantForAgents: false,
isRelevantForApiKeys: true,
isRelevantForUsers: true,
},
{
key: PermissionFlagType.SEND_EMAIL_TOOL,
@@ -83,6 +93,19 @@ export const SettingsRolePermissionsToolSection = ({
description: t`Send emails via connected accounts`,
Icon: IconMail,
isToolPermission: true,
isRelevantForAgents: true,
isRelevantForApiKeys: true,
isRelevantForUsers: true,
},
{
key: PermissionFlagType.HTTP_REQUEST_TOOL,
name: t`HTTP Request`,
description: t`Make HTTP requests to external APIs`,
Icon: IconApi,
isToolPermission: true,
isRelevantForAgents: true,
isRelevantForApiKeys: false,
isRelevantForUsers: false,
},
{
key: PermissionFlagType.IMPORT_CSV,
@@ -90,6 +113,9 @@ export const SettingsRolePermissionsToolSection = ({
description: t`Allow importing data from CSV files`,
Icon: IconFileImport,
isToolPermission: true,
isRelevantForAgents: false,
isRelevantForApiKeys: true,
isRelevantForUsers: true,
},
{
key: PermissionFlagType.EXPORT_CSV,
@@ -97,6 +123,9 @@ export const SettingsRolePermissionsToolSection = ({
description: t`Allow exporting data to CSV files`,
Icon: IconFileExport,
isToolPermission: true,
isRelevantForAgents: false,
isRelevantForApiKeys: true,
isRelevantForUsers: true,
},
{
key: PermissionFlagType.CONNECTED_ACCOUNTS,
@@ -104,6 +133,9 @@ export const SettingsRolePermissionsToolSection = ({
description: t`Sync email and calendar accounts`,
Icon: IconAt,
isToolPermission: true,
isRelevantForAgents: false,
isRelevantForApiKeys: false,
isRelevantForUsers: true,
},
{
key: PermissionFlagType.PROFILE_INFORMATION,
@@ -111,6 +143,9 @@ export const SettingsRolePermissionsToolSection = ({
description: t`Edit own profile information`,
Icon: IconUser,
isToolPermission: true,
isRelevantForAgents: false,
isRelevantForApiKeys: false,
isRelevantForUsers: true,
},
{
key: PermissionFlagType.VIEWS,
@@ -118,6 +153,9 @@ export const SettingsRolePermissionsToolSection = ({
description: t`Create, edit, and delete workspace views`,
Icon: IconTable,
isToolPermission: true,
isRelevantForAgents: true,
isRelevantForApiKeys: true,
isRelevantForUsers: true,
},
];
@@ -125,29 +163,65 @@ export const SettingsRolePermissionsToolSection = ({
if (permission.key === PermissionFlagType.AI && !isAIEnabled) {
return false;
}
const canBeAssignedOnlyToAgents =
settingsDraftRole.canBeAssignedToAgents &&
!settingsDraftRole.canBeAssignedToUsers &&
!settingsDraftRole.canBeAssignedToApiKeys;
const canBeAssignedOnlyToApiKeys =
settingsDraftRole.canBeAssignedToApiKeys &&
!settingsDraftRole.canBeAssignedToUsers &&
!settingsDraftRole.canBeAssignedToAgents;
const canBeAssignedOnlyToUsers =
settingsDraftRole.canBeAssignedToUsers &&
!settingsDraftRole.canBeAssignedToAgents &&
!settingsDraftRole.canBeAssignedToApiKeys;
if (canBeAssignedOnlyToAgents && !permission.isRelevantForAgents) {
return false;
}
if (canBeAssignedOnlyToApiKeys && !permission.isRelevantForApiKeys) {
return false;
}
if (canBeAssignedOnlyToUsers && !permission.isRelevantForUsers) {
return false;
}
return true;
});
const shouldShowAllAccessToggle =
!settingsDraftRole.canBeAssignedToAgents ||
settingsDraftRole.canBeAssignedToUsers;
return (
<Section>
<H2Title title={t`Actions`} description={t`Actions permissions`} />
<StyledCard rounded>
<SettingsOptionCardContentToggle
Icon={IconTool}
title={t`All Actions Access`}
description={t`Grants permission to perform all available actions without restriction`}
checked={settingsDraftRole.canAccessAllTools}
disabled={!isEditable}
onChange={() => {
setSettingsDraftRole({
...settingsDraftRole,
canAccessAllTools: !settingsDraftRole.canAccessAllTools,
});
}}
/>
</StyledCard>
{shouldShowAllAccessToggle && (
<StyledCard rounded>
<SettingsOptionCardContentToggle
Icon={IconTool}
title={t`All Actions Access`}
description={t`Grants permission to perform all available actions without restriction`}
checked={settingsDraftRole.canAccessAllTools}
disabled={!isEditable}
onChange={() => {
setSettingsDraftRole({
...settingsDraftRole,
canAccessAllTools: !settingsDraftRole.canAccessAllTools,
});
}}
/>
</StyledCard>
)}
<AnimatedExpandableContainer
isExpanded={!settingsDraftRole.canAccessAllTools}
isExpanded={
!shouldShowAllAccessToggle || !settingsDraftRole.canAccessAllTools
}
dimension="height"
animationDurations={{
opacity: 0.2,
@@ -7,4 +7,7 @@ export type SettingsRolePermissionsSettingPermission = {
description: string;
Icon: IconComponent;
isToolPermission?: boolean;
isRelevantForAgents?: boolean;
isRelevantForApiKeys?: boolean;
isRelevantForUsers?: boolean;
};
@@ -56,7 +56,7 @@ export const SettingsRoleApplicability = ({
const options = [
{
key: 'canBeAssignedToUsers' as const,
label: t`Assignable to team members`,
label: t`Assignable to Workspace Members`,
Icon: IconUsers,
},
{