@cogitator-ai/worker 0.8.10 → 0.9.0

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.
Files changed (42) hide show
  1. package/README.md +54 -14
  2. package/dist/distributed-swarm-worker.d.ts +12 -0
  3. package/dist/distributed-swarm-worker.d.ts.map +1 -1
  4. package/dist/distributed-swarm-worker.js +51 -1
  5. package/dist/distributed-swarm-worker.js.map +1 -1
  6. package/dist/index.d.ts +1 -1
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/processors/agent.d.ts +5 -13
  9. package/dist/processors/agent.d.ts.map +1 -1
  10. package/dist/processors/agent.js +20 -44
  11. package/dist/processors/agent.js.map +1 -1
  12. package/dist/processors/shared.d.ts +10 -38
  13. package/dist/processors/shared.d.ts.map +1 -1
  14. package/dist/processors/shared.js +9 -62
  15. package/dist/processors/shared.js.map +1 -1
  16. package/dist/processors/swarm-agent.d.ts +3 -3
  17. package/dist/processors/swarm-agent.d.ts.map +1 -1
  18. package/dist/processors/swarm-agent.js +5 -10
  19. package/dist/processors/swarm-agent.js.map +1 -1
  20. package/dist/processors/swarm.d.ts +11 -3
  21. package/dist/processors/swarm.d.ts.map +1 -1
  22. package/dist/processors/swarm.js +73 -7
  23. package/dist/processors/swarm.js.map +1 -1
  24. package/dist/processors/workflow.d.ts +2 -2
  25. package/dist/processors/workflow.d.ts.map +1 -1
  26. package/dist/processors/workflow.js +53 -28
  27. package/dist/processors/workflow.js.map +1 -1
  28. package/dist/queue.d.ts +36 -3
  29. package/dist/queue.d.ts.map +1 -1
  30. package/dist/queue.js +52 -2
  31. package/dist/queue.js.map +1 -1
  32. package/dist/serialize.d.ts +11 -6
  33. package/dist/serialize.d.ts.map +1 -1
  34. package/dist/serialize.js +10 -30
  35. package/dist/serialize.js.map +1 -1
  36. package/dist/types.d.ts +64 -63
  37. package/dist/types.d.ts.map +1 -1
  38. package/dist/worker.d.ts +18 -3
  39. package/dist/worker.d.ts.map +1 -1
  40. package/dist/worker.js +57 -10
  41. package/dist/worker.js.map +1 -1
  42. package/package.json +7 -6
package/README.md CHANGED
@@ -133,7 +133,7 @@ interface QueueConfig {
133
133
 
134
134
  **Agent Jobs:**
135
135
 
136
- The simplest way is to serialize an agent you already have. `serializeAgent` keeps its model, instructions, sampling, reasoning effort, response format and tool schemas, and turns a Zod response schema into JSON Schema, so the worker validates the structured answer the same way an in-process run does:
136
+ The simplest way is to serialize an agent you already have. `serializeAgent` writes it in the agent wire format of `@cogitator-ai/core` (`toAgentWire`), shared by agent, workflow and swarm jobs and by distributed swarm turns. It keeps the whole configuration (model and provider, instructions, sampling, stop sequences, reasoning effort, response format, iteration limit, timeout), the tool schemas and every agent it can hand over to, and turns a Zod response schema into JSON Schema, so the worker validates the structured answer the same way an in-process run does. A config with a key the worker does not know is refused rather than run without that setting:
137
137
 
138
138
  ```typescript
139
139
  import { Agent } from '@cogitator-ai/core';
@@ -184,7 +184,7 @@ const job = await queue.addAgentJob(agentConfig, 'Research quantum computing', {
184
184
  });
185
185
  ```
186
186
 
187
- The worker routes `model` exactly like the same agent in-process: a prefix that names a built-in provider, a backend in the worker Cogitator's `llm.backends` or a registered plugin picks that provider, so `'openrouter/deepseek/deepseek-v4-pro'` runs on an `openrouter` backend whatever `provider` says. `provider` (optional, any provider the worker routes to, custom backends and plugins included) is prepended only to a model whose prefix names none, such as `'meta-llama/llama-4-scout'` with `provider: 'openrouter'`. Without `provider` such a model runs on the worker's `llm.defaultProvider`, and a `provider` the worker cannot route to fails the job.
187
+ The worker routes `model` exactly like the same agent in-process: a prefix that names a built-in provider, a backend in the worker Cogitator's `llm.backends` or a registered plugin picks that provider, so `'openrouter/deepseek/deepseek-v4-pro'` runs on an `openrouter` backend whatever `provider` says. `provider` (optional, any provider the worker routes to, custom backends and plugins included) is prepended only to a model whose prefix names none, such as `'meta-llama/llama-4-scout'` with `provider: 'openrouter'`. Without `provider` such a model runs on the worker's `llm.defaultProvider`, and a `provider` the worker cannot route to fails the job. `serializeAgent` sends an agent with an explicit `provider` as `<provider>/<model>`, so it takes the same route on the worker as in-process.
188
188
 
189
189
  **Workflow Jobs:**
190
190
 
@@ -199,7 +199,7 @@ const workflowConfig: SerializedWorkflow = {
199
199
  id: 'classify',
200
200
  type: 'agent',
201
201
  config: {
202
- agentConfig: classifierAgent, // SerializedAgent
202
+ agentConfig: classifierAgent, // SerializedAgent; a json_schema agent writes its structured answer
203
203
  prompt: 'Classify this ticket as BUG or QUESTION: {{ticket}}',
204
204
  outputKey: 'category',
205
205
  },
@@ -252,13 +252,13 @@ await queue.addSwarmJob(swarmConfig, 'Write an article about AI', {
252
252
  });
253
253
  ```
254
254
 
255
- | Topology | Swarm strategy | Notes |
256
- | --------------- | -------------- | ------------------------------------------------------------ |
257
- | `sequential` | `pipeline` | One stage per agent, in order |
258
- | `hierarchical` | `hierarchical` | `coordinator` is required and becomes the supervisor |
259
- | `collaborative` | `round-robin` | |
260
- | `debate` | `debate` | `maxRounds` rounds, `coordinator` moderates |
261
- | `voting` | `consensus` | `consensusThreshold`, `maxRounds`; `coordinator` breaks ties |
255
+ | Topology | Swarm strategy | Notes |
256
+ | --------------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
257
+ | `sequential` | `pipeline` | One stage per agent, in order |
258
+ | `hierarchical` | `hierarchical` | `coordinator` is required and becomes the supervisor |
259
+ | `collaborative` | `pipeline` | Every agent contributes in each of `maxRounds` rounds (default 3), seeing all contributions so far, `coordinator` combines them, otherwise the last contribution is the answer |
260
+ | `debate` | `debate` | `maxRounds` rounds, `coordinator` moderates |
261
+ | `voting` | `consensus` | `consensusThreshold`, `maxRounds`, `coordinator` breaks ties |
262
262
 
263
263
  ### Queue Methods
264
264
 
@@ -269,6 +269,8 @@ const state: JobState = await queue.getJobState('job-id');
269
269
  // 'waiting' | 'prioritized' | 'delayed' | 'active' | 'completed' | 'failed'
270
270
  // | 'waiting-children' | 'unknown'
271
271
 
272
+ await queue.resumeAgentJob(agentConfig, pausedResult, { decisions }); // see Job Results
273
+
272
274
  const metrics = await queue.getMetrics();
273
275
  // { waiting, active, completed, failed, delayed, depth, workerCount }
274
276
 
@@ -368,13 +370,19 @@ const metrics = await pool.getMetrics(await queue.getMetrics());
368
370
  // Job duration histogram and per-type counters
369
371
  pool.metrics.format(await pool.getMetrics(await queue.getMetrics()));
370
372
 
371
- // Graceful shutdown (waits up to 30s for active jobs, then force-closes)
373
+ // Cancel a job this pool is running: its agent runs stop and the job fails without retries
374
+ pool.cancelJob(jobId, 'No longer needed');
375
+
376
+ // Graceful shutdown (waits up to 30s for active jobs, then aborts them and force-closes;
377
+ // BullMQ hands the aborted jobs to another worker once their locks expire)
372
378
  await pool.stop(30000);
373
379
 
374
- // Force shutdown
380
+ // Force shutdown (aborts the jobs still running)
375
381
  await pool.forceStop();
376
382
  ```
377
383
 
384
+ Every job gets the abort signal BullMQ gives it, down to each agent run, workflow node and swarm turn of the job. The processors take it too: `processAgentJob(payload, runtime, { signal })`, and the same third argument for `processWorkflowJob`, `processSwarmJob` and `executeSwarmAgentJob` (`processSwarmAgentJob` reads `signal` from its options).
385
+
378
386
  ---
379
387
 
380
388
  ## Job Processors
@@ -430,6 +438,7 @@ const worker = new DistributedSwarmWorker(
430
438
  {
431
439
  onJobCompleted: (job) => console.log('done', job.agentName),
432
440
  onJobFailed: (job, error) => console.error(job.agentName, error.message),
441
+ onJobCancelled: (job) => console.log('the swarm gave up on', job.jobId),
433
442
  onError: (error) => console.error(error),
434
443
  }
435
444
  );
@@ -438,7 +447,7 @@ await worker.start();
438
447
  process.on('SIGTERM', () => void worker.stop()); // waits for in-flight turns
439
448
  ```
440
449
 
441
- Failed turns are reported back to the swarm as errors, so the swarm's own `errorHandling` (retry, failover, skip) applies. Each turn runs on the model its agent would use in-process, routed by the worker's `cogitator`, so give the worker the same `llm.backends`, plugins and provider keys as the process that runs the swarm.
450
+ Failed turns are reported back to the swarm as errors, so the swarm's own `errorHandling` (retry, failover, skip) applies. A turn the swarm gave up on (its run aborted or timed out, the swarm closed, another attempt answered) is skipped, or aborted while it runs (checked every `cancelCheckInterval` ms, default 1000), and reported to `onJobCancelled` instead of being published. Each turn runs on the model its agent would use in-process, routed by the worker's `cogitator`, so give the worker the same `llm.backends`, plugins and provider keys as the process that runs the swarm.
442
451
 
443
452
  ---
444
453
 
@@ -467,6 +476,10 @@ interface AgentJobResult {
467
476
  input: unknown;
468
477
  output: unknown;
469
478
  }[];
479
+ /** 'paused' when tool calls wait for approval: output is then not the answer */
480
+ status?: 'completed' | 'paused';
481
+ pendingApprovals?: ToolApprovalRequest[]; // the calls a paused run waits on
482
+ checkpoint?: RunCheckpoint; // what a paused run continues from, see resumeAgentJob
470
483
  /** @deprecated use usage */
471
484
  tokenUsage?: {
472
485
  prompt: number;
@@ -476,6 +489,18 @@ interface AgentJobResult {
476
489
  }
477
490
  ```
478
491
 
492
+ A run that paused for tool approvals completes its job with `status: 'paused'`. Continue it with the decisions as a new job, on any worker:
493
+
494
+ ```typescript
495
+ if (result.status === 'paused') {
496
+ await queue.resumeAgentJob(agentConfig, result, {
497
+ decisions: { [result.pendingApprovals![0].toolCallId]: { approved: true } },
498
+ });
499
+ }
500
+ ```
501
+
502
+ Workflow and swarm jobs cannot wait for a decision: when one of their agents pauses, the job fails without retries with an `AgentRunPausedError`.
503
+
479
504
  ### Workflow Job Result
480
505
 
481
506
  ```typescript
@@ -643,19 +668,34 @@ Jobs use serialized configurations that can be stored in Redis.
643
668
 
644
669
  ### SerializedAgent
645
670
 
671
+ `SerializedAgent` is `AgentWireConfig` from `@cogitator-ai/types`:
672
+
646
673
  ```typescript
647
674
  interface SerializedAgent {
675
+ id?: string;
648
676
  name: string;
677
+ description?: string;
649
678
  instructions: string;
650
679
  model: string; // routed like in-process: a known provider prefix picks the provider
651
- provider?: LLMBackendProvider; // prepended when model names no provider the worker routes to
680
+ provider?: LLMBackendProvider; // used when model names no provider the worker routes to
652
681
  temperature?: number;
682
+ topP?: number;
653
683
  maxTokens?: number;
684
+ stopSequences?: string[];
685
+ responseFormat?:
686
+ { type: 'text' } | { type: 'json' } | { type: 'json_schema'; schema: JSONSchema };
687
+ reasoning?: ReasoningConfig;
654
688
  maxIterations?: number;
689
+ onIterationLimit?: 'answer' | 'stop';
690
+ timeout?: number;
655
691
  tools: ToolSchema[]; // resolved by name against the worker's tools
692
+ handoffs?: { agent: string; toolName?: string; description?: string }[];
693
+ handoffAgents?: Record<string, Omit<SerializedAgent, 'handoffAgents'>>; // handoff targets by name
656
694
  }
657
695
  ```
658
696
 
697
+ Unknown keys are refused. Agent job results (`AgentJobResult`) carry `output`, `structured`, `structuredError`, `reasoning`, `usage` (tokens, `cost`, `duration`, reasoning and cache tokens), `toolCalls` with their outputs, and `truncated`, `blocked` and `iterationLimitReached`.
698
+
659
699
  ### SerializedWorkflow
660
700
 
661
701
  ```typescript
@@ -22,11 +22,19 @@ export interface DistributedSwarmWorkerConfig extends WorkerRuntime {
22
22
  concurrency?: number;
23
23
  /** Seconds a blocking poll waits for new jobs before re-checking state (default: 1) */
24
24
  pollTimeout?: number;
25
+ /**
26
+ * How often, in ms, a running turn checks whether the coordinator cancelled it (its run
27
+ * aborted or timed out, the swarm closed, or another attempt answered), default 1000. A
28
+ * cancelled turn is aborted and its result is not published
29
+ */
30
+ cancelCheckInterval?: number;
25
31
  }
26
32
  export interface DistributedSwarmWorkerEvents {
27
33
  onJobStarted?: (job: SwarmAgentJobPayload) => void;
28
34
  onJobCompleted?: (job: SwarmAgentJobPayload, result: SwarmAgentJobResult) => void;
29
35
  onJobFailed?: (job: SwarmAgentJobPayload, error: Error) => void;
36
+ /** The coordinator gave up on the turn: it was skipped, or aborted while it ran */
37
+ onJobCancelled?: (job: SwarmAgentJobPayload) => void;
30
38
  onError?: (error: Error) => void;
31
39
  }
32
40
  export declare class DistributedSwarmWorker {
@@ -52,5 +60,9 @@ export declare class DistributedSwarmWorker {
52
60
  getActiveJobCount(): number;
53
61
  private consume;
54
62
  private handle;
63
+ /** Whether the coordinator gave up on the job (only coordinators that name a cancel set). */
64
+ private isCancelled;
65
+ /** Abort `controller` once the coordinator cancels the job while it runs. */
66
+ private watchCancellation;
55
67
  }
56
68
  //# sourceMappingURL=distributed-swarm-worker.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"distributed-swarm-worker.d.ts","sourceRoot":"","sources":["../src/distributed-swarm-worker.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAKxF,MAAM,WAAW,4BAA6B,SAAQ,aAAa;IACjE,qFAAqF;IACrF,KAAK,CAAC,EAAE;QACN,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,EAAE,CAAC,EAAE,MAAM,CAAC;KACb,CAAC;IACF,oFAAoF;IACpF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mFAAmF;IACnF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,uFAAuF;IACvF,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,4BAA4B;IAC3C,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,oBAAoB,KAAK,IAAI,CAAC;IACnD,cAAc,CAAC,EAAE,CAAC,GAAG,EAAE,oBAAoB,EAAE,MAAM,EAAE,mBAAmB,KAAK,IAAI,CAAC;IAClF,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,oBAAoB,EAAE,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAChE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAgBD,qBAAa,sBAAsB;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA+B;IACtD,OAAO,CAAC,QAAQ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;
134
+ if (await this.isCancelled(job)) {
135
+ this.events.onJobCancelled?.(job);
136
+ return;
137
+ }
134
138
  this.events.onJobStarted?.(job);
135
- const result = await executeSwarmAgentJob(job, this.runtime);
139
+ const controller = new AbortController();
140
+ const watch = this.watchCancellation(job, controller);
141
+ let result;
142
+ try {
143
+ result = await executeSwarmAgentJob(job, this.runtime, { signal: controller.signal });
144
+ }
145
+ finally {
146
+ clearInterval(watch);
147
+ }
148
+ if (controller.signal.aborted) {
149
+ this.events.onJobCancelled?.(job);
150
+ return;
151
+ }
136
152
  try {
137
153
  await this.publisher.publish(job.stateKeys.results, JSON.stringify(result));
138
154
  }
@@ -147,5 +163,39 @@ export class DistributedSwarmWorker {
147
163
  this.events.onJobCompleted?.(job, result);
148
164
  }
149
165
  }
166
+ /** Whether the coordinator gave up on the job (only coordinators that name a cancel set). */
167
+ async isCancelled(job) {
168
+ const key = job.stateKeys.cancelled;
169
+ if (!key || !this.publisher)
170
+ return false;
171
+ try {
172
+ return (await this.publisher.sismember(key, job.jobId)) === 1;
173
+ }
174
+ catch (error) {
175
+ this.events.onError?.(error instanceof Error ? error : new Error(toErrorMessage(error)));
176
+ return false;
177
+ }
178
+ }
179
+ /** Abort `controller` once the coordinator cancels the job while it runs. */
180
+ watchCancellation(job, controller) {
181
+ if (!job.stateKeys.cancelled)
182
+ return undefined;
183
+ const interval = Math.max(10, this.config.cancelCheckInterval ?? 1000);
184
+ let checking = false;
185
+ return setInterval(() => {
186
+ if (checking || controller.signal.aborted)
187
+ return;
188
+ checking = true;
189
+ void this.isCancelled(job)
190
+ .then((cancelled) => {
191
+ if (cancelled) {
192
+ controller.abort(new Error(`Swarm turn ${job.jobId} was cancelled by its coordinator`));
193
+ }
194
+ })
195
+ .finally(() => {
196
+ checking = false;
197
+ });
198
+ }, interval);
199
+ }
150
200
  }
151
201
  //# sourceMappingURL=distributed-swarm-worker.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"distributed-swarm-worker.js","sourceRoot":"","sources":["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.d.ts CHANGED
@@ -15,5 +15,5 @@ export { formatPrometheusMetrics, DurationHistogram, MetricsCollector } from './
15
15
  export { serializeAgent, serializeResponseFormat } from './serialize.js';
16
16
  export { resolveRedisOptions, type RedisConnectionOptions } from './connection.js';
17
17
  export { processAgentJob, processWorkflowJob, processSwarmJob, processSwarmAgentJob, executeSwarmAgentJob, buildSwarmConfig, validateWorkflow, type SwarmAgentJobOptions, type SwarmResultPublisher, } from './processors/index.js';
18
- export type { SerializedAgent, SerializedResponseFormat, AgentJobUsage, SerializedWorkflow, SerializedWorkflowNode, SerializedWorkflowEdge, AgentNodeConfig, TransformNodeConfig, TransformOperation, ConditionNodeConfig, ConditionOperator, SerializedSwarm, JobPayload, AgentJobPayload, WorkflowJobPayload, SwarmJobPayload, SwarmAgentJobPayload, JobResult, AgentJobResult, WorkflowJobResult, SwarmJobResult, SwarmAgentJobResult, QueueConfig, WorkerConfig, WorkerRuntime, QueueMetrics, JobState, } from './types.js';
18
+ export type { SerializedAgent, SerializedResponseFormat, AgentJobUsage, SerializedWorkflow, SerializedWorkflowNode, SerializedWorkflowEdge, AgentNodeConfig, TransformNodeConfig, TransformOperation, ConditionNodeConfig, ConditionOperator, SerializedSwarm, SwarmTopology, JobPayload, AgentJobPayload, AgentJobResume, WorkflowJobPayload, SwarmJobPayload, SwarmAgentJobPayload, JobResult, AgentJobResult, WorkflowJobResult, SwarmJobResult, SwarmAgentJobResult, QueueConfig, WorkerConfig, WorkerRuntime, JobExecutionOptions, QueueMetrics, JobState, } from './types.js';
19
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,KAAK,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC7D,OAAO,EACL,sBAAsB,EACtB,KAAK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AuB,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,KAAK,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEhF,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,EAChB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,GAC1B,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EACV,eAAe,EACf,wBAAwB,EACxB,aAAa,EACb,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,UAAU,EACV,eAAe,EACf,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,oBAAoB,EACpB,SAAS,EACT,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EACnB,WAAW,EACX,YAAY,EACZ,aAAa,EACb,mBAAmB,EACnB,YAAY,EACZ,QAAQ,GACT,MAAM,SAAS,CAAC"}
@@ -1,18 +1,10 @@
1
1
  /**
2
2
  * Agent job processor
3
3
  *
4
- * Recreates an Agent from serialized config and executes it.
4
+ * Recreates an Agent from its wire form and runs it, or resumes the run a previous job paused.
5
+ * A paused run is a result, not a failure: it carries `status: 'paused'` and its checkpoint.
5
6
  */
6
- import type { AgentJobPayload, AgentJobResult, WorkerRuntime } from '../types.js';
7
- export declare function processAgentJob(payload: AgentJobPayload, runtime?: WorkerRuntime): Promise<AgentJobResult>;
8
- interface ToolMessageLike {
9
- role: string;
10
- toolCallId?: string;
11
- content: unknown;
12
- }
13
- /**
14
- * Tool results are recorded as `tool` messages; recover the output for a tool call.
15
- */
16
- export declare function findToolOutput(messages: readonly ToolMessageLike[], toolCallId: string): unknown;
17
- export {};
7
+ import type { AgentJobPayload, AgentJobResult, JobExecutionOptions, WorkerRuntime } from '../types.js';
8
+ export { findToolOutput } from '@cogitator-ai/core';
9
+ export declare function processAgentJob(payload: AgentJobPayload, runtime?: WorkerRuntime, execution?: JobExecutionOptions): Promise<AgentJobResult>;
18
10
  //# sourceMappingURL=agent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/processors/agent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAG/E,wBAAsB,eAAe,CACnC,OAAO,EAAE,eAAe,EACxB,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,cAAc,CAAC,CAuCzB;AAED,UAAU,eAAe;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,SAAS,eAAe,EAAE,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAShG"}
1
+ {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/processors/agent.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGpG,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,wBAAsB,eAAe,CACnC,OAAO,EAAE,eAAe,EACxB,OAAO,GAAE,aAAkB,EAC3B,SAAS,GAAE,mBAAwB,GAClC,OAAO,CAAC,cAAc,CAAC,CA4BzB"}
@@ -1,40 +1,32 @@
1
1
  /**
2
2
  * Agent job processor
3
3
  *
4
- * Recreates an Agent from serialized config and executes it.
4
+ * Recreates an Agent from its wire form and runs it, or resumes the run a previous job paused.
5
+ * A paused run is a result, not a failure: it carries `status: 'paused'` and its checkpoint.
5
6
  */
7
+ import { toAgentWireRunResult } from '@cogitator-ai/core';
6
8
  import { createAgentFromConfig, resolveRuntime } from './shared.js';
7
- export async function processAgentJob(payload, runtime = {}) {
8
- const { agentConfig, input, threadId, userId } = payload;
9
+ export { findToolOutput } from '@cogitator-ai/core';
10
+ export async function processAgentJob(payload, runtime = {}, execution = {}) {
11
+ const { agentConfig, input, threadId, userId, resume } = payload;
9
12
  const resolved = resolveRuntime(runtime);
10
13
  const agent = createAgentFromConfig(agentConfig, resolved);
11
- const result = await resolved.cogitator.run(agent, {
12
- input,
13
- threadId,
14
- ...(userId !== undefined && { userId }),
15
- });
14
+ const result = resume
15
+ ? await resolved.cogitator.resume(agent, resume.checkpoint ?? threadId, {
16
+ ...(resume.decisions && { decisions: resume.decisions }),
17
+ ...(resume.defaultDecision && { defaultDecision: resume.defaultDecision }),
18
+ ...(userId !== undefined && { userId }),
19
+ ...(execution.signal && { signal: execution.signal }),
20
+ })
21
+ : await resolved.cogitator.run(agent, {
22
+ input,
23
+ threadId,
24
+ ...(userId !== undefined && { userId }),
25
+ ...(execution.signal && { signal: execution.signal }),
26
+ });
16
27
  return {
17
28
  type: 'agent',
18
- output: result.output,
19
- ...(result.structured !== undefined && { structured: result.structured }),
20
- ...(result.reasoning && { reasoning: result.reasoning }),
21
- usage: {
22
- inputTokens: result.usage.inputTokens,
23
- outputTokens: result.usage.outputTokens,
24
- totalTokens: result.usage.totalTokens,
25
- cost: result.usage.cost,
26
- ...(result.usage.reasoningTokens !== undefined && {
27
- reasoningTokens: result.usage.reasoningTokens,
28
- }),
29
- ...(result.usage.cachedInputTokens !== undefined && {
30
- cachedInputTokens: result.usage.cachedInputTokens,
31
- }),
32
- },
33
- toolCalls: result.toolCalls.map((tc) => ({
34
- name: tc.name,
35
- input: tc.arguments,
36
- output: findToolOutput(result.messages, tc.id),
37
- })),
29
+ ...toAgentWireRunResult(result),
38
30
  tokenUsage: {
39
31
  prompt: result.usage.inputTokens,
40
32
  completion: result.usage.outputTokens,
@@ -42,20 +34,4 @@ export async function processAgentJob(payload, runtime = {}) {
42
34
  },
43
35
  };
44
36
  }
45
- /**
46
- * Tool results are recorded as `tool` messages; recover the output for a tool call.
47
- */
48
- export function findToolOutput(messages, toolCallId) {
49
- const message = messages.find((m) => m.role === 'tool' && m.toolCallId === toolCallId);
50
- if (!message)
51
- return undefined;
52
- if (typeof message.content !== 'string')
53
- return message.content;
54
- try {
55
- return JSON.parse(message.content);
56
- }
57
- catch {
58
- return message.content;
59
- }
60
- }
61
37
  //# sourceMappingURL=agent.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"agent.js","sourceRoot":"","sources":["../../src/processors/agent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEpE,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,OAAwB,EACxB,UAAyB,EAAE;IAE3B,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAEzD,MAAM,QAAQ,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;IACzC,MAAM,KAAK,GAAG,qBAAqB,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IAC3D,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE;QACjD,KAAK;QACL,QAAQ;QACR,GAAG,CAAC,MAAM,KAAK,SAAS,IAAI,EAAE,MAAM,EAAE,CAAC;KACxC,CAAC,CAAC;IAEH,OAAO;QACL,IAAI,EAAE,OAAO;QACb,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,GAAG,CAAC,MAAM,CAAC,UAAU,KAAK,SAAS,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC;QACzE,GAAG,CAAC,MAAM,CAAC,SAAS,IAAI,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC;QACxD,KAAK,EAAE;YACL,WAAW,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E,CAAC;SACtD,CAAC;QACJ,CAAC,CAAC,MAAM,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE;YAClC,KAAK;YACL,QAAQ;YACR,GAAG,CAAC,MAAM,KAAK,SAAS,IAAI,EAAE,MAAM,EAAE,CAAC;YACvC,GAAG,CAAC,SAAS,CAAC,MAAM,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,CAAC;SACtD,CAAC,CAAC;IAEP,OAAO;QACL,IAAI,EAAE,OAAO;QACb,GAAG,oBAAoB,CAAC,MAAM,CAAC;QAC/B,UAAU,EAAE;YACV,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,WAAW;YAChC,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC,YAAY;YACrC,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,WAAW;SAChC;KACF,CAAC;AACJ,CAAC"}
@@ -1,40 +1,5 @@
1
- import { Agent, Cogitator } from '@cogitator-ai/core';
2
- import type { ReasoningConfig, ResponseFormat, Tool, ToolSchema } from '@cogitator-ai/types';
3
- import type { SerializedResponseFormat, WorkerRuntime } from '../types.js';
4
- /**
5
- * Model string to run on `cogitator`, so a serialized agent routes like the same agent
6
- * would in-process. A model whose prefix names a provider, backend or plugin the Cogitator
7
- * routes to is used as-is. Otherwise `provider` is prepended, and without a provider the
8
- * model stays unchanged and runs on the Cogitator's `llm.defaultProvider`.
9
- *
10
- * @throws Error when `provider` is needed but the Cogitator cannot route to it
11
- */
12
- export declare function resolveModelString(model: string, provider: string | undefined, cogitator: Cogitator): string;
13
- /**
14
- * Resolve serialized tool references against the worker's tool registry.
15
- * Fails when the agent needs tools this worker does not provide, instead of silently
16
- * running the agent with fake tools.
17
- */
18
- export declare function resolveTools(schemas: readonly ToolSchema[], available: readonly Tool[]): Tool[];
19
- export interface SerializedAgentLike {
20
- name: string;
21
- instructions: string;
22
- model: string;
23
- provider?: string;
24
- temperature?: number;
25
- topP?: number;
26
- maxTokens?: number;
27
- maxIterations?: number;
28
- onIterationLimit?: 'answer' | 'stop';
29
- responseFormat?: SerializedResponseFormat;
30
- reasoning?: ReasoningConfig;
31
- tools: readonly ToolSchema[];
32
- }
33
- /**
34
- * The agent's response format back from its queue form: JSON Schema becomes a Zod schema, so the
35
- * runtime validates the structured output and asks for a repair as it does in-process.
36
- */
37
- export declare function toResponseFormat(format: SerializedResponseFormat | undefined): ResponseFormat | undefined;
1
+ import { Cogitator, type Agent } from '@cogitator-ai/core';
2
+ import type { SerializedAgent, WorkerRuntime } from '../types.js';
38
3
  /**
39
4
  * Worker runtime with the Cogitator settled, so the agents of a job are routed by the
40
5
  * same Cogitator that runs them.
@@ -43,6 +8,13 @@ export interface ResolvedRuntime extends WorkerRuntime {
43
8
  cogitator: Cogitator;
44
9
  }
45
10
  export declare function resolveRuntime(runtime: WorkerRuntime): ResolvedRuntime;
46
- export declare function createAgentFromConfig(config: SerializedAgentLike, runtime: ResolvedRuntime): Agent;
11
+ /**
12
+ * The agent a job describes, ready to run on this worker: routed by the worker's Cogitator,
13
+ * with the worker's tool implementations (see `fromAgentWire`).
14
+ *
15
+ * @throws AgentWireError when the config is invalid, needs a tool the worker lacks or a
16
+ * provider it cannot route to
17
+ */
18
+ export declare function createAgentFromConfig(config: SerializedAgent, runtime: ResolvedRuntime): Agent;
47
19
  export declare function toErrorMessage(error: unknown): string;
48
20
  //# sourceMappingURL=shared.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/processors/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAE7F,OAAO,KAAK,EAAE,wBAAwB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAExE;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,C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EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE/D;;;GAGG;AACH,MAAM,WAAW,eAAgB,SAAQ,aAAa;IACpD,SAAS,EAAE,SAAS,CAAC;CACtB;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,aAAa,GAAG,eAAe,CAEtE;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,eAAe,GAAG,KAAK,CAE9F;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAErD"}
@@ -1,69 +1,16 @@
1
- import { Agent, Cogitator } from '@cogitator-ai/core';
2
- import { z } from 'zod';
3
- /**
4
- * Model string to run on `cogitator`, so a serialized agent routes like the same agent
5
- * would in-process. A model whose prefix names a provider, backend or plugin the Cogitator
6
- * routes to is used as-is. Otherwise `provider` is prepended, and without a provider the
7
- * model stays unchanged and runs on the Cogitator's `llm.defaultProvider`.
8
- *
9
- * @throws Error when `provider` is needed but the Cogitator cannot route to it
10
- */
11
- export function resolveModelString(model, provider, cogitator) {
12
- const slash = model.indexOf('/');
13
- if (slash > 0 && cogitator.knowsProvider(model.slice(0, slash)))
14
- return model;
15
- if (!provider)
16
- return model;
17
- if (!cogitator.knowsProvider(provider)) {
18
- throw new Error(`Provider "${provider}" of model "${model}" is not available on this worker: ` +
19
- 'it is not a built-in provider, a backend in llm.backends or a registered plugin of the worker Cogitator.');
20
- }
21
- return `${provider}/${model}`;
22
- }
23
- /**
24
- * Resolve serialized tool references against the worker's tool registry.
25
- * Fails when the agent needs tools this worker does not provide, instead of silently
26
- * running the agent with fake tools.
27
- */
28
- export function resolveTools(schemas, available) {
29
- if (schemas.length === 0)
30
- return [];
31
- const registry = new Map(available.map((t) => [t.name, t]));
32
- const missing = schemas.map((s) => s.name).filter((name) => !registry.has(name));
33
- if (missing.length > 0) {
34
- throw new Error(`Tools not registered on this worker: ${missing.join(', ')}. ` +
35
- 'Pass their implementations via the worker `tools` option.');
36
- }
37
- return schemas.map((schema) => registry.get(schema.name));
38
- }
39
- /**
40
- * The agent's response format back from its queue form: JSON Schema becomes a Zod schema, so the
41
- * runtime validates the structured output and asks for a repair as it does in-process.
42
- */
43
- export function toResponseFormat(format) {
44
- if (!format)
45
- return undefined;
46
- if (format.type !== 'json_schema')
47
- return format;
48
- return { type: 'json_schema', schema: z.fromJSONSchema(format.schema) };
49
- }
1
+ import { Cogitator, fromAgentWire } from '@cogitator-ai/core';
50
2
  export function resolveRuntime(runtime) {
51
3
  return { ...runtime, cogitator: runtime.cogitator ?? new Cogitator() };
52
4
  }
5
+ /**
6
+ * The agent a job describes, ready to run on this worker: routed by the worker's Cogitator,
7
+ * with the worker's tool implementations (see `fromAgentWire`).
8
+ *
9
+ * @throws AgentWireError when the config is invalid, needs a tool the worker lacks or a
10
+ * provider it cannot route to
11
+ */
53
12
  export function createAgentFromConfig(config, runtime) {
54
- return new Agent({
55
- name: config.name,
56
- model: resolveModelString(config.model, config.provider, runtime.cogitator),
57
- instructions: config.instructions,
58
- temperature: config.temperature,
59
- topP: config.topP,
60
- maxTokens: config.maxTokens,
61
- maxIterations: config.maxIterations,
62
- ...(config.onIterationLimit && { onIterationLimit: config.onIterationLimit }),
63
- responseFormat: toResponseFormat(config.responseFormat),
64
- reasoning: config.reasoning,
65
- tools: resolveTools(config.tools, runtime.tools ?? []),
66
- });
13
+ return fromAgentWire(config, runtime);
67
14
  }
68
15
  export function toErrorMessage(error) {
69
16
  return error instanceof Error ? error.message : String(error);
@@ -1 +1 @@
1
- {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/processors/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;;;;;GAOG;AACH,MAAM,UAAU,k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AAK,IAAI,EAAE,CAAC;KACvD,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC"}
1
+ {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/processors/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAc,MAAM,oBAAoB,CAAC;AAW1E,MAAM,UAAU,cAAc,CAAC,OAAsB;IACnD,OAAO,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,IAAI,SAAS,EAAE,EAAE,CAAC;AACzE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAAuB,EAAE,OAAwB;IACrF,OAAO,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC"}
@@ -5,15 +5,15 @@
5
5
  * the job id so the swarm coordinator can match it; failures are reported as results with
6
6
  * an `error` field instead of being thrown.
7
7
  */
8
- import type { SwarmAgentJobPayload, SwarmAgentJobResult, WorkerRuntime } from '../types.js';
9
- export declare function executeSwarmAgentJob(payload: SwarmAgentJobPayload, runtime?: WorkerRuntime): Promise<SwarmAgentJobResult>;
8
+ import type { JobExecutionOptions, SwarmAgentJobPayload, SwarmAgentJobResult, WorkerRuntime } from '../types.js';
9
+ export declare function executeSwarmAgentJob(payload: SwarmAgentJobPayload, runtime?: WorkerRuntime, execution?: JobExecutionOptions): Promise<SwarmAgentJobResult>;
10
10
  /**
11
11
  * Publishes a job result on the channel the swarm coordinator listens to.
12
12
  */
13
13
  export interface SwarmResultPublisher {
14
14
  publish(channel: string, message: string): Promise<unknown>;
15
15
  }
16
- export interface SwarmAgentJobOptions extends WorkerRuntime {
16
+ export interface SwarmAgentJobOptions extends WorkerRuntime, JobExecutionOptions {
17
17
  /** Connection used to publish the result back to the coordinator */
18
18
  publisher: SwarmResultPublisher;
19
19
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"swarm-agent.d.ts","sourceRoot":"","sources":["../../src/processors/swarm-agent.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAIzF,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,oBAAoB,EAC7B,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,mBAAmB,CAAC,CA6C9B;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC7D;AAED,MAAM,WAAW,oBAAqB,SAAQ,aAAa;IACzD,oEAAoE;IACpE,SAAS,EAAE,oBAAoB,CAAC;IAChC;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,oBAAoB,EAC7B,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,mBAAmB,CAAC,CAa9B"}
1
+ {"version":3,"file":"swarm-agent.d.ts","sourceRoot":"","sources":["../../src/processors/swarm-agent.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EACV,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,aAAa,EACd,MAAM,UAAU,CAAC;AAGlB,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,oBAAoB,EAC7B,OAAO,GAAE,aA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