@cogitator-ai/worker 0.8.10 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -14
- package/dist/distributed-swarm-worker.d.ts +12 -0
- package/dist/distributed-swarm-worker.d.ts.map +1 -1
- package/dist/distributed-swarm-worker.js +51 -1
- package/dist/distributed-swarm-worker.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/processors/agent.d.ts +5 -13
- package/dist/processors/agent.d.ts.map +1 -1
- package/dist/processors/agent.js +20 -44
- package/dist/processors/agent.js.map +1 -1
- package/dist/processors/shared.d.ts +10 -38
- package/dist/processors/shared.d.ts.map +1 -1
- package/dist/processors/shared.js +9 -62
- package/dist/processors/shared.js.map +1 -1
- package/dist/processors/swarm-agent.d.ts +3 -3
- package/dist/processors/swarm-agent.d.ts.map +1 -1
- package/dist/processors/swarm-agent.js +5 -10
- package/dist/processors/swarm-agent.js.map +1 -1
- package/dist/processors/swarm.d.ts +11 -3
- package/dist/processors/swarm.d.ts.map +1 -1
- package/dist/processors/swarm.js +73 -7
- package/dist/processors/swarm.js.map +1 -1
- package/dist/processors/workflow.d.ts +2 -2
- package/dist/processors/workflow.d.ts.map +1 -1
- package/dist/processors/workflow.js +53 -28
- package/dist/processors/workflow.js.map +1 -1
- package/dist/queue.d.ts +36 -3
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +52 -2
- package/dist/queue.js.map +1 -1
- package/dist/serialize.d.ts +11 -6
- package/dist/serialize.d.ts.map +1 -1
- package/dist/serialize.js +10 -30
- package/dist/serialize.js.map +1 -1
- package/dist/types.d.ts +64 -63
- package/dist/types.d.ts.map +1 -1
- package/dist/worker.d.ts +18 -3
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +57 -10
- package/dist/worker.js.map +1 -1
- package/package.json +7 -6
package/dist/serialize.d.ts
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
import type { Agent
|
|
2
|
-
import
|
|
1
|
+
import type { Agent } from '@cogitator-ai/types';
|
|
2
|
+
import { toAgentWireResponseFormat } from '@cogitator-ai/core';
|
|
3
|
+
import type { SerializedAgent } from './types.js';
|
|
3
4
|
/**
|
|
4
5
|
* An agent's response format in its queue form: a Zod schema becomes JSON Schema, which the
|
|
5
6
|
* worker turns back into a schema to validate the run's structured output.
|
|
6
7
|
*/
|
|
7
|
-
export declare
|
|
8
|
+
export declare const serializeResponseFormat: typeof toAgentWireResponseFormat;
|
|
8
9
|
/**
|
|
9
|
-
* An agent as a queue job carries it
|
|
10
|
-
*
|
|
10
|
+
* An agent as a queue job carries it, in the agent wire format shared with workflow jobs and
|
|
11
|
+
* distributed swarms (`toAgentWire` from `@cogitator-ai/core`): its whole configuration
|
|
12
|
+
* (model and provider, instructions, sampling, stop sequences, reasoning, response format,
|
|
13
|
+
* iteration limit, timeout), the schemas of its tools (the worker resolves tools by name from its
|
|
14
|
+
* own registry) and every agent it can hand over to. An explicit `provider` also prefixes the
|
|
15
|
+
* model, so the job runs on the route the agent takes in-process.
|
|
11
16
|
*
|
|
12
|
-
* @throws
|
|
17
|
+
* @throws AgentWireError when the agent has no model: a queued job cannot fall back to the
|
|
13
18
|
* submitting process's default model
|
|
14
19
|
*/
|
|
15
20
|
export declare function serializeAgent(agent: Agent): SerializedAgent;
|
package/dist/serialize.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../src/serialize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../src/serialize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAe,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C;;;GAGG;AACH,eAAO,MAAM,uBAAuB,kCAA4B,CAAC;AAEjE;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,eAAe,CAE5D"}
|
package/dist/serialize.js
CHANGED
|
@@ -1,41 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { toAgentWire, toAgentWireResponseFormat } from '@cogitator-ai/core';
|
|
2
2
|
/**
|
|
3
3
|
* An agent's response format in its queue form: a Zod schema becomes JSON Schema, which the
|
|
4
4
|
* worker turns back into a schema to validate the run's structured output.
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
7
|
-
if (format?.type !== 'json_schema')
|
|
8
|
-
return format;
|
|
9
|
-
const schema = z.toJSONSchema(format.schema, { unrepresentable: 'any' });
|
|
10
|
-
delete schema.$schema;
|
|
11
|
-
return { type: 'json_schema', schema };
|
|
12
|
-
}
|
|
6
|
+
export const serializeResponseFormat = toAgentWireResponseFormat;
|
|
13
7
|
/**
|
|
14
|
-
* An agent as a queue job carries it
|
|
15
|
-
*
|
|
8
|
+
* An agent as a queue job carries it, in the agent wire format shared with workflow jobs and
|
|
9
|
+
* distributed swarms (`toAgentWire` from `@cogitator-ai/core`): its whole configuration
|
|
10
|
+
* (model and provider, instructions, sampling, stop sequences, reasoning, response format,
|
|
11
|
+
* iteration limit, timeout), the schemas of its tools (the worker resolves tools by name from its
|
|
12
|
+
* own registry) and every agent it can hand over to. An explicit `provider` also prefixes the
|
|
13
|
+
* model, so the job runs on the route the agent takes in-process.
|
|
16
14
|
*
|
|
17
|
-
* @throws
|
|
15
|
+
* @throws AgentWireError when the agent has no model: a queued job cannot fall back to the
|
|
18
16
|
* submitting process's default model
|
|
19
17
|
*/
|
|
20
18
|
export function serializeAgent(agent) {
|
|
21
|
-
|
|
22
|
-
if (!config.model) {
|
|
23
|
-
throw new Error(`Agent "${agent.name}" has no model; set one before queueing it`);
|
|
24
|
-
}
|
|
25
|
-
const responseFormat = serializeResponseFormat(config.responseFormat);
|
|
26
|
-
return {
|
|
27
|
-
name: agent.name,
|
|
28
|
-
instructions: config.instructions,
|
|
29
|
-
model: config.model,
|
|
30
|
-
...(config.provider !== undefined && { provider: config.provider }),
|
|
31
|
-
...(config.temperature !== undefined && { temperature: config.temperature }),
|
|
32
|
-
...(config.topP !== undefined && { topP: config.topP }),
|
|
33
|
-
...(config.maxTokens !== undefined && { maxTokens: config.maxTokens }),
|
|
34
|
-
...(config.maxIterations !== undefined && { maxIterations: config.maxIterations }),
|
|
35
|
-
...(config.onIterationLimit !== undefined && { onIterationLimit: config.onIterationLimit }),
|
|
36
|
-
...(config.reasoning !== undefined && { reasoning: config.reasoning }),
|
|
37
|
-
...(responseFormat && { responseFormat }),
|
|
38
|
-
tools: agent.tools.map((tool) => tool.toJSON()),
|
|
39
|
-
};
|
|
19
|
+
return toAgentWire(agent);
|
|
40
20
|
}
|
|
41
21
|
//# sourceMappingURL=serialize.js.map
|
package/dist/serialize.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serialize.js","sourceRoot":"","sources":["../src/serialize.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"serialize.js","sourceRoot":"","sources":["../src/serialize.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAG5E;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,yBAAyB,CAAC;AAEjE;;;;;;;;;;GAUG;AACH,MAAM,UAAU,cAAc,CAAC,KAAY;IACzC,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC;AAC5B,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -2,54 +2,22 @@
|
|
|
2
2
|
* Worker types for distributed job processing
|
|
3
3
|
*/
|
|
4
4
|
import type { Cogitator } from '@cogitator-ai/core';
|
|
5
|
-
import type {
|
|
5
|
+
import type { AgentWireConfig, AgentWireResponseFormat, AgentWireRunResult, AgentWireUsage, RunCheckpoint, Tool, ToolApprovalDecision } from '@cogitator-ai/types';
|
|
6
6
|
import type { SwarmAgentJobPayload as SwarmAgentJobContract, SwarmAgentJobResult as SwarmAgentJobResultContract } from '@cogitator-ai/swarms';
|
|
7
7
|
/**
|
|
8
8
|
* An agent's response format in a form that travels through the queue: a Zod schema becomes
|
|
9
9
|
* JSON Schema (see `serializeAgent`), and the worker turns it back into a schema to validate the
|
|
10
10
|
* run's structured output.
|
|
11
11
|
*/
|
|
12
|
-
export type SerializedResponseFormat =
|
|
13
|
-
type: 'text';
|
|
14
|
-
} | {
|
|
15
|
-
type: 'json';
|
|
16
|
-
} | {
|
|
17
|
-
type: 'json_schema';
|
|
18
|
-
schema: Record<string, unknown>;
|
|
19
|
-
};
|
|
12
|
+
export type SerializedResponseFormat = AgentWireResponseFormat;
|
|
20
13
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
14
|
+
* An agent as a job carries it: the agent wire format of `@cogitator-ai/core`, shared by agent,
|
|
15
|
+
* workflow and swarm jobs and by distributed swarm turns. Build it with `serializeAgent`, or
|
|
16
|
+
* write it by hand. Tools travel as schemas and are resolved by name from the worker's tool
|
|
17
|
+
* registry. A config with a key the worker does not know is refused, so a newer producer never
|
|
18
|
+
* runs an agent without a setting it asked for.
|
|
23
19
|
*/
|
|
24
|
-
export
|
|
25
|
-
name: string;
|
|
26
|
-
instructions: string;
|
|
27
|
-
/**
|
|
28
|
-
* Model string, routed on the worker like the same agent in-process: a prefix naming a
|
|
29
|
-
* built-in provider, a backend in the worker Cogitator's `llm.backends` or a registered
|
|
30
|
-
* plugin picks that provider (e.g. 'openai/gpt-6.1-sol', 'openrouter/deepseek/deepseek-v4-pro')
|
|
31
|
-
*/
|
|
32
|
-
model: string;
|
|
33
|
-
/**
|
|
34
|
-
* Provider for a model whose prefix names none the worker routes to (e.g. 'gpt-6.1-sol'
|
|
35
|
-
* or 'meta-llama/llama-4-scout' with `provider: 'openrouter'`). Any provider the worker
|
|
36
|
-
* Cogitator routes to, custom backends and plugins included. Without it such a model runs
|
|
37
|
-
* on the worker's `llm.defaultProvider`
|
|
38
|
-
*/
|
|
39
|
-
provider?: LLMBackendProvider;
|
|
40
|
-
temperature?: number;
|
|
41
|
-
topP?: number;
|
|
42
|
-
maxTokens?: number;
|
|
43
|
-
maxIterations?: number;
|
|
44
|
-
/** What happens when tool calls use up `maxIterations`, as in `AgentConfig.onIterationLimit` */
|
|
45
|
-
onIterationLimit?: 'answer' | 'stop';
|
|
46
|
-
/** Structured output: the job result carries `structured` when the run's answer fits */
|
|
47
|
-
responseFormat?: SerializedResponseFormat;
|
|
48
|
-
/** Reasoning effort and summaries, as in `AgentConfig.reasoning` */
|
|
49
|
-
reasoning?: ReasoningConfig;
|
|
50
|
-
/** Tool schemas; tools are resolved by name from the worker's tool registry */
|
|
51
|
-
tools: ToolSchema[];
|
|
52
|
-
}
|
|
20
|
+
export type SerializedAgent = AgentWireConfig;
|
|
53
21
|
/**
|
|
54
22
|
* Serialized workflow configuration
|
|
55
23
|
*
|
|
@@ -81,7 +49,11 @@ export interface AgentNodeConfig {
|
|
|
81
49
|
agentConfig: SerializedAgent;
|
|
82
50
|
/** Prompt template; `{{path}}` placeholders read from workflow state. Defaults to the state as JSON */
|
|
83
51
|
prompt?: string;
|
|
84
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* State key that receives the agent's answer (default: node id): its validated structured
|
|
54
|
+
* answer when the agent has a JSON schema response format and the answer fits, its text
|
|
55
|
+
* otherwise
|
|
56
|
+
*/
|
|
85
57
|
outputKey?: string;
|
|
86
58
|
}
|
|
87
59
|
export type TransformOperation = 'uppercase' | 'lowercase' | 'trim' | 'json-parse' | 'json-stringify' | 'template';
|
|
@@ -101,24 +73,53 @@ export interface ConditionNodeConfig {
|
|
|
101
73
|
operator: ConditionOperator;
|
|
102
74
|
value?: string | number | boolean | null;
|
|
103
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* How a swarm job's agents work together:
|
|
78
|
+
* - `sequential`: a pipeline, each agent working on the previous agent's output
|
|
79
|
+
* - `hierarchical`: the coordinator supervises the agents and delegates to them
|
|
80
|
+
* - `collaborative`: in each of `maxRounds` rounds every agent contributes in turn, seeing the
|
|
81
|
+
* task and all contributions so far; the coordinator, if any, combines them into the answer,
|
|
82
|
+
* otherwise the last contribution is the answer
|
|
83
|
+
* - `debate`: the agents debate for `maxRounds` rounds, the coordinator moderates
|
|
84
|
+
* - `voting`: the agents vote until `consensusThreshold` is reached, the coordinator breaks ties
|
|
85
|
+
*/
|
|
86
|
+
export type SwarmTopology = 'sequential' | 'hierarchical' | 'collaborative' | 'debate' | 'voting';
|
|
104
87
|
/**
|
|
105
88
|
* Serialized swarm configuration
|
|
106
89
|
*/
|
|
107
90
|
export interface SerializedSwarm {
|
|
108
|
-
topology:
|
|
91
|
+
topology: SwarmTopology;
|
|
109
92
|
agents: SerializedAgent[];
|
|
110
93
|
coordinator?: SerializedAgent;
|
|
111
94
|
maxRounds?: number;
|
|
112
95
|
consensusThreshold?: number;
|
|
113
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* How an agent job continues a run that paused for tool approvals, see `JobQueue.resumeAgentJob`.
|
|
99
|
+
*/
|
|
100
|
+
export interface AgentJobResume {
|
|
101
|
+
/**
|
|
102
|
+
* The paused run's checkpoint, as the paused job's result carries it. Without it the worker
|
|
103
|
+
* looks the run up by the job's `threadId` in its Cogitator's `runCheckpoints` store, which
|
|
104
|
+
* then has to be shared by the workers (a memory adapter or your own store)
|
|
105
|
+
*/
|
|
106
|
+
checkpoint?: RunCheckpoint;
|
|
107
|
+
/** Decisions for the waiting calls, by tool call id; calls left out pause the run again */
|
|
108
|
+
decisions?: Record<string, ToolApprovalDecision>;
|
|
109
|
+
/** Decision for every waiting call `decisions` leaves out, e.g. one "approve all" answer */
|
|
110
|
+
defaultDecision?: ToolApprovalDecision;
|
|
111
|
+
}
|
|
114
112
|
export interface AgentJobPayload {
|
|
115
113
|
type: 'agent';
|
|
116
114
|
jobId: string;
|
|
117
115
|
agentConfig: SerializedAgent;
|
|
116
|
+
/** The task; unused when the job resumes a paused run */
|
|
118
117
|
input: string;
|
|
119
118
|
threadId: string;
|
|
120
119
|
/** User the run acts for: owns the thread, see `RunOptions.userId` */
|
|
121
120
|
userId?: string;
|
|
121
|
+
/** Continue a paused run with these decisions instead of starting a new one */
|
|
122
|
+
resume?: AgentJobResume;
|
|
122
123
|
metadata?: Record<string, unknown>;
|
|
123
124
|
}
|
|
124
125
|
export interface WorkflowJobPayload {
|
|
@@ -142,28 +143,17 @@ export interface SwarmJobPayload {
|
|
|
142
143
|
export type SwarmAgentJobPayload = SwarmAgentJobContract;
|
|
143
144
|
export type JobPayload = AgentJobPayload | WorkflowJobPayload | SwarmJobPayload | SwarmAgentJobPayload;
|
|
144
145
|
/** What an agent run used and cost, as `RunResult.usage` reports it. */
|
|
145
|
-
export
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
export interface AgentJobResult {
|
|
146
|
+
export type AgentJobUsage = AgentWireUsage;
|
|
147
|
+
/**
|
|
148
|
+
* The outcome of an agent job, in the run result wire format: the answer, the structured output,
|
|
149
|
+
* usage with cost, tool calls with their outputs, and the flags that say the answer was cut off
|
|
150
|
+
* (`truncated`), withheld (`blocked`) or given at the iteration limit. A run that paused for tool
|
|
151
|
+
* approvals completes the job with `status: 'paused'`, the calls in `pendingApprovals` and the
|
|
152
|
+
* `checkpoint`: its `output` is not the answer, and `JobQueue.resumeAgentJob` continues it once
|
|
153
|
+
* the calls are decided.
|
|
154
|
+
*/
|
|
155
|
+
export interface AgentJobResult extends AgentWireRunResult {
|
|
155
156
|
type: 'agent';
|
|
156
|
-
output: string;
|
|
157
|
-
/** The validated answer of an agent with a JSON schema response format, when it fits */
|
|
158
|
-
structured?: unknown;
|
|
159
|
-
/** The model's reasoning summary, when the agent asked for one */
|
|
160
|
-
reasoning?: string;
|
|
161
|
-
usage: AgentJobUsage;
|
|
162
|
-
toolCalls: {
|
|
163
|
-
name: string;
|
|
164
|
-
input: unknown;
|
|
165
|
-
output: unknown;
|
|
166
|
-
}[];
|
|
167
157
|
/** @deprecated Use `usage`, which also carries the cost */
|
|
168
158
|
tokenUsage?: {
|
|
169
159
|
prompt: number;
|
|
@@ -229,6 +219,17 @@ export interface QueueConfig {
|
|
|
229
219
|
removeOnFail?: boolean | number;
|
|
230
220
|
};
|
|
231
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* How one job runs on this worker.
|
|
224
|
+
*/
|
|
225
|
+
export interface JobExecutionOptions {
|
|
226
|
+
/**
|
|
227
|
+
* Cancels the job: agent runs, workflow nodes and swarm turns in flight are aborted and no
|
|
228
|
+
* further one starts. `WorkerPool` passes the signal BullMQ gives each job, so
|
|
229
|
+
* `WorkerPool.cancelJob()` and a shutdown that runs out of time stop the work
|
|
230
|
+
*/
|
|
231
|
+
signal?: AbortSignal;
|
|
232
|
+
}
|
|
232
233
|
/**
|
|
233
234
|
* Runtime dependencies used to execute jobs on a worker
|
|
234
235
|
*/
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EACV,eAAe,EACf,uBAAuB,EACvB,kBAAkB,EAClB,cAAc,EACd,aAAa,EACb,IAAI,EACJ,oBAAoB,EACrB,MAAM,qBAAqB,CAAC;AAC7B,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CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,4FAA4F;IAC5F,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB;;;OAGG;IACH,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC;CAChB;AAED,MAAM,WAAW,YAAa,SAAQ,WAAW,EAAE,aAAa;IAC9D,iCAAiC;IACjC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iCAAiC;IACjC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0BAA0B;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iCAAiC;IACjC,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,QAAQ,GAChB,SAAS,GACT,aAAa,GACb,SAAS,GACT,QAAQ,GACR,WAAW,GACX,QAAQ,GACR,kBAAkB,GAClB,SAAS,CAAC;AAEd,MAAM,WAAW,YAAY;IAC3B,4DAA4D;IAC5D,OAAO,EAAE,MAAM,CAAC;IAChB,qCAAqC;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,kCAAkC;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,uBAAuB;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,+BAA+B;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,4EAA4E;IAC5E,KAAK,EAAE,MAAM,CAAC;IACd,+BAA+B;IAC/B,WAAW,EAAE,MAAM,CAAC;CACrB"}
|
package/dist/worker.d.ts
CHANGED
|
@@ -28,9 +28,22 @@ export declare class WorkerPool {
|
|
|
28
28
|
*/
|
|
29
29
|
start(): Promise<void>;
|
|
30
30
|
/**
|
|
31
|
-
* Process a job based on its type
|
|
31
|
+
* Process a job based on its type. `signal` is the one BullMQ gives the job: it aborts on
|
|
32
|
+
* `cancelJob()` and when a shutdown runs out of time, and reaches every agent run of the job.
|
|
33
|
+
* A job cancelled while the pool runs fails without retries. One stopped by a shutdown is left
|
|
34
|
+
* to BullMQ, which hands it to another worker once its lock expires. A workflow or swarm job
|
|
35
|
+
* whose agent run paused for tool approvals fails without retries too: another attempt would
|
|
36
|
+
* only pause again.
|
|
32
37
|
*/
|
|
33
38
|
private processJob;
|
|
39
|
+
private runJob;
|
|
40
|
+
/**
|
|
41
|
+
* Cancel a job this pool is running: its agent runs, workflow nodes and swarm turns are
|
|
42
|
+
* aborted and the job fails without retries.
|
|
43
|
+
*
|
|
44
|
+
* @returns whether a worker of this pool was running the job
|
|
45
|
+
*/
|
|
46
|
+
cancelJob(jobId: string, reason?: string): boolean;
|
|
34
47
|
private getPublisher;
|
|
35
48
|
/**
|
|
36
49
|
* Get current worker count
|
|
@@ -46,11 +59,13 @@ export declare class WorkerPool {
|
|
|
46
59
|
getMetrics(baseMetrics: Omit<QueueMetrics, 'workerCount'>): Promise<QueueMetrics>;
|
|
47
60
|
/**
|
|
48
61
|
* Graceful shutdown
|
|
49
|
-
* Waits up to `timeout` ms for active jobs to complete
|
|
62
|
+
* Waits up to `timeout` ms for active jobs to complete. Then the jobs still running are
|
|
63
|
+
* aborted (their agent runs stop) and the workers are force-closed, BullMQ handing those jobs
|
|
64
|
+
* to another worker once their locks expire.
|
|
50
65
|
*/
|
|
51
66
|
stop(timeout?: number): Promise<void>;
|
|
52
67
|
/**
|
|
53
|
-
* Force shutdown without waiting for jobs
|
|
68
|
+
* Force shutdown without waiting for jobs: the jobs still running are aborted
|
|
54
69
|
*/
|
|
55
70
|
forceStop(): Promise<void>;
|
|
56
71
|
private releaseConnections;
|
package/dist/worker.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAiB,MAAM,SAAS,CAAC;AAKhG,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAUhD,MA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
|
4
4
|
* Manages multiple BullMQ workers that process agent, workflow, and swarm jobs.
|
|
5
5
|
* Supports graceful shutdown and health monitoring.
|
|
6
6
|
*/
|
|
7
|
-
import { Worker } from 'bullmq';
|
|
8
|
-
import { Cogitator } from '@cogitator-ai/core';
|
|
7
|
+
import { UnrecoverableError, Worker } from 'bullmq';
|
|
8
|
+
import { Cogitator, findAgentRunPausedError } from '@cogitator-ai/core';
|
|
9
9
|
import { processAgentJob } from './processors/agent.js';
|
|
10
10
|
import { processWorkflowJob } from './processors/workflow.js';
|
|
11
11
|
import { processSwarmJob } from './processors/swarm.js';
|
|
@@ -41,7 +41,7 @@ export class WorkerPool {
|
|
|
41
41
|
for (let i = 0; i < workerCount; i++) {
|
|
42
42
|
const connection = createBullConnection(this.config.redis, { blocking: true });
|
|
43
43
|
this.connections.push(connection);
|
|
44
|
-
const worker = new Worker(this.config.name ?? DEFAULT_QUEUE_NAME, async (job) => this.processJob(job), {
|
|
44
|
+
const worker = new Worker(this.config.name ?? DEFAULT_QUEUE_NAME, async (job, _token, signal) => this.processJob(job, signal), {
|
|
45
45
|
connection: connection.connection,
|
|
46
46
|
prefix: queuePrefix(this.config.redis),
|
|
47
47
|
concurrency,
|
|
@@ -69,20 +69,41 @@ export class WorkerPool {
|
|
|
69
69
|
this.isRunning = true;
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
|
-
* Process a job based on its type
|
|
72
|
+
* Process a job based on its type. `signal` is the one BullMQ gives the job: it aborts on
|
|
73
|
+
* `cancelJob()` and when a shutdown runs out of time, and reaches every agent run of the job.
|
|
74
|
+
* A job cancelled while the pool runs fails without retries. One stopped by a shutdown is left
|
|
75
|
+
* to BullMQ, which hands it to another worker once its lock expires. A workflow or swarm job
|
|
76
|
+
* whose agent run paused for tool approvals fails without retries too: another attempt would
|
|
77
|
+
* only pause again.
|
|
73
78
|
*/
|
|
74
|
-
async processJob(job) {
|
|
79
|
+
async processJob(job, signal) {
|
|
75
80
|
this.events.onJobStarted?.(job.id ?? job.data.jobId, job.data.type);
|
|
81
|
+
try {
|
|
82
|
+
return await this.runJob(job, signal);
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
if (signal?.aborted && this.isRunning) {
|
|
86
|
+
throw new UnrecoverableError(`Job cancelled: ${abortMessage(signal)}`);
|
|
87
|
+
}
|
|
88
|
+
const paused = findAgentRunPausedError(error);
|
|
89
|
+
if (paused)
|
|
90
|
+
throw new UnrecoverableError(paused.message);
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
runJob(job, signal) {
|
|
95
|
+
const execution = { ...(signal && { signal }) };
|
|
76
96
|
switch (job.data.type) {
|
|
77
97
|
case 'agent':
|
|
78
|
-
return processAgentJob(job.data, this.runtime);
|
|
98
|
+
return processAgentJob(job.data, this.runtime, execution);
|
|
79
99
|
case 'workflow':
|
|
80
|
-
return processWorkflowJob(job.data, this.runtime);
|
|
100
|
+
return processWorkflowJob(job.data, this.runtime, execution);
|
|
81
101
|
case 'swarm':
|
|
82
|
-
return processSwarmJob(job.data, this.runtime);
|
|
102
|
+
return processSwarmJob(job.data, this.runtime, execution);
|
|
83
103
|
case 'swarm-agent':
|
|
84
104
|
return processSwarmAgentJob(job.data, {
|
|
85
105
|
...this.runtime,
|
|
106
|
+
...execution,
|
|
86
107
|
publisher: this.getPublisher(),
|
|
87
108
|
isFinalAttempt: job.attemptsMade + 1 >= (job.opts.attempts ?? 1),
|
|
88
109
|
});
|
|
@@ -92,6 +113,20 @@ export class WorkerPool {
|
|
|
92
113
|
}
|
|
93
114
|
}
|
|
94
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Cancel a job this pool is running: its agent runs, workflow nodes and swarm turns are
|
|
118
|
+
* aborted and the job fails without retries.
|
|
119
|
+
*
|
|
120
|
+
* @returns whether a worker of this pool was running the job
|
|
121
|
+
*/
|
|
122
|
+
cancelJob(jobId, reason = 'Cancelled') {
|
|
123
|
+
let found = false;
|
|
124
|
+
for (const worker of this.workers) {
|
|
125
|
+
if (worker.cancelJob(jobId, reason))
|
|
126
|
+
found = true;
|
|
127
|
+
}
|
|
128
|
+
return found;
|
|
129
|
+
}
|
|
95
130
|
getPublisher() {
|
|
96
131
|
this.publisher ??= createRedisClient(this.config.redis);
|
|
97
132
|
return this.publisher;
|
|
@@ -119,7 +154,9 @@ export class WorkerPool {
|
|
|
119
154
|
}
|
|
120
155
|
/**
|
|
121
156
|
* Graceful shutdown
|
|
122
|
-
* Waits up to `timeout` ms for active jobs to complete
|
|
157
|
+
* Waits up to `timeout` ms for active jobs to complete. Then the jobs still running are
|
|
158
|
+
* aborted (their agent runs stop) and the workers are force-closed, BullMQ handing those jobs
|
|
159
|
+
* to another worker once their locks expire.
|
|
123
160
|
*/
|
|
124
161
|
async stop(timeout = 30000) {
|
|
125
162
|
if (!this.isRunning)
|
|
@@ -137,17 +174,21 @@ export class WorkerPool {
|
|
|
137
174
|
if (timer)
|
|
138
175
|
clearTimeout(timer);
|
|
139
176
|
if (timedOut) {
|
|
177
|
+
for (const worker of workers)
|
|
178
|
+
worker.cancelAllJobs('Worker pool stopped');
|
|
140
179
|
await Promise.all(workers.map((w) => w.close(true)));
|
|
141
180
|
}
|
|
142
181
|
await this.releaseConnections();
|
|
143
182
|
}
|
|
144
183
|
/**
|
|
145
|
-
* Force shutdown without waiting for jobs
|
|
184
|
+
* Force shutdown without waiting for jobs: the jobs still running are aborted
|
|
146
185
|
*/
|
|
147
186
|
async forceStop() {
|
|
148
187
|
this.isRunning = false;
|
|
149
188
|
const workers = this.workers;
|
|
150
189
|
this.workers = [];
|
|
190
|
+
for (const worker of workers)
|
|
191
|
+
worker.cancelAllJobs('Worker pool stopped');
|
|
151
192
|
await Promise.all(workers.map((w) => w.close(true)));
|
|
152
193
|
await this.releaseConnections();
|
|
153
194
|
}
|
|
@@ -165,4 +206,10 @@ export class WorkerPool {
|
|
|
165
206
|
}
|
|
166
207
|
}
|
|
167
208
|
}
|
|
209
|
+
function abortMessage(signal) {
|
|
210
|
+
const reason = signal.reason;
|
|
211
|
+
if (reason instanceof Error)
|
|
212
|
+
return reason.message;
|
|
213
|
+
return typeof reason === 'string' && reason !== '' ? reason : 'aborted';
|
|
214
|
+
}
|
|
168
215
|
//# sourceMappingURL=worker.js.map
|
package/dist/worker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAY,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAY,MAAM,QAAQ,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAExE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,WAAW,GAGZ,MAAM,iBAAiB,CAAC;AASzB,MAAM,OAAO,UAAU;IACb,OAAO,GAAoC,EAAE,CAAC;IAC9C,WAAW,GAAqB,EAAE,CAAC;IAC1B,MAAM,CAAe;IACrB,MAAM,CAAmB;IACzB,OAAO,CAA0B;IAC1C,SAAS,CAAe;IACxB,SAAS,GAAG,KAAK,CAAC;IAE1B,0EAA0E;IACjE,OAAO,GAAG,IAAI,gBAAgB,EAAE,CAAC;IAE1C,YAAY,MAAoB,EAAE,SAA2B,EAAE;QAC7D,IA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AAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACrD,MAAM,IAAI,CAAC,kBAAkB,EAAE,CAAC;IAClC,CAAC;IAEO,KAAK,CAAC,kBAAkB;QAC9B,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;QACrC,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,MAAM,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QACvD,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;IAC9B,CAAC;IAEO,KAAK,CAAC,cAAc;QAC1B,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QACjC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,SAAS,EAAE,CAAC;YACd,MAAM,SAAS,CAAC,IAAI,EAAE,CAAC;QACzB,CAAC;IACH,CAAC;CACF;AAED,SAAS,YAAY,CAAC,MAAmB;IACvC,MAAM,MAAM,GAAY,MAAM,CAAC,MAAM,CAAC;IACtC,IAAI,MAAM,YAAY,KAAK;QAAE,OAAO,MAAM,CAAC,OAAO,CAAC;IACnD,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AAC1E,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cogitator-ai/worker",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "Distributed job queue for Cogitator agent execution",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cogitator",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"exports": {
|
|
18
18
|
".": {
|
|
19
19
|
"types": "./dist/index.d.ts",
|
|
20
|
-
"import": "./dist/index.js"
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
|
+
"default": "./dist/index.js"
|
|
21
22
|
}
|
|
22
23
|
},
|
|
23
24
|
"files": [
|
|
@@ -27,15 +28,15 @@
|
|
|
27
28
|
"node": ">=22.12.0"
|
|
28
29
|
},
|
|
29
30
|
"dependencies": {
|
|
30
|
-
"@cogitator-ai/core": "0.
|
|
31
|
-
"@cogitator-ai/swarms": "0.
|
|
32
|
-
"@cogitator-ai/types": "0.
|
|
31
|
+
"@cogitator-ai/core": "0.35.0",
|
|
32
|
+
"@cogitator-ai/swarms": "0.12.1",
|
|
33
|
+
"@cogitator-ai/types": "0.37.0",
|
|
33
34
|
"bullmq": "^6.3.11",
|
|
34
35
|
"nanoid": "^6.0.1",
|
|
35
36
|
"zod": "^4.6.5"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
|
-
"@cogitator-ai/test-utils": "0.2.
|
|
39
|
+
"@cogitator-ai/test-utils": "0.2.15",
|
|
39
40
|
"ioredis": "^6.0.0",
|
|
40
41
|
"typescript": "^6.0.3",
|
|
41
42
|
"vitest": "^5.0.3"
|