Pass chatId/messageId through agent pipeline for sub-agent access

- Add chatId/messageId to AgentToolContext
- Update BaseAgent.processConsultation to accept meta parameter
- Update agent-registry routeToActiveAgent to forward meta
- Fix session end detection to check __SESSION_END__ in finalResponse

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
kappa
2026-02-12 09:32:55 +09:00
parent 7dda198f47
commit b9484908c7
2 changed files with 16 additions and 6 deletions

View File

@@ -14,7 +14,8 @@ const logger = createLogger('agent-registry');
export interface RegisterableAgent {
hasSession(db: D1Database, userId: string): Promise<boolean>;
processConsultation(
db: D1Database, userId: string, userMessage: string, env: Env
db: D1Database, userId: string, userMessage: string, env: Env,
meta?: { chatId?: number; messageId?: number }
): Promise<string>;
}
@@ -53,7 +54,8 @@ export async function routeToActiveAgent(
db: D1Database,
userId: string,
userMessage: string,
env: Env
env: Env,
meta?: { chatId?: number; messageId?: number }
): Promise<AgentRouteResult | null> {
for (const entry of registry) {
try {
@@ -66,7 +68,7 @@ export async function routeToActiveAgent(
});
const response = await entry.agent.processConsultation(
db, userId, userMessage, env
db, userId, userMessage, env, meta
);
// PASSTHROUGH: 무관한 메시지, 다음 에이전트 확인

View File

@@ -22,6 +22,8 @@ export interface AgentToolContext {
userId: string;
env: Env;
db: D1Database;
chatId?: number;
messageId?: number;
}
export interface AgentAIResult {
@@ -71,7 +73,8 @@ export abstract class BaseAgent<TSession extends BaseSession> {
db: D1Database,
userId: string,
userMessage: string,
env: Env
env: Env,
meta?: { chatId?: number; messageId?: number }
): Promise<string> {
const log = createLogger(this.agentName);
const startTime = Date.now();
@@ -88,7 +91,11 @@ export abstract class BaseAgent<TSession extends BaseSession> {
this.sessionManager.addMessage(session, 'user', userMessage);
// 3. Call AI
const context: AgentToolContext = { userId, env, db };
const context: AgentToolContext = {
userId, env, db,
chatId: meta?.chatId,
messageId: meta?.messageId,
};
const aiResult = await this.callExpertAI(session, userMessage, env, context);
// 4. Handle PASSTHROUGH
@@ -114,8 +121,9 @@ export abstract class BaseAgent<TSession extends BaseSession> {
}
}
// 6. Detect session end (both markers)
// 6. Detect session end (both markers, check both finalResponse and aiResult)
const isSessionEnd = finalResponse.includes('[세션 종료]')
|| finalResponse.includes('__SESSION_END__')
|| aiResult.response.includes('__SESSION_END__');
if (isSessionEnd) {