feat(orchestrator): MS23 agent lifecycle ingestion service (#701)
Some checks failed
ci/woodpecker/push/ci Pipeline failed
Some checks failed
ci/woodpecker/push/ci Pipeline failed
Co-authored-by: Jason Woltje <jason@diversecanvas.com> Co-committed-by: Jason Woltje <jason@diversecanvas.com>
This commit was merged in pull request #701.
This commit is contained in:
@@ -1,4 +1,11 @@
|
||||
import { Injectable, Logger, HttpException, HttpStatus, OnModuleDestroy } from "@nestjs/common";
|
||||
import {
|
||||
Injectable,
|
||||
Logger,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
OnModuleDestroy,
|
||||
Optional,
|
||||
} from "@nestjs/common";
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
import Anthropic from "@anthropic-ai/sdk";
|
||||
import { randomUUID } from "crypto";
|
||||
@@ -8,6 +15,7 @@ import {
|
||||
AgentSession,
|
||||
AgentType,
|
||||
} from "./types/agent-spawner.types";
|
||||
import { AgentIngestionService } from "../agent-ingestion/agent-ingestion.service";
|
||||
|
||||
/**
|
||||
* Default delay in milliseconds before cleaning up sessions after terminal states
|
||||
@@ -30,7 +38,10 @@ export class AgentSpawnerService implements OnModuleDestroy {
|
||||
private readonly sessionCleanupDelayMs: number;
|
||||
private readonly cleanupTimers = new Map<string, NodeJS.Timeout>();
|
||||
|
||||
constructor(private readonly configService: ConfigService) {
|
||||
constructor(
|
||||
private readonly configService: ConfigService,
|
||||
@Optional() private readonly agentIngestionService?: AgentIngestionService
|
||||
) {
|
||||
const configuredProvider = this.configService.get<string>("orchestrator.aiProvider");
|
||||
this.aiProvider = this.normalizeAiProvider(configuredProvider);
|
||||
|
||||
@@ -98,6 +109,19 @@ export class AgentSpawnerService implements OnModuleDestroy {
|
||||
this.cleanupTimers.clear();
|
||||
}
|
||||
|
||||
private recordSpawnedAgentIngestion(agentId: string, request: SpawnAgentRequest): void {
|
||||
if (!this.agentIngestionService) {
|
||||
return;
|
||||
}
|
||||
|
||||
void this.agentIngestionService
|
||||
.recordAgentSpawned(agentId, undefined, undefined, request.taskId, request.agentType)
|
||||
.catch((error: unknown) => {
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
this.logger.error(`Failed to record spawned ingestion for ${agentId}: ${errorMessage}`);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawn a new agent with the given configuration
|
||||
* @param request Agent spawn request
|
||||
@@ -130,6 +154,8 @@ export class AgentSpawnerService implements OnModuleDestroy {
|
||||
// Store session
|
||||
this.sessions.set(agentId, session);
|
||||
|
||||
this.recordSpawnedAgentIngestion(agentId, request);
|
||||
|
||||
this.logger.log(`Agent spawned successfully: ${agentId} (type: ${request.agentType})`);
|
||||
|
||||
// NOTE: Actual Claude SDK integration will be implemented in next iteration (see issue #TBD)
|
||||
|
||||
Reference in New Issue
Block a user