@ziggs-ai/agent-sdk 0.43.5 → 0.43.6

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.43.6
6
+
7
+ - Completing a delegated task now returns its result to the work that delegated it. A delegated result only reaches the delegator as a returned output artifact, and an agent that closed its task with `task_set_result` returned nothing, so the delegator was never woken and never saw the result. Before completing a delegated task, the SDK records the result as the task's output artifact. After completing it, the SDK returns that artifact. If either step fails, the failure is logged and the completion still stands.
8
+
5
9
  ## 0.43.5
6
10
 
7
11
  - A task's input bodies (0.43.4) now actually reach a hosted workflow agent. The agent pins every context read in a wake to that wake's work, and that pin also dropped the artifact the input read named, so the read came back without a body. A read may now narrow to one artifact of the same task or agreement; any other read still gets the wake's own scope.
@@ -34,6 +34,15 @@ export declare class TaskService {
34
34
  resultRecorded?: boolean;
35
35
  terminalState?: string;
36
36
  }>;
37
+ /**
38
+ * A delegated task's result only reaches the work that delegated it as a
39
+ * returned output artifact. A workflow agent closes its task with a result
40
+ * and nothing else, so the delegator never woke and never saw it. Before
41
+ * completing, record the result as this task's output; after, return it.
42
+ * Either step failing leaves the completion itself untouched.
43
+ */
44
+ private delegatedOutput;
45
+ private returnDelegatedOutput;
37
46
  /**
38
47
  * Say who this task is waiting on, with no other progress to post.
39
48
  *
@@ -1,4 +1,4 @@
1
- import { createTask, getTask, getActiveTasksForAgent, getSubtasks, updateTaskState, updateTaskPlanStep, updateTaskPlanSteps, cancelTask, reportTask, setTaskSatisfaction, countTasks, acknowledgeTaskControl, presentTaskOutcome, } from '@ziggs-ai/api-client';
1
+ import { createTask, getTask, getActiveTasksForAgent, getSubtasks, updateTaskState, updateTaskPlanStep, updateTaskPlanSteps, cancelTask, reportTask, setTaskSatisfaction, countTasks, acknowledgeTaskControl, presentTaskOutcome, returnTaskResult, ArtifactsClient, } from '@ziggs-ai/api-client';
2
2
  import { runtimeLog } from '../../shared/runtimeLog.js';
3
3
  function safeJsonStringify(value) {
4
4
  if (value === null || value === undefined)
@@ -64,8 +64,11 @@ export class TaskService {
64
64
  ...(idempotencyKey ? { idempotencyKey } : {}),
65
65
  ...(sources ? { sources } : {}),
66
66
  };
67
+ const output = state === 'completed' ? await this.delegatedOutput(taskId, result, idempotencyKey) : undefined;
67
68
  const updated = await updateTaskState(taskId, state, data, this.creds);
68
69
  runtimeLog.info('TaskService', `Task state: ${taskId} → ${state}`);
70
+ if (output)
71
+ await this.returnDelegatedOutput(taskId, output);
69
72
  // The same four facts the MCP surface reports, from the same
70
73
  // presenter: what was stored, who was woken, what metering did, what the
71
74
  // agreement is now. Both surfaces say it once, and say it the same way.
@@ -79,6 +82,44 @@ export class TaskService {
79
82
  throw error;
80
83
  }
81
84
  }
85
+ /**
86
+ * A delegated task's result only reaches the work that delegated it as a
87
+ * returned output artifact. A workflow agent closes its task with a result
88
+ * and nothing else, so the delegator never woke and never saw it. Before
89
+ * completing, record the result as this task's output; after, return it.
90
+ * Either step failing leaves the completion itself untouched.
91
+ */
92
+ async delegatedOutput(taskId, result, idempotencyKey) {
93
+ try {
94
+ const task = await getTask(taskId, this.creds);
95
+ if (!task?.delegation || task.delegation.returnedArtifactId)
96
+ return undefined;
97
+ const summary = result?.summary;
98
+ const text = typeof summary === 'string' ? summary : safeJsonStringify(result);
99
+ if (!text || !String(text).trim())
100
+ return undefined;
101
+ const recorded = await new ArtifactsClient(this.creds.operatorKey, this.creds.agentId).writeStrict({
102
+ taskId,
103
+ text: String(text),
104
+ name: `Result of task ${taskId}`,
105
+ ...(idempotencyKey ? { idempotencyKey: `${idempotencyKey}:output` } : {}),
106
+ });
107
+ return recorded.artifactId;
108
+ }
109
+ catch (error) {
110
+ runtimeLog.warn('TaskService', `Delegated result for ${taskId} not recorded as an output: ${error.message}`);
111
+ return undefined;
112
+ }
113
+ }
114
+ async returnDelegatedOutput(taskId, artifactId) {
115
+ try {
116
+ const returned = await returnTaskResult(taskId, artifactId, this.creds);
117
+ runtimeLog.info('TaskService', `Delegated result returned: ${taskId} → ${returned.parentTaskId} (${artifactId}, ${returned.outcome})`);
118
+ }
119
+ catch (error) {
120
+ runtimeLog.warn('TaskService', `Delegated result for ${taskId} not returned: ${error.message}`);
121
+ }
122
+ }
82
123
  /**
83
124
  * Say who this task is waiting on, with no other progress to post.
84
125
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ziggs-ai/agent-sdk",
3
- "version": "0.43.5",
3
+ "version": "0.43.6",
4
4
  "description": "Agent framework SDK for building autonomous agents on the Ziggs platform",
5
5
  "homepage": "https://ziggsai.com/docs",
6
6
  "bugs": {