@ziggs-ai/agent-sdk 0.48.21 → 0.48.23
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 +10 -0
- package/dist/Agent.d.ts +18 -0
- package/dist/Agent.js +75 -12
- package/dist/brain/claudeSdkTools.js +2 -2
- package/dist/platform/ZiggsEffectHandler.js +4 -4
- package/dist/platform/tools/tier1/protocolTools.js +1 -1
- package/dist/platform/tools/tier2/discoveryTools.d.ts +1 -0
- package/dist/platform/tools/tier2/discoveryTools.js +3 -2
- package/dist/runtime/executionController.d.ts +1 -1
- package/dist/runtime/executionController.js +13 -6
- package/dist/types.d.ts +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.48.23
|
|
6
|
+
|
|
7
|
+
- Hosted agents get `page` with the default bucket tools, beside `page_guide`.
|
|
8
|
+
- `people` (discovery tools) finds teammates by name.
|
|
9
|
+
- `task_create` says who can be given a task without an agreement: your person, a teammate, or an agent your owner runs.
|
|
10
|
+
|
|
11
|
+
## 0.48.22
|
|
12
|
+
|
|
13
|
+
- An agent's own `wake_at` that is refused because the work's audience or authority changed since it was set now runs once under a freshly prepared execution context. Before, every retry reused the ended context and was refused again.
|
|
14
|
+
|
|
5
15
|
## 0.48.21
|
|
6
16
|
|
|
7
17
|
## 0.48.20
|
package/dist/Agent.d.ts
CHANGED
|
@@ -273,6 +273,8 @@ export declare class Agent {
|
|
|
273
273
|
private wakeLedger;
|
|
274
274
|
/** Retries so far for an own wake whose turn failed, by wake id. */
|
|
275
275
|
private readonly wakeRetries;
|
|
276
|
+
/** Replaced in tests. */
|
|
277
|
+
private prepareExecution;
|
|
276
278
|
/** The per-agent inbox long-poll loop — this agent's sole wake source. */
|
|
277
279
|
private inboxLoop;
|
|
278
280
|
private inboxLoopEnabled;
|
|
@@ -302,6 +304,22 @@ export declare class Agent {
|
|
|
302
304
|
constructor(options?: AgentOptions);
|
|
303
305
|
private _validate;
|
|
304
306
|
private _setup;
|
|
307
|
+
/**
|
|
308
|
+
* Run one timer event on its lane. An agent's own wake that is refused
|
|
309
|
+
* because the work's audience or authority changed since it was set is run
|
|
310
|
+
* once more under a context prepared now: the backend checks the agent's
|
|
311
|
+
* authority again against the live audience, the way it does for a
|
|
312
|
+
* redelivered inbox item. Retrying under the saved context can only be
|
|
313
|
+
* refused again.
|
|
314
|
+
*/
|
|
315
|
+
private runTimerEvent;
|
|
316
|
+
/**
|
|
317
|
+
* The lane's action, prepared again, when `err` says its saved context was
|
|
318
|
+
* ended by a change of audience or authority. `'ended'` when the backend
|
|
319
|
+
* refuses it as no longer this agent's work (403 or 404). Undefined for any
|
|
320
|
+
* other failure, and for a lane with no exact action.
|
|
321
|
+
*/
|
|
322
|
+
private freshContextAfterChange;
|
|
305
323
|
private executionControlOn;
|
|
306
324
|
/**
|
|
307
325
|
* The door every work tool passes: the agent names a task it holds, the
|
package/dist/Agent.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { runWorkExecution } from '@ziggs-ai/api-client';
|
|
1
|
+
import { prepareWorkExecution, runWorkExecution } from '@ziggs-ai/api-client';
|
|
2
2
|
import { BucketsClient, MessageRecordsClient } from '@ziggs-ai/api-client/http';
|
|
3
3
|
import { responseCommand } from './runtime/messageCommand.js';
|
|
4
4
|
import { validateWorkExecution, withWorkExecution, currentWorkExecution } from '@ziggs-ai/api-client';
|
|
@@ -231,6 +231,8 @@ export class Agent {
|
|
|
231
231
|
wakeLedger;
|
|
232
232
|
/** Retries so far for an own wake whose turn failed, by wake id. */
|
|
233
233
|
wakeRetries = new Map();
|
|
234
|
+
/** Replaced in tests. */
|
|
235
|
+
prepareExecution = prepareWorkExecution;
|
|
234
236
|
/** The per-agent inbox long-poll loop — this agent's sole wake source. */
|
|
235
237
|
inboxLoop = null;
|
|
236
238
|
inboxLoopEnabled;
|
|
@@ -464,19 +466,80 @@ export class Agent {
|
|
|
464
466
|
// exact wake; a crash/failure leaves it durable, and an older completion
|
|
465
467
|
// cannot consume a timer armed while that work was running.
|
|
466
468
|
this.stateTimers = new StateTimers((ev, laneKey) => {
|
|
467
|
-
|
|
468
|
-
if (ev.type === 'wake-at') {
|
|
469
|
-
this.wakeRetries.delete(ev.wakeId);
|
|
470
|
-
this.wakeLedger.done(laneKey, ev.wakeId);
|
|
471
|
-
}
|
|
472
|
-
}).catch((err) => {
|
|
473
|
-
runtimeLog.warn('Agent', `state-timer frame failed laneKey=${laneKey}: ${err?.message || err}`);
|
|
474
|
-
if (ev.type === 'wake-at')
|
|
475
|
-
this.retryOwnWake(ev, laneKey);
|
|
476
|
-
});
|
|
477
|
-
this.wakeLedger.track(work);
|
|
469
|
+
this.wakeLedger.track(this.runTimerEvent(ev, laneKey));
|
|
478
470
|
});
|
|
479
471
|
}
|
|
472
|
+
/**
|
|
473
|
+
* Run one timer event on its lane. An agent's own wake that is refused
|
|
474
|
+
* because the work's audience or authority changed since it was set is run
|
|
475
|
+
* once more under a context prepared now: the backend checks the agent's
|
|
476
|
+
* authority again against the live audience, the way it does for a
|
|
477
|
+
* redelivered inbox item. Retrying under the saved context can only be
|
|
478
|
+
* refused again.
|
|
479
|
+
*/
|
|
480
|
+
async runTimerEvent(ev, laneKey) {
|
|
481
|
+
const settle = () => {
|
|
482
|
+
if (ev.type !== 'wake-at')
|
|
483
|
+
return;
|
|
484
|
+
this.wakeRetries.delete(ev.wakeId);
|
|
485
|
+
this.wakeLedger.done(laneKey, ev.wakeId);
|
|
486
|
+
};
|
|
487
|
+
try {
|
|
488
|
+
await this.eventQueue.enqueue(ev, laneKey);
|
|
489
|
+
settle();
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
catch (err) {
|
|
493
|
+
runtimeLog.warn('Agent', `state-timer frame failed laneKey=${laneKey}: ${err?.message || err}`);
|
|
494
|
+
if (ev.type !== 'wake-at')
|
|
495
|
+
return;
|
|
496
|
+
const fresh = await this.freshContextAfterChange(err, laneKey);
|
|
497
|
+
if (fresh === 'ended') {
|
|
498
|
+
// The backend says the work is no longer this agent's to do (the task
|
|
499
|
+
// ended or was handed on). The wake can never run again, so it is not
|
|
500
|
+
// retried or kept for the next start.
|
|
501
|
+
runtimeLog.info('Agent', `wake-at laneKey=${laneKey} dropped: its work has ended`);
|
|
502
|
+
settle();
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
if (fresh) {
|
|
506
|
+
try {
|
|
507
|
+
await this.eventQueue.enqueue(ev, laneKey, fresh);
|
|
508
|
+
runtimeLog.info('Agent', `wake-at laneKey=${laneKey} ran under a fresh execution context`);
|
|
509
|
+
settle();
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
catch (again) {
|
|
513
|
+
runtimeLog.warn('Agent', `wake-at laneKey=${laneKey} failed under a fresh execution context: ${again?.message || again}`);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
this.retryOwnWake(ev, laneKey);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* The lane's action, prepared again, when `err` says its saved context was
|
|
521
|
+
* ended by a change of audience or authority. `'ended'` when the backend
|
|
522
|
+
* refuses it as no longer this agent's work (403 or 404). Undefined for any
|
|
523
|
+
* other failure, and for a lane with no exact action.
|
|
524
|
+
*/
|
|
525
|
+
async freshContextAfterChange(err, laneKey) {
|
|
526
|
+
if (err?.code !== 'EXECUTION_CONTEXT_CHANGED')
|
|
527
|
+
return undefined;
|
|
528
|
+
const action = this.sessions.get(laneKey)?.executionContext?.action;
|
|
529
|
+
if (!action || !this.options.operatorKey || !this.options.agentId)
|
|
530
|
+
return undefined;
|
|
531
|
+
try {
|
|
532
|
+
return await this.prepareExecution(action, this.options.operatorKey, this.options.agentId, resolveBackendUrl());
|
|
533
|
+
}
|
|
534
|
+
catch (refused) {
|
|
535
|
+
runtimeLog.warn('Agent', `wake-at laneKey=${laneKey} could not prepare a fresh execution context: ${refused?.message || refused}`);
|
|
536
|
+
// Refused or gone: no later attempt is authorized either.
|
|
537
|
+
const status = refused?.status;
|
|
538
|
+
if (status === 403 || status === 404)
|
|
539
|
+
return 'ended';
|
|
540
|
+
return undefined;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
480
543
|
executionControlOn() {
|
|
481
544
|
return this.options.executionControl ?? isClaudeCognition(this.options.cognition);
|
|
482
545
|
}
|
|
@@ -85,10 +85,10 @@ export { listTasksTool, cancelTaskTool, delegateTaskTool, passTaskOnTool };
|
|
|
85
85
|
* with the people it is for and sends inside it. A file reaches people the same
|
|
86
86
|
* way, by being put in a bucket with them: `bucket_create` takes items, and
|
|
87
87
|
* `bucket_insert` puts one in a bucket that exists. `page_guide` is how a
|
|
88
|
-
* working page is built
|
|
88
|
+
* working page is built, and `page` posts it. Every hosted
|
|
89
89
|
* agent has these, the same tool objects `BUCKET_TOOLS` hands out.
|
|
90
90
|
*/
|
|
91
|
-
const BUCKET_DEFAULTS = BUCKET_TOOLS.filter((tool) => ['bucket_create', 'bucket_send', 'bucket_insert', 'page_guide'].includes(String(tool.schema.function.name)));
|
|
91
|
+
const BUCKET_DEFAULTS = BUCKET_TOOLS.filter((tool) => ['bucket_create', 'bucket_send', 'bucket_insert', 'page_guide', 'page'].includes(String(tool.schema.function.name)));
|
|
92
92
|
export const CLAUDE_SDK_TOOLS = [
|
|
93
93
|
contextSnapshotTool,
|
|
94
94
|
messageSendTool,
|
|
@@ -206,7 +206,7 @@ export async function executeToolWithSideEffects(deps, eff, effect, roster) {
|
|
|
206
206
|
state: 'started',
|
|
207
207
|
tool: effect.name,
|
|
208
208
|
...(argsPreview ? { args: argsPreview } : {}),
|
|
209
|
-
}, effect.writeKeys?.artifactKey({ s: 'started', t: effect.name, a: argsPreview }), binding
|
|
209
|
+
}, effect.writeKeys?.artifactKey({ s: 'started', t: effect.name, a: argsPreview }), (binding ? binding.agreementId ?? undefined : effect.serviceAgreementId), binding?.taskId);
|
|
210
210
|
const lastUser = roster.users.find((u) => u.userId || u.id);
|
|
211
211
|
// Accumulate token usage from any nested LLM call the tool makes (llmTool),
|
|
212
212
|
// so it can be folded into the turn's authoritative token count.
|
|
@@ -240,7 +240,7 @@ export async function executeToolWithSideEffects(deps, eff, effect, roster) {
|
|
|
240
240
|
senderId: effect.senderId ?? lastUser?.userId ?? lastUser?.id,
|
|
241
241
|
senderType: effect.senderType ?? (lastUser ? 'USER' : undefined),
|
|
242
242
|
onBehalfOfAgreementId: binding?.agreementId ?? effect.onBehalfOfAgreementId,
|
|
243
|
-
serviceAgreementId: binding
|
|
243
|
+
serviceAgreementId: (binding ? binding.agreementId ?? undefined : effect.serviceAgreementId),
|
|
244
244
|
...(binding ? { executionTaskId: binding.taskId, wakeAgreementId: binding.agreementId } : {}),
|
|
245
245
|
memory: effect.memory,
|
|
246
246
|
writeKeys: effect.writeKeys,
|
|
@@ -263,7 +263,7 @@ export async function executeToolWithSideEffects(deps, eff, effect, roster) {
|
|
|
263
263
|
state: 'completed',
|
|
264
264
|
tool: effect.name,
|
|
265
265
|
result: clipped,
|
|
266
|
-
}, effect.writeKeys?.artifactKey({ s: 'completed', t: effect.name, r: clipped }), binding
|
|
266
|
+
}, effect.writeKeys?.artifactKey({ s: 'completed', t: effect.name, r: clipped }), (binding ? binding.agreementId ?? undefined : effect.serviceAgreementId), binding?.taskId);
|
|
267
267
|
sendTelemetry(deps.telemetryClient, buildToolIngestPayload({
|
|
268
268
|
sessionId: effect.sessionId,
|
|
269
269
|
tool: effect.name,
|
|
@@ -281,7 +281,7 @@ export async function executeToolWithSideEffects(deps, eff, effect, roster) {
|
|
|
281
281
|
state: 'failed',
|
|
282
282
|
tool: effect.name,
|
|
283
283
|
error: errMsg,
|
|
284
|
-
}, effect.writeKeys?.artifactKey({ s: 'failed', t: effect.name, e: errMsg }), binding
|
|
284
|
+
}, effect.writeKeys?.artifactKey({ s: 'failed', t: effect.name, e: errMsg }), (binding ? binding.agreementId ?? undefined : effect.serviceAgreementId), binding?.taskId);
|
|
285
285
|
sendTelemetry(deps.telemetryClient, buildToolIngestPayload({
|
|
286
286
|
sessionId: effect.sessionId,
|
|
287
287
|
tool: effect.name,
|
|
@@ -133,7 +133,7 @@ export const taskUpdatePlanStepTool = defineTool('task_update_plan_step', {
|
|
|
133
133
|
description: "Who this task now waits on, because you just asked them: { kind: 'user' | 'agent', id } — both fields required. Send it when you ask — with the step you are ticking, or on its own when the ask is all that happened. Your person then sees the task as waiting on them rather than as running, which is the difference between a job that looks stalled and one that is waiting for an answer. It clears itself: any later progress that does not restate it, and any terminal state, drops it.",
|
|
134
134
|
},
|
|
135
135
|
}, handlerFor('task_update_plan_step'), { description: "Update the status of a single step within a task's plan, and say who you are waiting on when you have just asked somebody. A task with no plan can still carry the waiting-on on its own." });
|
|
136
|
-
export const taskCreateTool = defineTool('task_create', { agreementId: { type: 'string', description: 'Agreement the work is done under. Omit for a teammate or an agent your owner runs.' }, description: { type: 'string', required: true }, parentTaskId: 'string', assigneeId: { type: 'string', description: '
|
|
136
|
+
export const taskCreateTool = defineTool('task_create', { agreementId: { type: 'string', description: 'Agreement the work is done under. Omit for a teammate or an agent your owner runs.' }, description: { type: 'string', required: true }, parentTaskId: 'string', assigneeId: { type: 'string', description: 'Who works it: your person, a teammate, an agent your owner runs, or under agreementId anyone it lets you give work. Required without agreementId.' }, inputArtifactIds: { type: 'array', items: { type: 'string' }, description: 'Prior-step output artifact handles, for structured input links.' }, plan: { type: 'object' }, planReviewTiming: planReviewTimingParam, requireMidWorkPlanAck: 'boolean', dueAt: dueAtParam, checkBack: checkBackParam, sources: SOURCES_PARAM }, handlerFor('task_create'), { description: 'Give someone a task: your person, a teammate, an agent your owner runs, or anyone an agreement lets you give work (name it as agreementId). For work that means chasing an answer out of somebody, set dueAt and checkBack so the holder knows when to stop and how often it may remind.' });
|
|
137
137
|
export const PROTOCOL_TOOLS = [
|
|
138
138
|
agreementProposeTool, agreementSubcontractTool,
|
|
139
139
|
agreementRespondTool, agreementClaimTool, agreementCounterTool, agreementGetTool, agreementRevokeTool,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ToolDefinition } from '../../../tools/defineTool.js';
|
|
2
2
|
export declare const agentSearchTool: ToolDefinition;
|
|
3
3
|
export declare const agentGetTool: ToolDefinition;
|
|
4
|
+
export declare const peopleTool: ToolDefinition;
|
|
4
5
|
export declare const DISCOVERY_TOOLS: ToolDefinition[];
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { agentSearchCapability, agentGetCapability } from '@ziggs-ai/api-client';
|
|
1
|
+
import { agentSearchCapability, agentGetCapability, peopleCapability } from '@ziggs-ai/api-client';
|
|
2
2
|
import { toolFromCapability } from '../../../tools/capabilityAdapter.js';
|
|
3
3
|
// agent discovery is a shared capability definition (api-client),
|
|
4
4
|
// so search shaping (zero-hit hint, reachability rows) is identical
|
|
5
5
|
// on both surfaces.
|
|
6
6
|
export const agentSearchTool = toolFromCapability(agentSearchCapability);
|
|
7
7
|
export const agentGetTool = toolFromCapability(agentGetCapability);
|
|
8
|
-
export const
|
|
8
|
+
export const peopleTool = toolFromCapability(peopleCapability);
|
|
9
|
+
export const DISCOVERY_TOOLS = [agentSearchTool, agentGetTool, peopleTool];
|
|
@@ -3,7 +3,7 @@ import type { Task } from '@ziggs-ai/api-client';
|
|
|
3
3
|
import type { ToolDefinition } from '../tools/defineTool.js';
|
|
4
4
|
type Row = Record<string, unknown>;
|
|
5
5
|
export interface ExecutionBinding {
|
|
6
|
-
agreementId: string;
|
|
6
|
+
agreementId: string | null;
|
|
7
7
|
taskId: string;
|
|
8
8
|
}
|
|
9
9
|
interface ControllerOptions {
|
|
@@ -97,7 +97,9 @@ export class ExecutionController {
|
|
|
97
97
|
const binding = await this.verify(taskId, TASK_MANAGEMENT.has(name));
|
|
98
98
|
for (const key of AUTHORITY_ARGS) {
|
|
99
99
|
if (args[key] != null && args[key] !== binding.agreementId) {
|
|
100
|
-
this.refuse('AGREEMENT_SCOPE_MISMATCH',
|
|
100
|
+
this.refuse('AGREEMENT_SCOPE_MISMATCH', binding.agreementId
|
|
101
|
+
? `${key} must be the task's own agreement (${binding.agreementId}).`
|
|
102
|
+
: `${key} must be left out: the task has no agreement, so it lends no agreement's authority.`);
|
|
101
103
|
}
|
|
102
104
|
}
|
|
103
105
|
const handlerArgs = { ...args };
|
|
@@ -116,11 +118,16 @@ export class ExecutionController {
|
|
|
116
118
|
if (task.taskId !== taskId || (task.executorIsYou !== true && task.assigneeId !== this.options.agentId)) {
|
|
117
119
|
this.refuse('TASK_NOT_HELD', `Task ${taskId} is not assigned to you. Work only under a task you hold.`);
|
|
118
120
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
121
|
+
// A task given with no agreement (by the person who runs you, or a
|
|
122
|
+
// teammate) is work of its own: no agreement above it to check. A task
|
|
123
|
+
// that names one works only while that agreement is active work.
|
|
124
|
+
const agreementId = id(task.agreementId) ?? null;
|
|
125
|
+
if (agreementId) {
|
|
126
|
+
const agreement = row(await this.options.readAgreement(agreementId));
|
|
127
|
+
if (agreement.agreementId !== agreementId || agreement.status !== 'active'
|
|
128
|
+
|| agreement.engagementKind === 'link' || isListing(agreement)) {
|
|
129
|
+
this.refuse('AGREEMENT_INACTIVE', 'The task\'s agreement is not an active work agreement. Conversation links and listings do not authorize work.');
|
|
130
|
+
}
|
|
124
131
|
}
|
|
125
132
|
const state = String(task.state);
|
|
126
133
|
if (CLOSED.has(state) || task.control?.action === 'stop') {
|
package/dist/types.d.ts
CHANGED
|
@@ -404,7 +404,7 @@ export interface ToolCallResult {
|
|
|
404
404
|
errorCode?: string;
|
|
405
405
|
/** Host-verified work binding, supplied by the execution controller. */
|
|
406
406
|
execution?: {
|
|
407
|
-
agreementId: string;
|
|
407
|
+
agreementId: string | null;
|
|
408
408
|
taskId: string;
|
|
409
409
|
};
|
|
410
410
|
result?: unknown;
|
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.23",
|
|
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.
|
|
33
|
+
"@ziggs-ai/api-client": "0.42.21",
|
|
34
|
+
"@ziggs-ai/contracts": "0.53.5",
|
|
35
35
|
"ajv": "^8.17.1",
|
|
36
36
|
"dotenv": "^17.2.3",
|
|
37
37
|
"openai": "^4.0.0",
|