Merge data navigator and manipulator agents (#15761)
Merge data manipulator and navigator agents
This commit is contained in:
@@ -169,7 +169,7 @@ export class AgentExecutionService implements AgentExecutionContext {
|
||||
}
|
||||
}
|
||||
|
||||
private async getContextForSystemPrompt(
|
||||
async getContextForSystemPrompt(
|
||||
workspace: WorkspaceEntity,
|
||||
recordIdsByObjectMetadataNameSingular: RecordIdsByObjectMetadataNameSingularType,
|
||||
userWorkspaceId: string,
|
||||
|
||||
@@ -164,6 +164,7 @@ export class AgentStreamingService {
|
||||
state: 'routed',
|
||||
debug: {
|
||||
routingTimeMs: routingTime,
|
||||
contextBuildTimeMs: timings.contextBuildTimeMs,
|
||||
agentExecutionStartTimeMs: Date.now() - startTime,
|
||||
selectedAgentId: agent.id,
|
||||
selectedAgentLabel: agent.label,
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
import { isWorkflowRelatedObject } from 'src/engine/metadata-modules/agent/utils/is-workflow-related-object.util';
|
||||
import { type ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';
|
||||
|
||||
describe('isWorkflowRelatedObject', () => {
|
||||
it('should return true for workflow-related objects', () => {
|
||||
expect(
|
||||
isWorkflowRelatedObject({
|
||||
standardId: STANDARD_OBJECT_IDS.workflow,
|
||||
} as ObjectMetadataEntity),
|
||||
).toBe(true);
|
||||
|
||||
expect(
|
||||
isWorkflowRelatedObject({
|
||||
standardId: STANDARD_OBJECT_IDS.workflowRun,
|
||||
} as ObjectMetadataEntity),
|
||||
).toBe(true);
|
||||
|
||||
expect(
|
||||
isWorkflowRelatedObject({
|
||||
standardId: STANDARD_OBJECT_IDS.workflowVersion,
|
||||
} as ObjectMetadataEntity),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for non-workflow objects', () => {
|
||||
expect(
|
||||
isWorkflowRelatedObject({
|
||||
standardId: STANDARD_OBJECT_IDS.person,
|
||||
} as ObjectMetadataEntity),
|
||||
).toBe(false);
|
||||
|
||||
expect(
|
||||
isWorkflowRelatedObject({
|
||||
standardId: null,
|
||||
} as ObjectMetadataEntity),
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
import { type ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';
|
||||
|
||||
// All workflow-related standard object IDs that should be filtered out from agent access
|
||||
const WORKFLOW_STANDARD_OBJECT_IDS = [
|
||||
STANDARD_OBJECT_IDS.workflow,
|
||||
STANDARD_OBJECT_IDS.workflowRun,
|
||||
STANDARD_OBJECT_IDS.workflowVersion,
|
||||
STANDARD_OBJECT_IDS.workflowAutomatedTrigger,
|
||||
] as const;
|
||||
|
||||
export const isWorkflowRelatedObject = (
|
||||
objectMetadata: ObjectMetadataEntity,
|
||||
): boolean => {
|
||||
return (
|
||||
objectMetadata.standardId !== null &&
|
||||
WORKFLOW_STANDARD_OBJECT_IDS.includes(
|
||||
objectMetadata.standardId as (typeof WORKFLOW_STANDARD_OBJECT_IDS)[number],
|
||||
)
|
||||
);
|
||||
};
|
||||
+14
-7
@@ -1,14 +1,21 @@
|
||||
import { type ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';
|
||||
|
||||
const WORKFLOW_OBJECT_NAMES = ['workflowVersion', 'workflowRun'];
|
||||
// All workflow-related standard object IDs that should be filtered out from agent access
|
||||
const WORKFLOW_STANDARD_OBJECT_IDS = [
|
||||
STANDARD_OBJECT_IDS.workflow,
|
||||
STANDARD_OBJECT_IDS.workflowRun,
|
||||
STANDARD_OBJECT_IDS.workflowVersion,
|
||||
STANDARD_OBJECT_IDS.workflowAutomatedTrigger,
|
||||
] as const;
|
||||
|
||||
export const isWorkflowRunObject = (
|
||||
export const isWorkflowRelatedObject = (
|
||||
objectMetadata: ObjectMetadataEntity,
|
||||
): boolean => {
|
||||
if (objectMetadata.standardId) {
|
||||
return objectMetadata.standardId === STANDARD_OBJECT_IDS.workflowRun;
|
||||
}
|
||||
|
||||
return WORKFLOW_OBJECT_NAMES.includes(objectMetadata.nameSingular);
|
||||
return (
|
||||
objectMetadata.standardId !== null &&
|
||||
WORKFLOW_STANDARD_OBJECT_IDS.includes(
|
||||
objectMetadata.standardId as (typeof WORKFLOW_STANDARD_OBJECT_IDS)[number],
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
@@ -4,11 +4,16 @@ import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { AiModule } from 'src/engine/core-modules/ai/ai.module';
|
||||
import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { AgentEntity } from 'src/engine/metadata-modules/agent/agent.entity';
|
||||
import { ObjectMetadataModule } from 'src/engine/metadata-modules/object-metadata/object-metadata.module';
|
||||
|
||||
import { AiRouterService } from './ai-router.service';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([AgentEntity, WorkspaceEntity]), AiModule],
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([AgentEntity, WorkspaceEntity]),
|
||||
AiModule,
|
||||
ObjectMetadataModule,
|
||||
],
|
||||
providers: [AiRouterService],
|
||||
exports: [AiRouterService],
|
||||
})
|
||||
|
||||
@@ -14,6 +14,9 @@ import { type ModelId } from 'src/engine/core-modules/ai/constants/ai-models.con
|
||||
import { AI_TELEMETRY_CONFIG } from 'src/engine/core-modules/ai/constants/ai-telemetry.const';
|
||||
import { AiModelRegistryService } from 'src/engine/core-modules/ai/services/ai-model-registry.service';
|
||||
import { AgentEntity } from 'src/engine/metadata-modules/agent/agent.entity';
|
||||
import { isWorkflowRelatedObject } from 'src/engine/metadata-modules/agent/utils/is-workflow-related-object.util';
|
||||
import { ObjectMetadataService } from 'src/engine/metadata-modules/object-metadata/object-metadata.service';
|
||||
import { DATA_MANIPULATOR_AGENT } from 'src/engine/workspace-manager/workspace-sync-metadata/standard-agents/agents/data-manipulator-agent';
|
||||
import { HELPER_AGENT } from 'src/engine/workspace-manager/workspace-sync-metadata/standard-agents/agents/helper-agent';
|
||||
|
||||
export interface AiRouterContext {
|
||||
@@ -41,6 +44,7 @@ export class AiRouterService {
|
||||
@InjectRepository(AgentEntity)
|
||||
private readonly agentRepository: Repository<AgentEntity>,
|
||||
private readonly aiModelRegistryService: AiModelRegistryService,
|
||||
private readonly objectMetadataService: ObjectMetadataService,
|
||||
) {}
|
||||
|
||||
async routeMessage(
|
||||
@@ -88,7 +92,12 @@ export class AiRouterService {
|
||||
)?.text || '';
|
||||
|
||||
const model = this.getRouterModel(routerModel);
|
||||
const agentDescriptions = this.buildAgentDescriptions(availableAgents);
|
||||
const workspaceObjectsList =
|
||||
await this.buildWorkspaceObjectsList(workspaceId);
|
||||
const agentDescriptions = this.buildAgentDescriptions(
|
||||
availableAgents,
|
||||
workspaceObjectsList,
|
||||
);
|
||||
|
||||
const systemPrompt = this.buildRouterSystemPrompt(agentDescriptions);
|
||||
const userPrompt = this.buildRouterUserPrompt(
|
||||
@@ -193,9 +202,55 @@ export class AiRouterService {
|
||||
return registeredModel.model;
|
||||
}
|
||||
|
||||
private buildAgentDescriptions(agents: AgentEntity[]): string {
|
||||
private async buildWorkspaceObjectsList(
|
||||
workspaceId: string,
|
||||
): Promise<string> {
|
||||
try {
|
||||
const objects = await this.objectMetadataService.findManyWithinWorkspace(
|
||||
workspaceId,
|
||||
{
|
||||
where: { isActive: true, isSystem: false },
|
||||
},
|
||||
);
|
||||
|
||||
const filteredObjects = objects.filter(
|
||||
(obj) => !isWorkflowRelatedObject(obj),
|
||||
);
|
||||
|
||||
if (filteredObjects.length === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return filteredObjects
|
||||
.map((obj) => `- ${obj.labelSingular} (${obj.nameSingular})`)
|
||||
.join('\n');
|
||||
} catch (error) {
|
||||
this.logger.warn('Failed to build workspace objects list:', error);
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
private buildAgentDescriptions(
|
||||
agents: AgentEntity[],
|
||||
workspaceObjectsList: string,
|
||||
): string {
|
||||
return agents
|
||||
.map((agent) => `- ${agent.label} (${agent.id}): ${agent.description}`)
|
||||
.map((agent) => {
|
||||
const baseDescription = `- ${agent.label} (${agent.id}): ${agent.description}`;
|
||||
|
||||
if (
|
||||
agent.standardId === DATA_MANIPULATOR_AGENT.standardId &&
|
||||
workspaceObjectsList
|
||||
) {
|
||||
return `${baseDescription}
|
||||
|
||||
Available workspace objects:
|
||||
${workspaceObjectsList}`;
|
||||
}
|
||||
|
||||
return baseDescription;
|
||||
})
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user