@ziggs-ai/agent-sdk 0.48.1 → 0.48.3
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/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.48.3
|
|
6
|
+
|
|
7
|
+
- A task an agent opens for itself is taken up at once. The server never rings an agent with its own write, so the inbox's held read used to wait for unrelated mail before the task woke the agent (minutes in practice). The inbox loop now reads again as soon as `task_create` opens a task assigned to the agent. `InboxLoopHandle.rereadNow()` does the same for any host.
|
|
8
|
+
|
|
5
9
|
## 0.48.1
|
|
6
10
|
|
|
7
11
|
## 0.48.0
|
package/dist/Agent.js
CHANGED
|
@@ -416,6 +416,9 @@ export class Agent {
|
|
|
416
416
|
wakeScheduler: {
|
|
417
417
|
armWakeAt: (sessionId, at, reason) => this.armOwnWake(sessionId, at, reason),
|
|
418
418
|
},
|
|
419
|
+
// A task the agent gives itself rings no bell; read the inbox now so
|
|
420
|
+
// it is taken up instead of waiting for unrelated mail.
|
|
421
|
+
onOwnTaskCreated: () => this.inboxLoop?.rereadNow(),
|
|
419
422
|
});
|
|
420
423
|
this.brain = this.options.brain?.kind === 'handler'
|
|
421
424
|
? { workflow, tick: this.options.brain.config.tick }
|
|
@@ -66,7 +66,14 @@ export interface ZiggsEffectDeps {
|
|
|
66
66
|
* `wake_at` says so plainly rather than pretending to have scheduled one.
|
|
67
67
|
*/
|
|
68
68
|
wakeScheduler?: WakeSchedulerPort;
|
|
69
|
+
/**
|
|
70
|
+
* Called when a tool call opened a task assigned to this agent. Its own
|
|
71
|
+
* write rings no bell, so the host reads its inbox again to pick it up.
|
|
72
|
+
*/
|
|
73
|
+
onOwnTaskCreated?: (taskId: string) => void;
|
|
69
74
|
}
|
|
75
|
+
/** The task a successful `task_create` opened for this agent itself, if any. */
|
|
76
|
+
export declare function ownTaskCreated(tool: string, result: unknown, agentId: string): string | null;
|
|
70
77
|
/**
|
|
71
78
|
* The single tool-execution path for BOTH cognitions.
|
|
72
79
|
*
|
|
@@ -83,7 +90,7 @@ export interface ZiggsEffectDeps {
|
|
|
83
90
|
* (`context_snapshot`, `message_send`) resolve through this same path
|
|
84
91
|
* regardless of which cognition invoked them.
|
|
85
92
|
*/
|
|
86
|
-
export declare function executeToolWithSideEffects(deps: Pick<ZiggsEffectDeps, 'toolManager' | 'artifactsClient' | 'telemetryClient' | 'telemetryIngest' | 'operatorKey' | 'agentId' | 'taskService' | 'agreementService' | 'contextReadClient' | 'messageSender' | 'wakeScheduler' | 'conversationFor'>, eff: EffectHandler, effect: Extract<Effect, {
|
|
93
|
+
export declare function executeToolWithSideEffects(deps: Pick<ZiggsEffectDeps, 'toolManager' | 'artifactsClient' | 'telemetryClient' | 'telemetryIngest' | 'operatorKey' | 'agentId' | 'taskService' | 'agreementService' | 'contextReadClient' | 'messageSender' | 'wakeScheduler' | 'conversationFor' | 'onOwnTaskCreated'>, eff: EffectHandler, effect: Extract<Effect, {
|
|
87
94
|
kind: 'tool-call';
|
|
88
95
|
}>, roster: {
|
|
89
96
|
agents: unknown[];
|
|
@@ -9,6 +9,17 @@ import { assertRequiredContext } from '../runtime/requiredContext.js';
|
|
|
9
9
|
import { artifactScope } from '@ziggs-ai/api-client';
|
|
10
10
|
import { buildLlmIngestPayload, buildToolIngestPayload, isTelemetryIngestEnabled, sendTelemetry, } from './telemetryIngest.js';
|
|
11
11
|
const CONTEXT_CACHE_MAX = 256;
|
|
12
|
+
/** The task a successful `task_create` opened for this agent itself, if any. */
|
|
13
|
+
export function ownTaskCreated(tool, result, agentId) {
|
|
14
|
+
if (tool !== 'task_create' || !result || typeof result !== 'object')
|
|
15
|
+
return null;
|
|
16
|
+
const r = result;
|
|
17
|
+
if (r.ok === false || r.success === false || r.error)
|
|
18
|
+
return null;
|
|
19
|
+
const task = (r.task && typeof r.task === 'object' ? r.task : r);
|
|
20
|
+
const taskId = typeof task.taskId === 'string' ? task.taskId : null;
|
|
21
|
+
return taskId && (task.assigneeId === agentId || task.executorIsYou === true) ? taskId : null;
|
|
22
|
+
}
|
|
12
23
|
/** Said in place of a read when nothing selects one. Not a failure: the wake can still act on explicit resources. */
|
|
13
24
|
const NO_CONTEXT = 'This wake selects no message, artifact or work. Name an exact message, artifact, task or agreement before reading context.';
|
|
14
25
|
/** Required work context and optional messaging inputs share the same access
|
|
@@ -240,7 +251,11 @@ export async function executeToolWithSideEffects(deps, eff, effect, roster) {
|
|
|
240
251
|
reportUsage,
|
|
241
252
|
turnScratch: {},
|
|
242
253
|
});
|
|
243
|
-
|
|
254
|
+
const toolName = effect.name.replace(/^(functions|tools|function|tool)\./, '');
|
|
255
|
+
controller?.observeTool(toolName, result);
|
|
256
|
+
const ownTask = ownTaskCreated(toolName, result, deps.agentId);
|
|
257
|
+
if (ownTask)
|
|
258
|
+
deps.onOwnTaskCreated?.(ownTask);
|
|
244
259
|
// One clip per tool call: this is a full JSON.stringify of the untruncated
|
|
245
260
|
// result, and the artifact body and the idempotency key want the same string.
|
|
246
261
|
const clipped = clipForOperationArtifact(result);
|
|
@@ -163,6 +163,8 @@ export declare function pollInboxOnce(deps: InboxLoopDeps, waitSeconds?: number,
|
|
|
163
163
|
signal?: AbortSignal;
|
|
164
164
|
dispatch?: InboxDispatch;
|
|
165
165
|
seen?: string;
|
|
166
|
+
/** Cancels only the held read, never a pass that has its envelope. */
|
|
167
|
+
waitSignal?: AbortSignal;
|
|
166
168
|
}): Promise<InboxPassResult>;
|
|
167
169
|
export interface InboxLoopHandle {
|
|
168
170
|
/**
|
|
@@ -190,6 +192,14 @@ export interface InboxLoopHandle {
|
|
|
190
192
|
* report reads the other. `running` says the loop exists; this says it turns.
|
|
191
193
|
*/
|
|
192
194
|
readonly lastAttemptAt: number | null;
|
|
195
|
+
/**
|
|
196
|
+
* Read the inbox again now instead of waiting out a held read. A held read
|
|
197
|
+
* answers only to new mail, and a task an agent gives itself rings no bell
|
|
198
|
+
* (the server never wakes an actor with its own write), so without this the
|
|
199
|
+
* task would wait for unrelated mail. A pass already holding its envelope is
|
|
200
|
+
* left to finish; the next read is immediate either way.
|
|
201
|
+
*/
|
|
202
|
+
rereadNow(): void;
|
|
193
203
|
}
|
|
194
204
|
/**
|
|
195
205
|
* Whether a pass changed anything. One that only found rows already running
|
|
@@ -216,7 +216,9 @@ export async function pollInboxOnce(deps, waitSeconds = 0, opts = {}) {
|
|
|
216
216
|
const envelope = await inbox.getInbox({
|
|
217
217
|
...(waitSeconds > 0 ? { waitSeconds } : {}),
|
|
218
218
|
...(opts.seen ? { seen: opts.seen } : {}),
|
|
219
|
-
...(opts.signal
|
|
219
|
+
...(opts.signal || opts.waitSignal
|
|
220
|
+
? { signal: opts.signal && opts.waitSignal ? AbortSignal.any([opts.signal, opts.waitSignal]) : (opts.signal ?? opts.waitSignal) }
|
|
221
|
+
: {}),
|
|
220
222
|
...(shared ? { capacity: free } : {}),
|
|
221
223
|
});
|
|
222
224
|
// A response may race shutdown. Do not enqueue another wake after stopping;
|
|
@@ -711,6 +713,9 @@ export function runInboxLoop(deps, opts = {}) {
|
|
|
711
713
|
let lastPassAt = null;
|
|
712
714
|
let lastAttemptAt = null;
|
|
713
715
|
let first = true;
|
|
716
|
+
// Set by rereadNow: the next read is immediate and waits for nothing.
|
|
717
|
+
let immediate = false;
|
|
718
|
+
let held = null;
|
|
714
719
|
const shutdown = new AbortController();
|
|
715
720
|
// One DELETE, whichever gets there first: the loop's own exit, or a stop
|
|
716
721
|
// that ran out of patience with the pass in flight.
|
|
@@ -720,11 +725,16 @@ export function runInboxLoop(deps, opts = {}) {
|
|
|
720
725
|
while (running) {
|
|
721
726
|
try {
|
|
722
727
|
lastAttemptAt = Date.now();
|
|
723
|
-
const
|
|
728
|
+
const now = first || immediate;
|
|
729
|
+
immediate = false;
|
|
730
|
+
held = now ? null : new AbortController();
|
|
731
|
+
const pass = await pollInboxOnce(deps, now ? 0 : waitSeconds, {
|
|
724
732
|
signal: shutdown.signal,
|
|
725
733
|
dispatch,
|
|
726
|
-
...(
|
|
734
|
+
...(held ? { waitSignal: held.signal } : {}),
|
|
735
|
+
...(!now && seen && dispatch.size > 0 && !heldPasses ? { seen } : {}),
|
|
727
736
|
});
|
|
737
|
+
held = null;
|
|
728
738
|
if (pass.bellAt)
|
|
729
739
|
seen = pass.bellAt;
|
|
730
740
|
lastPassAt = Date.now();
|
|
@@ -740,6 +750,12 @@ export function runInboxLoop(deps, opts = {}) {
|
|
|
740
750
|
catch (err) {
|
|
741
751
|
if (!running)
|
|
742
752
|
break;
|
|
753
|
+
// rereadNow cancelled a held read: read again at once, not as a failure.
|
|
754
|
+
if (held?.signal.aborted) {
|
|
755
|
+
held = null;
|
|
756
|
+
continue;
|
|
757
|
+
}
|
|
758
|
+
held = null;
|
|
743
759
|
consecutiveErrors++;
|
|
744
760
|
// a 429 already told us how long to wait, and every refused
|
|
745
761
|
// call still counts against the cap — so the exponential ladder digs
|
|
@@ -773,6 +789,12 @@ export function runInboxLoop(deps, opts = {}) {
|
|
|
773
789
|
get lastAttemptAt() {
|
|
774
790
|
return lastAttemptAt;
|
|
775
791
|
},
|
|
792
|
+
rereadNow() {
|
|
793
|
+
if (!running)
|
|
794
|
+
return;
|
|
795
|
+
immediate = true;
|
|
796
|
+
held?.abort();
|
|
797
|
+
},
|
|
776
798
|
async stop(timeoutMs = INBOX_STOP_TIMEOUT_MS) {
|
|
777
799
|
running = false;
|
|
778
800
|
// Cancel an idle long-poll; a pass already handed to the host keeps
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ziggs-ai/agent-sdk",
|
|
3
|
-
"version": "0.48.
|
|
3
|
+
"version": "0.48.3",
|
|
4
4
|
"description": "Agent framework SDK for building autonomous agents on the Ziggs platform",
|
|
5
5
|
"homepage": "https://ziggsai.com/docs",
|
|
6
6
|
"bugs": {
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"@anthropic-ai/claude-agent-sdk": "^0.3.284",
|
|
31
31
|
"@anthropic-ai/sdk": "^0.110.0",
|
|
32
32
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
33
|
-
"@ziggs-ai/api-client": "0.42.
|
|
34
|
-
"@ziggs-ai/contracts": "0.49.
|
|
33
|
+
"@ziggs-ai/api-client": "0.42.3",
|
|
34
|
+
"@ziggs-ai/contracts": "0.49.1",
|
|
35
35
|
"ajv": "^8.17.1",
|
|
36
36
|
"dotenv": "^17.2.3",
|
|
37
37
|
"openai": "^4.0.0",
|