agency-lang 0.7.3 → 0.7.4

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.
@@ -279,13 +279,23 @@ def summarize(messages: ThreadMessage[]): string {
279
279
 
280
280
  @param messages - The thread's messages to summarize
281
281
  """
282
+ // System/developer messages are instructions, not conversation --
283
+ // and an agent's system prompt can run thousands of tokens. Keep
284
+ // them out of the summarizer prompt (mirrors the eager TS path in
285
+ // lib/stdlib/threads.ts). maxTokens caps the summarizer so a model
286
+ // that misses its stop token can't generate unboundedly.
282
287
  let transcript = ""
283
288
  for (m in messages) {
284
- transcript = transcript + "[" + m.role + "] " + m.content + "\n"
289
+ if (m.role != "system" && m.role != "developer") {
290
+ transcript = transcript + "[" + m.role + "] " + m.content + "\n"
291
+ }
292
+ }
293
+ if (transcript == "") {
294
+ return ""
285
295
  }
286
296
  let summary = ""
287
297
  thread(hidden: true) {
288
- const r: SummaryResult = llm("Summarize this conversation in 1-2 sentences:\n" + transcript)
298
+ const r: SummaryResult = llm("Summarize this conversation in 1-2 sentences:\n" + transcript, { maxTokens: 256 })
289
299
  summary = r.summary
290
300
  }
291
301
  return summary
package/stdlib/thread.js CHANGED
@@ -1565,18 +1565,39 @@ async function __summarize_impl(messages) {
1565
1565
  });
1566
1566
  });
1567
1567
  await runner.step(1, async (runner2) => {
1568
+ });
1569
+ await runner.step(2, async (runner2) => {
1568
1570
  __stack.locals.transcript = ``;
1569
1571
  });
1570
- await runner.loop(2, async () => __stack.args.messages, async (m, _, runner2) => {
1571
- await runner2.step(0, async (runner3) => {
1572
- __stack.locals.transcript = __stack.locals.transcript + `[${m.role}] ${m.content}
1572
+ await runner.loop(3, async () => __stack.args.messages, async (m, _, runner2) => {
1573
+ await runner2.ifElse(0, [
1574
+ {
1575
+ condition: async () => !__eq(m.role, `system`) && !__eq(m.role, `developer`),
1576
+ body: async (runner3) => {
1577
+ await runner3.step(0, async (runner4) => {
1578
+ __stack.locals.transcript = __stack.locals.transcript + `[${m.role}] ${m.content}
1573
1579
  `;
1574
- });
1580
+ });
1581
+ }
1582
+ }
1583
+ ]);
1575
1584
  });
1576
- await runner.step(3, async (runner2) => {
1585
+ await runner.ifElse(4, [
1586
+ {
1587
+ condition: async () => __eq(__stack.locals.transcript, ``),
1588
+ body: async (runner2) => {
1589
+ await runner2.step(0, async (runner3) => {
1590
+ __functionCompleted = true;
1591
+ runner3.halt(``);
1592
+ return;
1593
+ });
1594
+ }
1595
+ }
1596
+ ]);
1597
+ await runner.step(5, async (runner2) => {
1577
1598
  __stack.locals.summary = ``;
1578
1599
  });
1579
- await runner.thread(4, "create", async () => ({ hidden: true }), async (runner2) => {
1600
+ await runner.thread(6, "create", async () => ({ hidden: true }), async (runner2) => {
1580
1601
  await runner2.step(0, async (runner3) => {
1581
1602
  __self.__removedTools = __self.__removedTools || [];
1582
1603
  __stack.locals.r = await runPrompt({
@@ -1586,7 +1607,9 @@ ${__stack.locals.transcript}`,
1586
1607
  responseFormat: z.object({
1587
1608
  response: SummaryResult
1588
1609
  }),
1589
- clientConfig: {},
1610
+ clientConfig: {
1611
+ "maxTokens": 256
1612
+ },
1590
1613
  maxToolCallRounds: 10,
1591
1614
  removedTools: __self.__removedTools,
1592
1615
  checkpointInfo: runner3.getCheckpointInfo()
@@ -1601,7 +1624,7 @@ ${__stack.locals.transcript}`,
1601
1624
  __stack.locals.summary = __stack.locals.r.summary;
1602
1625
  });
1603
1626
  });
1604
- await runner.step(5, async (runner2) => {
1627
+ await runner.step(7, async (runner2) => {
1605
1628
  __functionCompleted = true;
1606
1629
  runner2.halt(__stack.locals.summary);
1607
1630
  return;
@@ -2353,7 +2376,7 @@ const getThread = __AgencyFunction.create({
2353
2376
  exported: true
2354
2377
  }, __toolRegistry);
2355
2378
  var stdin_default = graph;
2356
- const __sourceMap = { "stdlib/thread.agency:systemMessage": { "1": { "line": 70, "col": 2 } }, "stdlib/thread.agency:userMessage": { "1": { "line": 81, "col": 2 } }, "stdlib/thread.agency:image": { "1": { "line": 97, "col": 2 } }, "stdlib/thread.agency:file": { "1": { "line": 114, "col": 2 } }, "stdlib/thread.agency:attachToReply": { "1": { "line": 127, "col": 2 } }, "stdlib/thread.agency:assistantMessage": { "1": { "line": 138, "col": 2 } }, "stdlib/thread.agency:getCost": { "1": { "line": 151, "col": 2 } }, "stdlib/thread.agency:getTokens": { "1": { "line": 158, "col": 2 } }, "stdlib/thread.agency:getModelCosts": { "1": { "line": 177, "col": 2 } }, "stdlib/thread.agency:guard": { "1": { "line": 246, "col": 2 }, "2": { "line": 247, "col": 2 }, "3": { "line": 248, "col": 2 }, "4": { "line": 249, "col": 2 } }, "stdlib/thread.agency:summarize": { "1": { "line": 281, "col": 2 }, "2": { "line": 282, "col": 2 }, "3": { "line": 285, "col": 2 }, "4": { "line": 286, "col": 2 }, "5": { "line": 290, "col": 2 }, "2.0": { "line": 283, "col": 4 }, "4.0": { "line": 287, "col": 4 }, "4.1": { "line": 288, "col": 4 } }, "stdlib/thread.agency:summaryFor": { "1": { "line": 300, "col": 2 }, "2": { "line": 303, "col": 2 }, "3": { "line": 304, "col": 2 }, "4": { "line": 305, "col": 2 }, "1.0": { "line": 301, "col": 4 } }, "stdlib/thread.agency:listThreads": { "1": { "line": 326, "col": 2 }, "2": { "line": 327, "col": 2 }, "3": { "line": 330, "col": 2 }, "4": { "line": 331, "col": 2 }, "5": { "line": 364, "col": 2 }, "2.0": { "line": 328, "col": 4 }, "4.0": { "line": 332, "col": 4 }, "4.1.1.0": { "line": 338, "col": 8 }, "4.1.1.1": { "line": 340, "col": 8 }, "4.1.1": { "line": 337, "col": 6 }, "4.1.3.0": { "line": 347, "col": 8 }, "4.1.3.1": { "line": 349, "col": 8 }, "4.1.3.2": { "line": 351, "col": 8 }, "4.1.3": { "line": 346, "col": 6 }, "4.1": { "line": 333, "col": 4 }, "4.2": { "line": 354, "col": 4 } }, "stdlib/thread.agency:currentThreadId": { "1": { "line": 374, "col": 2 } }, "stdlib/thread.agency:getThread": { "1": { "line": 393, "col": 2 } } };
2379
+ const __sourceMap = { "stdlib/thread.agency:systemMessage": { "1": { "line": 70, "col": 2 } }, "stdlib/thread.agency:userMessage": { "1": { "line": 81, "col": 2 } }, "stdlib/thread.agency:image": { "1": { "line": 97, "col": 2 } }, "stdlib/thread.agency:file": { "1": { "line": 114, "col": 2 } }, "stdlib/thread.agency:attachToReply": { "1": { "line": 127, "col": 2 } }, "stdlib/thread.agency:assistantMessage": { "1": { "line": 138, "col": 2 } }, "stdlib/thread.agency:getCost": { "1": { "line": 151, "col": 2 } }, "stdlib/thread.agency:getTokens": { "1": { "line": 158, "col": 2 } }, "stdlib/thread.agency:getModelCosts": { "1": { "line": 177, "col": 2 } }, "stdlib/thread.agency:guard": { "1": { "line": 246, "col": 2 }, "2": { "line": 247, "col": 2 }, "3": { "line": 248, "col": 2 }, "4": { "line": 249, "col": 2 } }, "stdlib/thread.agency:summarize": { "2": { "line": 286, "col": 2 }, "3": { "line": 287, "col": 2 }, "4": { "line": 292, "col": 2 }, "5": { "line": 295, "col": 2 }, "6": { "line": 296, "col": 2 }, "7": { "line": 300, "col": 2 }, "3.0.0": { "line": 289, "col": 6 }, "3.0": { "line": 288, "col": 4 }, "4.0": { "line": 293, "col": 4 }, "6.0": { "line": 297, "col": 4 }, "6.1": { "line": 298, "col": 4 } }, "stdlib/thread.agency:summaryFor": { "1": { "line": 310, "col": 2 }, "2": { "line": 313, "col": 2 }, "3": { "line": 314, "col": 2 }, "4": { "line": 315, "col": 2 }, "1.0": { "line": 311, "col": 4 } }, "stdlib/thread.agency:listThreads": { "1": { "line": 336, "col": 2 }, "2": { "line": 337, "col": 2 }, "3": { "line": 340, "col": 2 }, "4": { "line": 341, "col": 2 }, "5": { "line": 374, "col": 2 }, "2.0": { "line": 338, "col": 4 }, "4.0": { "line": 342, "col": 4 }, "4.1.1.0": { "line": 348, "col": 8 }, "4.1.1.1": { "line": 350, "col": 8 }, "4.1.1": { "line": 347, "col": 6 }, "4.1.3.0": { "line": 357, "col": 8 }, "4.1.3.1": { "line": 359, "col": 8 }, "4.1.3.2": { "line": 361, "col": 8 }, "4.1.3": { "line": 356, "col": 6 }, "4.1": { "line": 343, "col": 4 }, "4.2": { "line": 364, "col": 4 } }, "stdlib/thread.agency:currentThreadId": { "1": { "line": 384, "col": 2 } }, "stdlib/thread.agency:getThread": { "1": { "line": 403, "col": 2 } } };
2357
2380
  export {
2358
2381
  Attachment,
2359
2382
  AttachmentSource,