@ziggs-ai/agent-sdk 0.48.14 → 0.48.15
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
|
@@ -219,6 +219,33 @@ function proposalOutcomeLine(reason, agreementId) {
|
|
|
219
219
|
'This wake does not carry the conversation that led to it; read that request (message_list) if you need it. ' +
|
|
220
220
|
'Do not greet the provider or open a new conversation.';
|
|
221
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* What the tasks this task handed out have done. A delegated task's result
|
|
224
|
+
* reaches the delegator only as a returned output artifact, and the wake that
|
|
225
|
+
* carries it is a reason to act, so each returned result is said in words with
|
|
226
|
+
* how to read it. Without this the delegator sees only its own task and
|
|
227
|
+
* concludes nothing has come back.
|
|
228
|
+
*/
|
|
229
|
+
function renderDelegationLines(inputs, delegations, lines) {
|
|
230
|
+
const returnedNow = new Set((Array.isArray(inputs) ? inputs : [])
|
|
231
|
+
.filter((input) => input?.reason === 'delegation_returned' && typeof input.eventId === 'string')
|
|
232
|
+
.map((input) => String(input.eventId).replace(/^delegation-return:/, '')));
|
|
233
|
+
if (!Array.isArray(delegations) || delegations.length === 0)
|
|
234
|
+
return;
|
|
235
|
+
const rows = delegations;
|
|
236
|
+
for (const row of rows) {
|
|
237
|
+
if (typeof row?.taskId !== 'string')
|
|
238
|
+
continue;
|
|
239
|
+
const artifact = typeof row.returnedArtifactId === 'string' ? row.returnedArtifactId : null;
|
|
240
|
+
if (artifact)
|
|
241
|
+
lines.push(`Work signal: task ${row.taskId}, which you handed out from this task, ${returnedNow.has(row.taskId) ? 'just returned' : 'has returned'} its result as artifact ${artifact}. ` +
|
|
242
|
+
`Read it (context_read type "artifacts", via "artifact:${artifact}") and carry the work on with it.`);
|
|
243
|
+
else if (row.state === 'completed')
|
|
244
|
+
lines.push(`Delegated task ${row.taskId} is completed; its result has not been returned to this task yet.`);
|
|
245
|
+
else if (typeof row.state === 'string')
|
|
246
|
+
lines.push(`Delegated task ${row.taskId} is ${row.state}.`);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
222
249
|
/**
|
|
223
250
|
* What arrived for this task since its last wake. A proposal made inside the
|
|
224
251
|
* task reports its outcome here, on the task, where the work it is for can be
|
|
@@ -374,6 +401,7 @@ function renderEventLines(event, lines, now) {
|
|
|
374
401
|
if (typeof result.taskId === 'string')
|
|
375
402
|
lines.push(`Task: ${result.taskId}`);
|
|
376
403
|
renderTaskInputLines(result.inputs, typeof result.taskId === 'string' ? result.taskId : undefined, lines);
|
|
404
|
+
renderDelegationLines(result.inputs, result.delegations, lines);
|
|
377
405
|
if (typeof result.agreementId === 'string')
|
|
378
406
|
lines.push(`Agreement: ${result.agreementId}`);
|
|
379
407
|
if (typeof result.state === 'string')
|
|
@@ -42,6 +42,15 @@ export declare class TaskService {
|
|
|
42
42
|
* Either step failing leaves the completion itself untouched.
|
|
43
43
|
*/
|
|
44
44
|
private delegatedOutput;
|
|
45
|
+
/** The text of the outputs this agent recorded on the task, each under its name. */
|
|
46
|
+
private outputBodies;
|
|
47
|
+
/**
|
|
48
|
+
* Return the completed task's output to the work that handed it out. The
|
|
49
|
+
* run that completed it can end, or its audience change, before the return
|
|
50
|
+
* lands ("Execution context is no longer current", "The work audience or
|
|
51
|
+
* authority changed"); returning its own finished output does not need that
|
|
52
|
+
* run, so the return is tried once more outside it.
|
|
53
|
+
*/
|
|
45
54
|
private returnDelegatedOutput;
|
|
46
55
|
/**
|
|
47
56
|
* Say who this task is waiting on, with no other progress to post.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createTask, getTask, getActiveTasksForAgent, getSubtasks, updateTaskState, updateTaskPlanStep, updateTaskPlanSteps, cancelTask, reportTask, setTaskSatisfaction, countTasks, acknowledgeTaskControl, presentTaskOutcome, returnTaskResult, ArtifactsClient, } from '@ziggs-ai/api-client';
|
|
1
|
+
import { createTask, getTask, getActiveTasksForAgent, getSubtasks, updateTaskState, updateTaskPlanStep, updateTaskPlanSteps, cancelTask, reportTask, setTaskSatisfaction, countTasks, acknowledgeTaskControl, presentTaskOutcome, returnTaskResult, ArtifactsClient, withWorkExecution, ARTIFACT_INLINE_TEXT_MAX_CHARS, } 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)
|
|
@@ -100,12 +100,20 @@ export class TaskService {
|
|
|
100
100
|
if (!task?.delegation || task.delegation.returnedArtifactId)
|
|
101
101
|
return undefined;
|
|
102
102
|
const summary = result?.summary;
|
|
103
|
-
const
|
|
104
|
-
|
|
103
|
+
const head = typeof summary === 'string' ? summary : safeJsonStringify(result);
|
|
104
|
+
const artifacts = new ArtifactsClient(this.creds.operatorKey, this.creds.agentId);
|
|
105
|
+
// Only one output goes back to the delegator, so it carries the bodies of
|
|
106
|
+
// the other outputs this task made: the pages or drafts themselves, not
|
|
107
|
+
// only the line that names them.
|
|
108
|
+
const bodies = await this.outputBodies(artifacts, taskId);
|
|
109
|
+
const text = [head, ...bodies].filter((part) => !!part && !!String(part).trim()).join('\n\n');
|
|
110
|
+
if (!text.trim())
|
|
105
111
|
return undefined;
|
|
106
|
-
const recorded = await
|
|
112
|
+
const recorded = await artifacts.writeStrict({
|
|
107
113
|
taskId,
|
|
108
|
-
text:
|
|
114
|
+
text: text.length > ARTIFACT_INLINE_TEXT_MAX_CHARS
|
|
115
|
+
? `${text.slice(0, ARTIFACT_INLINE_TEXT_MAX_CHARS - 80)}\n\n[cut: the outputs are longer than one result can carry]`
|
|
116
|
+
: text,
|
|
109
117
|
name: `Result of task ${taskId}`,
|
|
110
118
|
...(idempotencyKey ? { idempotencyKey: `${idempotencyKey}:output` } : {}),
|
|
111
119
|
});
|
|
@@ -116,9 +124,39 @@ export class TaskService {
|
|
|
116
124
|
return undefined;
|
|
117
125
|
}
|
|
118
126
|
}
|
|
127
|
+
/** The text of the outputs this agent recorded on the task, each under its name. */
|
|
128
|
+
async outputBodies(artifacts, taskId) {
|
|
129
|
+
try {
|
|
130
|
+
const listed = await artifacts.list({ taskId });
|
|
131
|
+
return listed.artifacts
|
|
132
|
+
.filter((a) => a.linkRole === 'output' && a.sender?.id === this.creds.agentId && !!a.text?.trim())
|
|
133
|
+
.map((a) => `## ${a.name?.trim() || a.artifactId}\n\n${a.text.trim()}`);
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
runtimeLog.warn('TaskService', `Outputs of ${taskId} not read for its result: ${error.message}`);
|
|
137
|
+
return [];
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Return the completed task's output to the work that handed it out. The
|
|
142
|
+
* run that completed it can end, or its audience change, before the return
|
|
143
|
+
* lands ("Execution context is no longer current", "The work audience or
|
|
144
|
+
* authority changed"); returning its own finished output does not need that
|
|
145
|
+
* run, so the return is tried once more outside it.
|
|
146
|
+
*/
|
|
119
147
|
async returnDelegatedOutput(taskId, artifactId) {
|
|
148
|
+
const attempt = () => returnTaskResult(taskId, artifactId, this.creds);
|
|
149
|
+
const outsideRun = () => withWorkExecution(undefined, () => returnTaskResult(taskId, artifactId, { ...this.creds, executionContextId: undefined }));
|
|
120
150
|
try {
|
|
121
|
-
|
|
151
|
+
let returned;
|
|
152
|
+
try {
|
|
153
|
+
returned = await attempt();
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
if (!/no longer current|stale|authority changed|fresh authorized execution/i.test(error.message))
|
|
157
|
+
throw error;
|
|
158
|
+
returned = await outsideRun();
|
|
159
|
+
}
|
|
122
160
|
runtimeLog.info('TaskService', `Delegated result returned: ${taskId} → ${returned.parentTaskId} (${artifactId}, ${returned.outcome})`);
|
|
123
161
|
}
|
|
124
162
|
catch (error) {
|
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.15",
|
|
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.50.
|
|
33
|
+
"@ziggs-ai/api-client": "0.42.13",
|
|
34
|
+
"@ziggs-ai/contracts": "0.50.12",
|
|
35
35
|
"ajv": "^8.17.1",
|
|
36
36
|
"dotenv": "^17.2.3",
|
|
37
37
|
"openai": "^4.0.0",
|