@ziggs-ai/agent-sdk 0.45.3 → 0.46.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.46.0
6
+
7
+ - An agent wakes once when its own proposal is approved or declined, and carries on under that agreement. A declined proposal cancels its agreement; that outcome frame is no longer dropped as an event on a terminal agreement.
8
+ - Removed the hire-activation skip. `actsOnHireActivation` (Agent and ClaudeBrain option) is gone, and so are `isHireActivationNotice`, `shouldSkipAgentFormedHireActivation` and the `agent_formed_hire_activation` / `task_only_activation` no-op reasons. A hired provider no longer gets an activation wake from the server, so there is nothing to skip; it waits for assigned work.
9
+ - While wakes run, the inbox loop passes the last envelope's `bellAt` back as `seen`, so the server holds the read until new mail arrives instead of the loop re-reading every few seconds. A message from someone else starts at once, and a busy agent no longer runs into the inbox polling limit.
10
+
5
11
  ## 0.45.3
6
12
 
7
13
  - `sharedInbox` (or `ZIGGS_AGENT_SHARED_INBOX=1`) runs the agent as one of several host processes. Each read tells the server how many more threads this process can start, so work spreads across processes and one thread stays on one process at a time. Only the process holding the inbox lease runs the agent's declared polls and restores its saved wake-ups, and the polls move when leadership does. Every wake reloads the thread's session from `sessionStore`, since the thread may have last run elsewhere. Requires api-client 0.40.3.
package/dist/Agent.d.ts CHANGED
@@ -111,12 +111,6 @@ export interface AgentOptions {
111
111
  cognition?: CognitionKind;
112
112
  /** Code-enforced work agreement/task binding. Defaults on for the Claude brain; other brains can opt in. */
113
113
  executionControl?: boolean;
114
- /**
115
- * Spend a model turn on an activation notice for a hire an agent formed.
116
- * Default off — the host records a no-op and waits for the assigned task.
117
- * A hire a person formed (store claim) still wakes regardless of this flag.
118
- */
119
- actsOnHireActivation?: boolean;
120
114
  /**
121
115
  * Before a Claude turn on chat messages, ask the backend whether
122
116
  * they ask this agent for anything; a confident "no" skips the turn. On by
package/dist/Agent.js CHANGED
@@ -49,7 +49,6 @@ import { SeenMessages } from './platform/SeenMessages.js';
49
49
  import { runtimeLog } from './shared/runtimeLog.js';
50
50
  import { isTelemetryIngestEnabled, sendTelemetry, } from './platform/telemetryIngest.js';
51
51
  import { buildWakeOutcomePayload, classifyWakeOutcome, wakeWasAsked, } from './runtime/wakeOutcome.js';
52
- import { agreementIdFromWake, formedByFromWake, isHireActivationNotice, shouldSkipAgentFormedHireActivation, } from './brain/hireActivationNotice.js';
53
52
  // ConnectionPool lives in a separate module; resolved via a computed-path
54
53
  // dynamic import to avoid a circular import with Agent.
55
54
  async function loadConnectionPool() {
@@ -291,7 +290,6 @@ export class Agent {
291
290
  pollKinds: resolved.pollKinds,
292
291
  cognition: resolved.cognition ?? 'fsm',
293
292
  executionControl: resolved.executionControl,
294
- actsOnHireActivation: resolved.actsOnHireActivation === true,
295
293
  wakeGate: resolved.wakeGate,
296
294
  claudeMaxTurns: resolved.claudeMaxTurns,
297
295
  claudeStatelessPerWake: resolved.claudeStatelessPerWake,
@@ -434,7 +432,6 @@ export class Agent {
434
432
  // services from the effect handler's deps like the FSM path.
435
433
  maxTurns: this.options.claudeMaxTurns,
436
434
  statelessPerWake: this.options.claudeStatelessPerWake,
437
- actsOnHireActivation: this.options.actsOnHireActivation === true,
438
435
  ...(this.options.wakeGate === false || !this.options.operatorKey
439
436
  ? {}
440
437
  : {
@@ -846,7 +843,9 @@ export class Agent {
846
843
  async wakeSuppression(event, _sessionId) {
847
844
  const execution = currentWorkExecution();
848
845
  const agreementId = execution ? execution.agreementId : workScopeFromWake(event).agreementId;
849
- if (await this.agreementIsTerminal(agreementId)) {
846
+ // A declined proposal cancels its agreement, and its proposer still wakes
847
+ // once to carry on: that outcome is the one terminal frame with work in it.
848
+ if (!isProposalOutcome(event) && await this.agreementIsTerminal(agreementId)) {
850
849
  return { reason: 'agreement_terminal', because: 'its agreement is terminal' };
851
850
  }
852
851
  if (this.isSettledTaskEcho(event)) {
@@ -855,25 +854,6 @@ export class Agent {
855
854
  because: 'its task already reported a result',
856
855
  };
857
856
  }
858
- if (isHireActivationNotice(event)) {
859
- const id = agreementIdFromWake(event);
860
- const agreement = id && this.options.actsOnHireActivation !== true
861
- ? await this.agreementService.get(id).catch(() => null)
862
- : null;
863
- if (agreement?.terms?.interactionMode === 'tasks')
864
- return { reason: 'task_only_activation', because: 'task-only service waits for assigned work' };
865
- const formedBy = formedByFromWake(event) ?? agreement?.formedBy;
866
- if (shouldSkipAgentFormedHireActivation({
867
- event,
868
- formedBy,
869
- actsOnHireActivation: this.options.actsOnHireActivation === true,
870
- })) {
871
- return {
872
- reason: 'agent_formed_hire_activation',
873
- because: 'agent-formed hire activation',
874
- };
875
- }
876
- }
877
857
  return null;
878
858
  }
879
859
  /**
@@ -1980,3 +1960,9 @@ export function readScopesForWake(asked, wake) {
1980
1960
  });
1981
1961
  return narrowed.every(Boolean) ? narrowed : wake;
1982
1962
  }
1963
+ /** The outcome of this agent's own proposal (the server hands it only to the proposer). */
1964
+ function isProposalOutcome(event) {
1965
+ const frame = (event ?? {});
1966
+ const reason = frame.reason ?? frame.resource?.reason;
1967
+ return reason === 'proposal_approved' || reason === 'proposal_approved_execute' || reason === 'proposal_rejected';
1968
+ }
@@ -47,12 +47,6 @@ export interface ClaudeBrainOptions {
47
47
  queryFn?: typeof query;
48
48
  /** Full authoritative agreement read used to recognize listing bookkeeping. */
49
49
  readAgreement?: (agreementId: string) => Promise<unknown>;
50
- /**
51
- * Opt in to spending a model turn on an activation notice for a hire
52
- * this agent's counterparty formed. Default is off — the host records a
53
- * no-op and waits for the task.
54
- */
55
- actsOnHireActivation?: boolean;
56
50
  /**
57
51
  * Asked before a turn is spent on chat messages; a confident
58
52
  * "context" skips the turn. Absent means no gate (the default here; the
@@ -106,7 +100,6 @@ export declare class ClaudeBrain implements Brain {
106
100
  private statelessPerWake;
107
101
  private queryFn;
108
102
  private readAgreement;
109
- private actsOnHireActivation;
110
103
  private askWakeGate;
111
104
  /**
112
105
  * Per-lane tool context. One agent object serves every room, and a
@@ -15,7 +15,6 @@ import { assertHostedAgentZiggsTools } from './hostedAgentConnection.js';
15
15
  import { runtimeLog } from '../shared/runtimeLog.js';
16
16
  import { resolveOnBehalfAgreementId, } from './onBehalfAgreement.js';
17
17
  import { filterStandingOfferNotices } from './standingOfferNotice.js';
18
- import { formedByFromWake, shouldSkipAgentFormedHireActivation, } from './hireActivationNotice.js';
19
18
  import { gateableMessages, wakeAddressId, wakeAgreementId } from './wakeGate.js';
20
19
  /**
21
20
  * status notices must not spend a Claude turn answering
@@ -208,7 +207,6 @@ export class ClaudeBrain {
208
207
  statelessPerWake;
209
208
  queryFn;
210
209
  readAgreement;
211
- actsOnHireActivation;
212
210
  askWakeGate;
213
211
  /**
214
212
  * Per-lane tool context. One agent object serves every room, and a
@@ -245,7 +243,6 @@ export class ClaudeBrain {
245
243
  operatorKey: this.operatorKey,
246
244
  agentId: this.agentId,
247
245
  }));
248
- this.actsOnHireActivation = opts.actsOnHireActivation === true;
249
246
  this.askWakeGate = opts.askWakeGate ?? null;
250
247
  }
251
248
  async tick({ event, ctx, state, identity, eff, memory, signal, checkout }) {
@@ -265,22 +262,6 @@ export class ClaudeBrain {
265
262
  };
266
263
  const nextCtx = bootstrapCtx(identity, ctx);
267
264
  nextCtx.lastOutcome = outcomeFromEvent(rawEvent ?? null, identity.agentId);
268
- if (shouldSkipAgentFormedHireActivation({
269
- event: rawEvent,
270
- formedBy: formedByFromWake(rawEvent),
271
- actsOnHireActivation: this.actsOnHireActivation,
272
- })) {
273
- const sessionId = identity.sessionId;
274
- runtimeLog.info('ClaudeBrain', `agent-formed hire activation — skipping LLM session=${sessionId} agent=${this.agentId}`);
275
- return {
276
- ctx: nextCtx,
277
- state: state ?? DEFAULT_STATE,
278
- parked: true,
279
- stateTimeoutUnhandled: false,
280
- metrics: { llmCalls: 0, tokens: { total: 0, input: 0, output: 0 } },
281
- skippedReason: 'agent_formed_hire_activation',
282
- };
283
- }
284
265
  if (isNoticeOnlyWake(rawEvent)) {
285
266
  runtimeLog.info('ClaudeBrain', `notice-only wake — skipping LLM session=${identity.sessionId} agent=${this.agentId} ` +
286
267
  `type=${rawEvent?.type ?? 'unknown'}`);
@@ -68,6 +68,8 @@ export interface InboxPassResult {
68
68
  acked: boolean;
69
69
  /** True when there was more mail than one envelope carries. */
70
70
  truncated: boolean;
71
+ /** The latest delivery this envelope answered, to pass back as `seen`. */
72
+ bellAt?: string;
71
73
  /**
72
74
  * Handovers into the host that failed this pass. Non-zero means the
73
75
  * watermark was deliberately held, so the same window arrives again.
@@ -156,6 +158,7 @@ export declare function pollInboxOnce(deps: InboxLoopDeps, waitSeconds?: number,
156
158
  forceAck?: boolean;
157
159
  signal?: AbortSignal;
158
160
  dispatch?: InboxDispatch;
161
+ seen?: string;
159
162
  }): Promise<InboxPassResult>;
160
163
  export interface InboxLoopHandle {
161
164
  /**
@@ -203,11 +206,10 @@ export declare const INBOX_STOP_TIMEOUT_MS = 30000;
203
206
  *
204
207
  * Wakes do not hold the loop: a pass starts its wakes (up to the agent's
205
208
  * bound) and the loop reads again, so a new thread is taken up while another
206
- * is still being answered. The server keeps listing a row until it is handled,
207
- * so while wakes run a read can come back at once with nothing new in it; then
208
- * the loop waits for one of them to finish, or a few seconds, before reading
209
- * again. A message from someone else is taken up within that recheck, not
210
- * after the running wake.
209
+ * is still being answered. The server lists a row until it is handled, so
210
+ * while wakes run the loop passes back the envelope's `bellAt` as `seen`: the
211
+ * held read then answers only mail delivered after it, and a message from
212
+ * someone else is taken up as soon as it arrives.
211
213
  *
212
214
  * The FIRST pass is an immediate read. A held poll only answers to new mail, so
213
215
  * a host that just started (or restarted after a crash) would otherwise sit
@@ -216,5 +218,4 @@ export declare const INBOX_STOP_TIMEOUT_MS = 30000;
216
218
  */
217
219
  export declare function runInboxLoop(deps: InboxLoopDeps, opts?: {
218
220
  waitSeconds?: number;
219
- busyRecheckMs?: number;
220
221
  }): InboxLoopHandle;
@@ -203,6 +203,7 @@ export async function pollInboxOnce(deps, waitSeconds = 0, opts = {}) {
203
203
  : inboxConcurrency(deps.concurrency);
204
204
  const envelope = await inbox.getInbox({
205
205
  ...(waitSeconds > 0 ? { waitSeconds } : {}),
206
+ ...(opts.seen ? { seen: opts.seen } : {}),
206
207
  ...(opts.signal ? { signal: opts.signal } : {}),
207
208
  ...(shared ? { capacity: free } : {}),
208
209
  });
@@ -599,6 +600,7 @@ export async function pollInboxOnce(deps, waitSeconds = 0, opts = {}) {
599
600
  'window will be redelivered');
600
601
  }
601
602
  return {
603
+ ...(envelope.bellAt ? { bellAt: envelope.bellAt } : {}),
602
604
  deliveries: envelope.deliveries.length,
603
605
  messagesDelivered,
604
606
  resourceEvents,
@@ -619,9 +621,8 @@ export async function pollInboxOnce(deps, waitSeconds = 0, opts = {}) {
619
621
  * some defaults ship with. Lower it if your deployment sits behind a shorter one.
620
622
  */
621
623
  const DEFAULT_WAIT_SECONDS = 110;
622
- /** While wakes run, how soon to read again for a new thread. The server keeps
623
- * listing the running rows, so a held read cannot wait for new mail then. */
624
- const BUSY_RECHECK_MS = 3_000;
624
+ /** The shortest gap between two reads that found nothing new. */
625
+ const IDLE_REREAD_MS = 1_000;
625
626
  const ERROR_BACKOFF_BASE_MS = 1_000;
626
627
  const ERROR_BACKOFF_MAX_MS = 30_000;
627
628
  /**
@@ -671,11 +672,10 @@ function withinMs(promise, ms) {
671
672
  *
672
673
  * Wakes do not hold the loop: a pass starts its wakes (up to the agent's
673
674
  * bound) and the loop reads again, so a new thread is taken up while another
674
- * is still being answered. The server keeps listing a row until it is handled,
675
- * so while wakes run a read can come back at once with nothing new in it; then
676
- * the loop waits for one of them to finish, or a few seconds, before reading
677
- * again. A message from someone else is taken up within that recheck, not
678
- * after the running wake.
675
+ * is still being answered. The server lists a row until it is handled, so
676
+ * while wakes run the loop passes back the envelope's `bellAt` as `seen`: the
677
+ * held read then answers only mail delivered after it, and a message from
678
+ * someone else is taken up as soon as it arrives.
679
679
  *
680
680
  * The FIRST pass is an immediate read. A held poll only answers to new mail, so
681
681
  * a host that just started (or restarted after a crash) would otherwise sit
@@ -685,8 +685,11 @@ function withinMs(promise, ms) {
685
685
  export function runInboxLoop(deps, opts = {}) {
686
686
  const label = deps.label ?? 'inboxLoop';
687
687
  const waitSeconds = opts.waitSeconds ?? DEFAULT_WAIT_SECONDS;
688
- const busyRecheckMs = Math.min(opts.busyRecheckMs ?? BUSY_RECHECK_MS, waitSeconds * 1000);
689
688
  const dispatch = new InboxDispatch(deps.concurrency);
689
+ // The delivery the last read answered. Passed back while wakes run, so the
690
+ // next held read waits for new mail; never after a failed pass, whose rows
691
+ // must come back on the retry.
692
+ let seen;
690
693
  let running = true;
691
694
  let consecutiveErrors = 0;
692
695
  let heldPasses = 0;
@@ -702,7 +705,13 @@ export function runInboxLoop(deps, opts = {}) {
702
705
  while (running) {
703
706
  try {
704
707
  lastAttemptAt = Date.now();
705
- const pass = await pollInboxOnce(deps, first ? 0 : waitSeconds, { signal: shutdown.signal, dispatch });
708
+ const pass = await pollInboxOnce(deps, first ? 0 : waitSeconds, {
709
+ signal: shutdown.signal,
710
+ dispatch,
711
+ ...(seen && dispatch.size > 0 && !heldPasses ? { seen } : {}),
712
+ });
713
+ if (pass.bellAt)
714
+ seen = pass.bellAt;
706
715
  lastPassAt = Date.now();
707
716
  first = false;
708
717
  consecutiveErrors = 0;
@@ -711,7 +720,7 @@ export function runInboxLoop(deps, opts = {}) {
711
720
  if (heldPasses)
712
721
  await sleep(Math.min(ERROR_BACKOFF_MAX_MS, ERROR_BACKOFF_BASE_MS * 2 ** Math.min(heldPasses - 1, 5)), shutdown.signal);
713
722
  else if (dispatch.size > 0 && !passMadeProgress(pass))
714
- await dispatch.settledOr(busyRecheckMs, shutdown.signal);
723
+ await dispatch.settledOr(IDLE_REREAD_MS, shutdown.signal);
715
724
  }
716
725
  catch (err) {
717
726
  if (!running)
@@ -43,7 +43,6 @@ export function createSkillAgent(options) {
43
43
  },
44
44
  tools: [...SKILL_ARTIFACT_TOOLS, accessRequestTool],
45
45
  taskTools: 'all',
46
- actsOnHireActivation: true,
47
46
  respondsToProposals: true,
48
47
  metricsTap: options.metricsTap,
49
48
  initial: 'ready',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ziggs-ai/agent-sdk",
3
- "version": "0.45.3",
3
+ "version": "0.46.0",
4
4
  "description": "Agent framework SDK for building autonomous agents on the Ziggs platform",
5
5
  "homepage": "https://ziggsai.com/docs",
6
6
  "bugs": {
@@ -1,19 +0,0 @@
1
- /**
2
- * Whether a hire-activation notice earns a model call is the host's
3
- * decision. The rule reads the agreement row (`formedBy`), never an
4
- * agent kind, name, or id shape.
5
- *
6
- * A hire an agent formed is a recorded no-op unless the hired agent's
7
- * manifest opts in. A hire a person formed (store claim) still wakes
8
- * so the provider can open the room and greet.
9
- */
10
- export type AgreementFormedBy = 'agent' | 'principal';
11
- export declare function formedByFromWake(event: unknown): AgreementFormedBy | undefined;
12
- export declare function agreementIdFromWake(event: unknown): string | undefined;
13
- /** Chat activation ping, store-claim doorbell, or approval-echo fan-out. */
14
- export declare function isHireActivationNotice(event: unknown): boolean;
15
- export declare function shouldSkipAgentFormedHireActivation(input: {
16
- event: unknown;
17
- formedBy?: AgreementFormedBy;
18
- actsOnHireActivation?: boolean;
19
- }): boolean;
@@ -1,80 +0,0 @@
1
- /**
2
- * Whether a hire-activation notice earns a model call is the host's
3
- * decision. The rule reads the agreement row (`formedBy`), never an
4
- * agent kind, name, or id shape.
5
- *
6
- * A hire an agent formed is a recorded no-op unless the hired agent's
7
- * manifest opts in. A hire a person formed (store claim) still wakes
8
- * so the provider can open the room and greet.
9
- */
10
- import { SERVER_EVENTS } from '@ziggs-ai/contracts';
11
- const ACTIVATION_LIFECYCLE_OPS = new Set([
12
- 'proposal_approved',
13
- 'proposal_approved_execute',
14
- ]);
15
- function asRecord(value) {
16
- return value && typeof value === 'object' ? value : null;
17
- }
18
- export function formedByFromWake(event) {
19
- const ev = asRecord(event);
20
- if (!ev)
21
- return undefined;
22
- const direct = ev.formedBy;
23
- if (direct === 'agent' || direct === 'principal')
24
- return direct;
25
- const agreement = asRecord(ev.agreement);
26
- const fromAgreement = agreement?.formedBy;
27
- if (fromAgreement === 'agent' || fromAgreement === 'principal')
28
- return fromAgreement;
29
- const resource = asRecord(ev.resource);
30
- const fromResource = resource?.formedBy;
31
- if (fromResource === 'agent' || fromResource === 'principal')
32
- return fromResource;
33
- return undefined;
34
- }
35
- export function agreementIdFromWake(event) {
36
- const ev = asRecord(event);
37
- if (!ev)
38
- return undefined;
39
- if (typeof ev.agreementId === 'string' && ev.agreementId)
40
- return ev.agreementId;
41
- const agreement = asRecord(ev.agreement);
42
- if (typeof agreement?.agreementId === 'string' && agreement.agreementId) {
43
- return agreement.agreementId;
44
- }
45
- const resource = asRecord(ev.resource);
46
- if (typeof resource?.agreementId === 'string' && resource.agreementId) {
47
- return resource.agreementId;
48
- }
49
- if (resource?.kind === 'agreement' &&
50
- typeof resource.resourceId === 'string' &&
51
- resource.resourceId) {
52
- return resource.resourceId;
53
- }
54
- return undefined;
55
- }
56
- /** Chat activation ping, store-claim doorbell, or approval-echo fan-out. */
57
- export function isHireActivationNotice(event) {
58
- const ev = asRecord(event);
59
- if (!ev)
60
- return false;
61
- const type = ev.type;
62
- const operation = typeof ev.operation === 'string' ? ev.operation : undefined;
63
- if (type === 'agreement_lifecycle' && operation && ACTIVATION_LIFECYCLE_OPS.has(operation)) {
64
- return true;
65
- }
66
- if (type !== SERVER_EVENTS.resourceChanged)
67
- return false;
68
- const resource = asRecord(ev.resource) ?? ev;
69
- const reason = typeof resource.reason === 'string' ? resource.reason : undefined;
70
- if (reason === 'proposal_approved')
71
- return true;
72
- return typeof reason === 'string' && reason.startsWith('approval:');
73
- }
74
- export function shouldSkipAgentFormedHireActivation(input) {
75
- if (input.actsOnHireActivation)
76
- return false;
77
- if (input.formedBy !== 'agent')
78
- return false;
79
- return isHireActivationNotice(input.event);
80
- }