MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / SwarmMode

Class SwarmMode

packages/agent-core/src/agent/swarm/index.ts:13–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11export type SwarmModeTrigger = 'manual' | 'task' | 'tool';
12
13export class SwarmMode {
14 protected active: SwarmModeTrigger | null = null;
15
16 constructor(protected readonly agent: Agent) {}
17
18 enter(trigger: SwarmModeTrigger): void {
19 if (this.active !== null) return;
20 this.agent.records.logRecord({ type: 'swarm_mode.enter', trigger });
21 this.active = trigger;
22 if (trigger !== 'tool') {
23 this.agent.context.appendSystemReminder(SWARM_MODE_ENTER_REMINDER, {
24 kind: 'injection',
25 variant: 'swarm_mode',
26 });
27 }
28 this.agent.emitStatusUpdated();
29 }
30
31 restoreEnter(trigger: SwarmModeTrigger): void {
32 this.active = trigger;
33 }
34
35 exit(): void {
36 if (this.active === null) return;
37 this.agent.records.logRecord({ type: 'swarm_mode.exit' });
38 const trigger = this.active;
39 this.active = null;
40 this.agent.emitStatusUpdated();
41 if (trigger === 'tool') return;
42 if (this.agent.context.popMatchedMessage((origin) => origin?.kind === 'injection' && origin.variant === 'swarm_mode')) {
43 return;
44 }
45 if (!this.agent.records.restoring) {
46 this.agent.context.appendSystemReminder(SWARM_MODE_EXIT_REMINDER, {
47 kind: 'injection',
48 variant: 'swarm_mode_exit',
49 });
50 }
51 }
52
53 get isActive(): boolean {
54 return this.active !== null;
55 }
56
57 get shouldAutoExit(): boolean {
58 return this.active === 'task' || this.active === 'tool';
59 }
60}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected