diff --git a/src/router.ts b/src/router.ts index 10a7b84..484610f 100644 --- a/src/router.ts +++ b/src/router.ts @@ -16,6 +16,8 @@ export class EventRouter { private log = logger.child({ component: 'event-router' }); private activeTasks = 0; private trackerTools: ToolDefinition[]; + /** Tasks taken via tool call (agent already knows about them — skip auto-processing) */ + private selfAssignedTasks = new Set(); constructor( private config: AgentConfig, private client: TrackerClient, @@ -24,6 +26,7 @@ export class EventRouter { this.trackerTools = createTrackerTools({ trackerClient: client, agentSlug: config.slug, + selfAssignedTasks: this.selfAssignedTasks, }); this.log.info({ toolCount: this.trackerTools.length }, 'Tracker tools registered'); } @@ -61,6 +64,13 @@ export class EventRouter { return; } + // Skip if agent took this task itself via tool call (already in conversation context) + if (this.selfAssignedTasks.has(task.id)) { + this.selfAssignedTasks.delete(task.id); + this.log.info('│ TASK %s self-assigned via tool, skipping auto-processing', task.key); + return; + } + if (this.activeTasks >= this.config.maxConcurrentTasks) { this.log.warn({ taskId: task.id, activeTasks: this.activeTasks }, 'Max concurrent tasks reached, skipping'); return; diff --git a/src/tools/tasks.ts b/src/tools/tasks.ts index bc2250e..b0d53e4 100644 --- a/src/tools/tasks.ts +++ b/src/tools/tasks.ts @@ -100,6 +100,7 @@ export function createTaskTools(ctx: ToolContext): ToolDefinition[] { description: 'Take a task for yourself (atomically assign to this agent). Task must be in backlog or todo status.', parameters: TakeTaskParams, async execute(_id: string, params: any) { + ctx.selfAssignedTasks.add(params.task_id); await ctx.trackerClient.takeTask(params.task_id, ctx.agentSlug); return ok(`Task ${params.task_id} taken by ${ctx.agentSlug}`); }, diff --git a/src/tools/types.ts b/src/tools/types.ts index a7ae20c..97fb9c2 100644 --- a/src/tools/types.ts +++ b/src/tools/types.ts @@ -4,4 +4,6 @@ import type { TrackerClient } from '../tracker/client.js'; export interface ToolContext { trackerClient: TrackerClient; agentSlug: string; + /** Track tasks taken via tool call — prevents duplicate auto-processing */ + selfAssignedTasks: Set; }