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:
@@ -14,7 +14,8 @@ const logger = createLogger('agent-registry');
|
|||||||
export interface RegisterableAgent {
|
export interface RegisterableAgent {
|
||||||
hasSession(db: D1Database, userId: string): Promise<boolean>;
|
hasSession(db: D1Database, userId: string): Promise<boolean>;
|
||||||
processConsultation(
|
processConsultation(
|
||||||
db: D1Database, userId: string, userMessage: string, env: Env
|
db: D1Database, userId: string, userMessage: string, env: Env,
|
||||||
|
meta?: { chatId?: number; messageId?: number }
|
||||||
): Promise<string>;
|
): Promise<string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,7 +54,8 @@ export async function routeToActiveAgent(
|
|||||||
db: D1Database,
|
db: D1Database,
|
||||||
userId: string,
|
userId: string,
|
||||||
userMessage: string,
|
userMessage: string,
|
||||||
env: Env
|
env: Env,
|
||||||
|
meta?: { chatId?: number; messageId?: number }
|
||||||
): Promise<AgentRouteResult | null> {
|
): Promise<AgentRouteResult | null> {
|
||||||
for (const entry of registry) {
|
for (const entry of registry) {
|
||||||
try {
|
try {
|
||||||
@@ -66,7 +68,7 @@ export async function routeToActiveAgent(
|
|||||||
});
|
});
|
||||||
|
|
||||||
const response = await entry.agent.processConsultation(
|
const response = await entry.agent.processConsultation(
|
||||||
db, userId, userMessage, env
|
db, userId, userMessage, env, meta
|
||||||
);
|
);
|
||||||
|
|
||||||
// PASSTHROUGH: 무관한 메시지, 다음 에이전트 확인
|
// PASSTHROUGH: 무관한 메시지, 다음 에이전트 확인
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ export interface AgentToolContext {
|
|||||||
userId: string;
|
userId: string;
|
||||||
env: Env;
|
env: Env;
|
||||||
db: D1Database;
|
db: D1Database;
|
||||||
|
chatId?: number;
|
||||||
|
messageId?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AgentAIResult {
|
export interface AgentAIResult {
|
||||||
@@ -71,7 +73,8 @@ export abstract class BaseAgent<TSession extends BaseSession> {
|
|||||||
db: D1Database,
|
db: D1Database,
|
||||||
userId: string,
|
userId: string,
|
||||||
userMessage: string,
|
userMessage: string,
|
||||||
env: Env
|
env: Env,
|
||||||
|
meta?: { chatId?: number; messageId?: number }
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const log = createLogger(this.agentName);
|
const log = createLogger(this.agentName);
|
||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
@@ -88,7 +91,11 @@ export abstract class BaseAgent<TSession extends BaseSession> {
|
|||||||
this.sessionManager.addMessage(session, 'user', userMessage);
|
this.sessionManager.addMessage(session, 'user', userMessage);
|
||||||
|
|
||||||
// 3. Call AI
|
// 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);
|
const aiResult = await this.callExpertAI(session, userMessage, env, context);
|
||||||
|
|
||||||
// 4. Handle PASSTHROUGH
|
// 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('[세션 종료]')
|
const isSessionEnd = finalResponse.includes('[세션 종료]')
|
||||||
|
|| finalResponse.includes('__SESSION_END__')
|
||||||
|| aiResult.response.includes('__SESSION_END__');
|
|| aiResult.response.includes('__SESSION_END__');
|
||||||
|
|
||||||
if (isSessionEnd) {
|
if (isSessionEnd) {
|
||||||
|
|||||||
Reference in New Issue
Block a user