feat: Migrate documentation to Mintlify and implement Helper Agent with search functionality (#15443)
This commit is contained in:
+29
@@ -6,10 +6,13 @@ import { Repository } from 'typeorm';
|
||||
|
||||
import { ToolAdapterService } from 'src/engine/core-modules/ai/services/tool-adapter.service';
|
||||
import { ToolService } from 'src/engine/core-modules/ai/services/tool.service';
|
||||
import { SearchArticlesTool } from 'src/engine/core-modules/tool/tools/search-articles-tool/search-articles-tool';
|
||||
import { AgentEntity } from 'src/engine/metadata-modules/agent/agent.entity';
|
||||
import { type ActorMetadata } from 'src/engine/metadata-modules/field-metadata/composite-types/actor.composite-type';
|
||||
import { PermissionFlagType } from 'src/engine/metadata-modules/permissions/constants/permission-flag-type.constants';
|
||||
import { PermissionsService } from 'src/engine/metadata-modules/permissions/permissions.service';
|
||||
import { RoleEntity } from 'src/engine/metadata-modules/role/role.entity';
|
||||
import { HELPER_AGENT } from 'src/engine/workspace-manager/workspace-sync-metadata/standard-agents/agents/helper-agent';
|
||||
import { WorkflowToolWorkspaceService as WorkflowToolService } from 'src/modules/workflow/workflow-tools/services/workflow-tool.workspace-service';
|
||||
|
||||
@Injectable()
|
||||
@@ -19,10 +22,13 @@ export class AgentToolGeneratorService {
|
||||
constructor(
|
||||
@InjectRepository(RoleEntity)
|
||||
private readonly roleRepository: Repository<RoleEntity>,
|
||||
@InjectRepository(AgentEntity)
|
||||
private readonly agentRepository: Repository<AgentEntity>,
|
||||
private readonly toolAdapterService: ToolAdapterService,
|
||||
private readonly toolService: ToolService,
|
||||
private readonly workflowToolService: WorkflowToolService,
|
||||
private readonly permissionsService: PermissionsService,
|
||||
private readonly searchArticlesTool: SearchArticlesTool,
|
||||
) {}
|
||||
|
||||
async generateToolsForAgent(
|
||||
@@ -34,6 +40,14 @@ export class AgentToolGeneratorService {
|
||||
let tools: ToolSet = {};
|
||||
|
||||
try {
|
||||
const agent = await this.agentRepository.findOne({
|
||||
where: { id: agentId },
|
||||
});
|
||||
|
||||
if (agent?.standardId === HELPER_AGENT.standardId) {
|
||||
return this.getHelperAgentTools();
|
||||
}
|
||||
|
||||
const actionTools = await this.toolAdapterService.getTools();
|
||||
|
||||
tools = { ...actionTools };
|
||||
@@ -80,4 +94,19 @@ export class AgentToolGeneratorService {
|
||||
|
||||
return tools;
|
||||
}
|
||||
|
||||
private getHelperAgentTools(): ToolSet {
|
||||
const tools: ToolSet = {
|
||||
search_articles: {
|
||||
description: this.searchArticlesTool.description,
|
||||
inputSchema: this.searchArticlesTool.inputSchema,
|
||||
execute: async (params) =>
|
||||
this.searchArticlesTool.execute(params.input),
|
||||
},
|
||||
};
|
||||
|
||||
this.logger.log('Generated search_articles tool for Helper agent');
|
||||
|
||||
return tools;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,10 +10,11 @@ import {
|
||||
import { Repository } from 'typeorm';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { AI_TELEMETRY_CONFIG } from 'src/engine/core-modules/ai/constants/ai-telemetry.const';
|
||||
import { ModelId } from 'src/engine/core-modules/ai/constants/ai-models.const';
|
||||
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 { HELPER_AGENT } from 'src/engine/workspace-manager/workspace-sync-metadata/standard-agents/agents/helper-agent';
|
||||
|
||||
export interface AiRouterContext {
|
||||
messages: UIMessage<unknown, UIDataTypes, UITools>[];
|
||||
@@ -90,13 +91,12 @@ export class AiRouterService {
|
||||
(agent) => agent.id === result.object.agentId,
|
||||
);
|
||||
} catch (error) {
|
||||
this.logger.error('Routing to agent failed:', error);
|
||||
|
||||
const availableAgents = await this.getAvailableAgents(
|
||||
context.workspaceId,
|
||||
this.logger.error(
|
||||
'Routing to agent failed, falling back to Helper agent:',
|
||||
error,
|
||||
);
|
||||
|
||||
return availableAgents[0] || null;
|
||||
return this.getHelperAgent(context.workspaceId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,6 +109,17 @@ export class AiRouterService {
|
||||
});
|
||||
}
|
||||
|
||||
private async getHelperAgent(workspaceId: string) {
|
||||
const helperAgent = await this.agentRepository.findOne({
|
||||
where: {
|
||||
workspaceId,
|
||||
standardId: HELPER_AGENT.standardId,
|
||||
},
|
||||
});
|
||||
|
||||
return helperAgent;
|
||||
}
|
||||
|
||||
private getRouterModel(modelId: ModelId) {
|
||||
if (modelId === 'auto') {
|
||||
const registeredModel =
|
||||
|
||||
Reference in New Issue
Block a user