e7ebf51e50
## Overview This PR replaces the dynamic agent handoff system with a more predictable planning-based router that decides upfront how to handle multi-agent coordination. ## Major Changes ### 🔄 Architecture Shift: Handoffs → Planning **Removed:** - `AgentHandoffEntity` and handoff tracking system - `AgentHandoffService` and `AgentHandoffExecutorService` - Dynamic agent-to-agent transfers during execution - Handoff tool generation and description templates **Added:** - `AiRouterService` with two strategies: `simple` (single agent) and `planned` (multi-agent) - `AgentPlanExecutorService` for executing multi-step plans - Plan validation (cycle detection, dependency resolution) - `UnifiedRouterResult` type with discriminated union ### 🤖 New Standard Agents Added two new specialized agents: - **Researcher Agent**: Web search, fact-finding, competitive intelligence - **Code Agent**: TypeScript function generation for serverless workflows ### 🏗️ Router Refactoring (Latest) Split router responsibilities into focused services: - `AiRouterStrategyDeciderService`: Decides simple vs planned strategy - `AiRouterPlanGeneratorService`: Generates and validates execution plans - `AiRouterService`: Coordinates between services (reduced from 426→275 lines) ### ⚙️ Configuration Improvements - Added `outputStrategy` to agent definitions (`direct` vs `synthesize`) - Removed hardcoded special cases for workflow-builder - Added `plannerModel` field to workspace entity - Increased `MAX_STEPS` from 10 to 25 for complex workflows ### 📝 Agent Prompt Refinements Significantly simplified prompts for better clarity: - Workflow Builder: 51→36 lines - Helper: 49→28 lines - Data Manipulator: Enhanced with sorting guidance ### 🔍 Enhanced Debugging - Plan reasoning and step count in data message parts - Router debug info with token usage tracking - Better logging throughout execution pipeline ## Benefits 1. **Simpler Mental Model**: Router decides upfront vs dynamic transfers 2. **Better Predictability**: Users see the plan before execution 3. **Cleaner Architecture**: SRP with focused services 4. **Configuration Over Code**: Agent behavior via config, not hardcoded logic 5. **Plan Validation**: Catches invalid dependencies and cycles ## Migration Notes - Database migration removes `agentHandoff` table - Adds `plannerModel` column to workspace table - No API breaking changes (agent endpoints unchanged) ## Testing - Integration tests updated to remove handoff dependencies - Agent tool test utilities simplified - Plan validation covered by new logic ## Next Steps (Future PRs) - Parallel execution of independent plan steps - Dynamic re-planning based on results - Plan caching for common routing patterns - Error recovery strategies in plan executor
43 lines
2.2 KiB
TypeScript
43 lines
2.2 KiB
TypeScript
import { Global, Module } from '@nestjs/common';
|
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
|
|
import { ToolAdapterService } from 'src/engine/metadata-modules/ai-tools/services/tool-adapter.service';
|
|
import { ToolService } from 'src/engine/metadata-modules/ai-tools/services/tool.service';
|
|
import { TokenModule } from 'src/engine/core-modules/auth/token/token.module';
|
|
import { FeatureFlagModule } from 'src/engine/core-modules/feature-flag/feature-flag.module';
|
|
import { FileEntity } from 'src/engine/core-modules/file/entities/file.entity';
|
|
import { FileModule } from 'src/engine/core-modules/file/file.module';
|
|
import { RecordCrudModule } from 'src/engine/core-modules/record-crud/record-crud.module';
|
|
import { ToolModule } from 'src/engine/core-modules/tool/tool.module';
|
|
import { SearchArticlesTool } from 'src/engine/core-modules/tool/tools/search-articles-tool/search-articles-tool';
|
|
import { ObjectMetadataModule } from 'src/engine/metadata-modules/object-metadata/object-metadata.module';
|
|
import { PermissionsModule } from 'src/engine/metadata-modules/permissions/permissions.module';
|
|
import { RoleEntity } from 'src/engine/metadata-modules/role/role.entity';
|
|
import { UserRoleModule } from 'src/engine/metadata-modules/user-role/user-role.module';
|
|
import { WorkspacePermissionsCacheModule } from 'src/engine/metadata-modules/workspace-permissions-cache/workspace-permissions-cache.module';
|
|
import { TwentyORMModule } from 'src/engine/twenty-orm/twenty-orm.module';
|
|
import { WorkspaceCacheStorageModule } from 'src/engine/workspace-cache-storage/workspace-cache-storage.module';
|
|
import { MessagingModule } from 'src/modules/messaging/messaging.module';
|
|
|
|
@Global()
|
|
@Module({
|
|
imports: [
|
|
TypeOrmModule.forFeature([RoleEntity, FileEntity]),
|
|
FileModule,
|
|
TokenModule,
|
|
FeatureFlagModule,
|
|
RecordCrudModule,
|
|
ObjectMetadataModule,
|
|
WorkspacePermissionsCacheModule,
|
|
WorkspaceCacheStorageModule,
|
|
UserRoleModule,
|
|
TwentyORMModule,
|
|
MessagingModule,
|
|
PermissionsModule,
|
|
ToolModule,
|
|
],
|
|
providers: [ToolService, ToolAdapterService, SearchArticlesTool],
|
|
exports: [ToolService, ToolAdapterService, SearchArticlesTool],
|
|
})
|
|
export class AiToolsModule {}
|