fix: single session per agent instance
One agent = one session. Chat, tasks, tools — all share the same
context. Session ID: 'agent-{slug}' (stable across restarts).
This commit is contained in:
parent
b2a620185f
commit
a8f205609b
@ -16,17 +16,20 @@ export class EventRouter {
|
|||||||
private log = logger.child({ component: 'event-router' });
|
private log = logger.child({ component: 'event-router' });
|
||||||
private activeTasks = 0;
|
private activeTasks = 0;
|
||||||
private trackerTools: ToolDefinition[];
|
private trackerTools: ToolDefinition[];
|
||||||
|
/** Single session ID for the entire agent lifetime. */
|
||||||
|
private readonly sessionId: string;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private config: AgentConfig,
|
private config: AgentConfig,
|
||||||
private client: TrackerClient,
|
private client: TrackerClient,
|
||||||
private taskTracker: TaskTracker,
|
private taskTracker: TaskTracker,
|
||||||
) {
|
) {
|
||||||
|
this.sessionId = `agent-${config.slug}`;
|
||||||
this.trackerTools = createTrackerTools({
|
this.trackerTools = createTrackerTools({
|
||||||
trackerClient: client,
|
trackerClient: client,
|
||||||
agentSlug: config.slug,
|
agentSlug: config.slug,
|
||||||
});
|
});
|
||||||
this.log.info({ toolCount: this.trackerTools.length }, 'Tracker tools registered');
|
this.log.info({ toolCount: this.trackerTools.length, sessionId: this.sessionId }, 'Tracker tools registered');
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleEvent(event: TrackerEvent): Promise<void> {
|
async handleEvent(event: TrackerEvent): Promise<void> {
|
||||||
@ -87,7 +90,7 @@ export class EventRouter {
|
|||||||
let collectedText = '';
|
let collectedText = '';
|
||||||
for await (const msg of runAgent(prompt, {
|
for await (const msg of runAgent(prompt, {
|
||||||
workDir: this.config.workDir,
|
workDir: this.config.workDir,
|
||||||
sessionId: `task-${task.id}`,
|
sessionId: this.sessionId,
|
||||||
model: this.config.model,
|
model: this.config.model,
|
||||||
provider: this.config.provider,
|
provider: this.config.provider,
|
||||||
systemPrompt: this.config.prompt || undefined,
|
systemPrompt: this.config.prompt || undefined,
|
||||||
@ -156,13 +159,10 @@ export class EventRouter {
|
|||||||
this.log.info('│ MESSAGE from @%s: "%s"', authorSlug, content.slice(0, 200));
|
this.log.info('│ MESSAGE from @%s: "%s"', authorSlug, content.slice(0, 200));
|
||||||
this.log.info('│ Context: %s | Mentioned: %s', taskId ? `task=${taskId}` : chatId ? `chat=${chatId}` : 'none', isMentioned);
|
this.log.info('│ Context: %s | Mentioned: %s', taskId ? `task=${taskId}` : chatId ? `chat=${chatId}` : 'none', isMentioned);
|
||||||
|
|
||||||
// Stable session ID per chat/task context — preserves conversation history
|
|
||||||
const sessionId = chatId ? `chat-${chatId}` : taskId ? `task-${taskId}` : `msg-${Date.now()}`;
|
|
||||||
|
|
||||||
let collectedText = '';
|
let collectedText = '';
|
||||||
for await (const msg of runAgent(content, {
|
for await (const msg of runAgent(content, {
|
||||||
workDir: this.config.workDir,
|
workDir: this.config.workDir,
|
||||||
sessionId,
|
sessionId: this.sessionId,
|
||||||
model: this.config.model,
|
model: this.config.model,
|
||||||
provider: this.config.provider,
|
provider: this.config.provider,
|
||||||
systemPrompt: this.config.prompt || undefined,
|
systemPrompt: this.config.prompt || undefined,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user