MCPcopy
hub / github.com/CopilotKit/CopilotKit / IntelligenceAgent

Class IntelligenceAgent

packages/core/src/intelligence-agent.ts:150–833  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

148}
149
150export class IntelligenceAgent extends AbstractAgent {
151 private config: IntelligenceAgentConfig;
152 private socket: Socket | null = null;
153 private activeChannel: Channel | null = null;
154 private canonicalRunId: string | null = null;
155 private sharedState: IntelligenceAgentSharedState;
156
157 constructor(
158 config: IntelligenceAgentConfig,
159 sharedState: IntelligenceAgentSharedState = {
160 lastSeenEventIds: new Map<string, string>(),
161 },
162 ) {
163 super();
164 this.config = config;
165 this.sharedState = sharedState;
166 }
167
168 clone(): IntelligenceAgent {
169 return new IntelligenceAgent(this.config, this.sharedState);
170 }
171
172 /**
173 * Override of AbstractAgent.connectAgent that removes the `verifyEvents` step.
174 *
175 * Background: AbstractAgent's connectAgent pipeline runs events through
176 * `verifyEvents`, which validates that the stream follows the AG-UI protocol
177 * lifecycle — specifically, it expects a RUN_STARTED event before any content
178 * events and a RUN_FINISHED/RUN_ERROR event to complete the stream.
179 *
180 * IntelligenceAgent uses long-lived WebSocket connections rather than
181 * request-scoped SSE streams. When connecting to replay historical messages
182 * for an existing thread, the connection semantics don't map to a single
183 * agent run start/stop cycle. The replayed events may not include
184 * RUN_STARTED/RUN_FINISHED bookends (or may contain events from multiple
185 * past runs), which causes verifyEvents to either never complete or to
186 * error out.
187 *
188 * This override replicates the base connectAgent implementation exactly,
189 * substituting only `transformChunks` (which is still needed for message
190 * reassembly) and omitting `verifyEvents`.
191 *
192 * TODO: Remove this override once AG-UI's AbstractAgent supports opting out
193 * of verifyEvents for transports with different connection life-cycles.
194 */
195 override async connectAgent(
196 parameters?: RunAgentParameters,
197 subscriber?: AgentSubscriber,
198 ): Promise<RunAgentResult> {
199 // Access private fields through a type escape hatch — these are set/read
200 // by the base class and must be managed identically to the original.
201 // Using `any` because these fields are private in AbstractAgent, and
202 // intersecting private+public members of the same name produces `never`.
203 // eslint-disable-next-line @typescript-eslint/no-explicit-any
204 const self = this as any;
205
206 try {
207 this.isRunning = true;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…