@vietor/agent-core 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.
@@ -2,7 +2,7 @@ import { createLLM } from "./llm/client.js";
2
2
  import { Session } from "./runtime/session.js";
3
3
  import { ToolRegistry } from "./tools/registry.js";
4
4
  import { MCPServerManager } from "./mcp/manager.js";
5
- import { TOOL_USE_PROMPT } from "./runtime/prompts.js";
5
+ import { renderToolUsePrompt } from "./runtime/prompts.js";
6
6
  import { DEFAULT_MAX_TURNS } from "./util/constants.js";
7
7
  import { TODO_WRITE_GUIDANCE } from "./tools/todo-write.js";
8
8
  import { ASK_USER_GUIDANCE } from "./tools/ask-user.js";
@@ -13,7 +13,7 @@ function contextLimitFor(maxInputTokens) {
13
13
  }
14
14
  function buildSystemPrompt(base, skills, builtInTools, maxTurns) {
15
15
  const parts = [base];
16
- const toolUseLines = [TOOL_USE_PROMPT, `- Turn budget: ${maxTurns} tool-calling turns per run.`];
16
+ const toolUseLines = [renderToolUsePrompt(maxTurns)];
17
17
  if (typeof builtInTools === "object") {
18
18
  if (builtInTools.todoWrite)
19
19
  toolUseLines.push(TODO_WRITE_GUIDANCE);
@@ -1,5 +1,6 @@
1
1
  import type { Todo } from "../tools/types.js";
2
2
  export declare const TOOL_USE_PROMPT: string;
3
+ export declare function renderToolUsePrompt(maxTurns: number): string;
3
4
  export declare const COMPACT_PROMPT: string;
4
5
  export declare function renderTodoReminder(todos: readonly Todo[]): string;
5
6
  export declare function renderIncompleteTodoNudge(todos: readonly Todo[]): string;
@@ -8,6 +8,9 @@ export const TOOL_USE_PROMPT = [
8
8
  "- For file operations (read/write/edit/glob/grep) and fetching URLs, use the dedicated tool. Fall back to Shell only when no dedicated tool covers the task and Shell is available. A runtime error does not make Shell the fallback; do not retry that same operation through Shell.",
9
9
  "- If a tool call fails, read the error, adjust the arguments or approach, and continue; do not repeat the identical call and do not abandon the task over a single failure.",
10
10
  ].join("\n");
11
+ export function renderToolUsePrompt(maxTurns) {
12
+ return [TOOL_USE_PROMPT, `- Turn budget: ${maxTurns} tool-calling turns per run.`].join("\n");
13
+ }
11
14
  export const COMPACT_PROMPT = [
12
15
  "Summarize the conversation above for context continuation. Preserve:\n",
13
16
  "1. Primary goal, sub-goals, constraints, acceptance criteria.\n",
@@ -34,7 +37,7 @@ export function renderTodoReminder(todos) {
34
37
  const focusLine = focus ? ` Current focus: ${focus.content}` : "";
35
38
  const incomplete = todos.filter(t => t.status !== "completed");
36
39
  const warning = incomplete.length > 0
37
- ? ` ${incomplete.length} incomplete. You MUST complete EVERY task before your final text-only response update status via TodoWrite after each task finishes.`
40
+ ? ` ${incomplete.length} incomplete. You MUST complete EVERY task before your final text-only response. Mark them complete via TodoWrite as they finish; the final update may go in the same turn as your last tool call.`
38
41
  : "";
39
42
  return `<system-reminder>Tasks: ${items.join(" | ")}${focusLine}${warning}</system-reminder>`;
40
43
  }
@@ -30,6 +30,7 @@ export declare class SessionMessages {
30
30
  add(msg: SessionMessage): void;
31
31
  toLLM(): LLMMessage[];
32
32
  export(): SessionMessage[];
33
+ lastAssistantText(): string;
33
34
  import(messages: SessionMessage[]): void;
34
35
  normalizeInterruptedToolCalls(): void;
35
36
  clear(): void;
@@ -86,6 +86,9 @@ export class SessionMessages {
86
86
  export() {
87
87
  return this.messages.slice();
88
88
  }
89
+ lastAssistantText() {
90
+ return lastAssistantText(this.messages);
91
+ }
89
92
  import(messages) {
90
93
  this.resetMessages(messages.slice(), messages.reduce((sum, m) => sum + estimateTokens(messageText(m)), 0));
91
94
  this.normalizeInterruptedToolCalls();
@@ -1,10 +1,10 @@
1
- import { SessionMessages, lastAssistantText } from "./session-messages.js";
1
+ import { SessionMessages } from "./session-messages.js";
2
2
  import { Agent } from "./agent.js";
3
- import { TOOL_USE_PROMPT } from "./prompts.js";
3
+ import { renderToolUsePrompt } from "./prompts.js";
4
4
  import { ToolRegistry } from "../tools/registry.js";
5
5
  export function createSubAgentRunner(opts) {
6
6
  return async (systemPrompt, task, signal) => {
7
- const conversation = new SessionMessages([systemPrompt, TOOL_USE_PROMPT, `- Turn budget: ${opts.maxTurns} tool-calling turns per run.`].join("\n\n"));
7
+ const conversation = new SessionMessages([systemPrompt, renderToolUsePrompt(opts.maxTurns)].join("\n\n"));
8
8
  const subTools = new ToolRegistry();
9
9
  subTools.registerAll(opts.tools.filter((t) => t.readOnly === true));
10
10
  const subAgent = new Agent({
@@ -19,8 +19,8 @@ export function createSubAgentRunner(opts) {
19
19
  contextLimit: opts.contextLimit,
20
20
  });
21
21
  const status = await subAgent.run(task, undefined, signal);
22
- const messages = conversation.export();
23
- const reply = lastAssistantText(messages) || `(sub-agent produced no final text; status ${status})`;
22
+ const reply = conversation.lastAssistantText() || `(sub-agent produced no final text; status ${status})`;
23
+ const messages = status !== "ok" ? conversation.export() : [];
24
24
  return { status, reply, messages };
25
25
  };
26
26
  }
@@ -69,11 +69,16 @@ export function createSubAgentTool(deps) {
69
69
  const { status, reply, messages } = await deps.runSubAgent(def.systemPrompt, task, ctx.signal);
70
70
  if (status === "ok")
71
71
  return { content: reply };
72
- const stallReason = status === "stalled"
73
- ? [...messages].reverse()
74
- .map((m) => m.content)
75
- .find((c) => typeof c === "string" && c.startsWith(NOT_EXECUTED_PREFIX))
76
- : undefined;
72
+ let stallReason;
73
+ if (status === "stalled") {
74
+ for (let i = messages.length - 1; i >= 0; i--) {
75
+ const content = messages[i].content;
76
+ if (typeof content === "string" && content.startsWith(NOT_EXECUTED_PREFIX)) {
77
+ stallReason = content;
78
+ break;
79
+ }
80
+ }
81
+ }
77
82
  const suffix = stallReason ? ` ${stallReason}` : "";
78
83
  return { content: `Sub-agent "${type}" ended with status ${status}.${suffix}\n\n${reply}`, isError: true };
79
84
  },
@@ -1,3 +1,3 @@
1
1
  import type { Tool, Todo } from "./types.js";
2
- export declare const TODO_WRITE_GUIDANCE = "- For multi-step tasks (3+ steps), you MUST use TodoWrite: create the task list first, then update each task's status as you execute. Never execute a multi-step task without a TodoWrite task list.";
2
+ export declare const TODO_WRITE_GUIDANCE = "- For multi-step tasks (5+ steps), you MUST use TodoWrite: create the task list first, then update statuses as tasks complete. Never execute a 5+ step task without a TodoWrite task list.";
3
3
  export declare function createTodoWriteTool(setTodos: (todos: Todo[]) => void): Tool;
@@ -1,7 +1,7 @@
1
1
  import { toolError } from "./types.js";
2
- export const TODO_WRITE_GUIDANCE = "- For multi-step tasks (3+ steps), you MUST use TodoWrite: create the task list first, then update each task's status as you execute. Never execute a multi-step task without a TodoWrite task list.";
2
+ export const TODO_WRITE_GUIDANCE = "- For multi-step tasks (5+ steps), you MUST use TodoWrite: create the task list first, then update statuses as tasks complete. Never execute a 5+ step task without a TodoWrite task list.";
3
3
  const STATUSES = ["pending", "inProgress", "completed"];
4
- const DESCRIPTION = "Manage the task list for tasks with 3+ steps. Pass the FULL list each call; it replaces the previous list. Keep one inProgress at a time. status: pending, inProgress, completed.";
4
+ const DESCRIPTION = "Manage the task list for tasks with 5+ steps. Pass the FULL list each call; it replaces the previous list. Keep one inProgress at a time. status: pending, inProgress, completed.";
5
5
  function parseTodos(args) {
6
6
  const raw = args.todos;
7
7
  if (!Array.isArray(raw)) {
@@ -32,6 +32,13 @@ function parseTodos(args) {
32
32
  }
33
33
  todos.push({ content, status });
34
34
  }
35
+ if (!seenInProgress) {
36
+ const firstPending = todos.find((t) => t.status === "pending");
37
+ if (firstPending) {
38
+ firstPending.status = "inProgress";
39
+ normalized++;
40
+ }
41
+ }
35
42
  return { todos, done, normalized };
36
43
  }
37
44
  export function createTodoWriteTool(setTodos) {
package/dist/util/net.js CHANGED
@@ -1,4 +1,4 @@
1
- import { ProxyAgent } from "undici";
1
+ import { fetch, ProxyAgent } from "undici";
2
2
  let proxyAgent;
3
3
  let noProxyList;
4
4
  let proxyInitialized = false;
@@ -11,11 +11,12 @@ function ensureProxy() {
11
11
  proxyAgent = proxyUrl ? new ProxyAgent(proxyUrl) : null;
12
12
  noProxyList = noProxy?.split(",").map((s) => s.trim()).filter(Boolean);
13
13
  }
14
+ const undiciFetch = fetch;
14
15
  export async function netFetch(input, init) {
15
16
  if (!proxyInitialized)
16
17
  ensureProxy();
17
18
  if (!proxyAgent)
18
- return fetch(input, init);
19
+ return undiciFetch(input, init);
19
20
  const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
20
21
  if (noProxyList) {
21
22
  const hostname = new URL(url).hostname;
@@ -25,7 +26,7 @@ export async function netFetch(input, init) {
25
26
  return hostname === p || hostname.endsWith("." + p);
26
27
  });
27
28
  if (shouldBypass)
28
- return fetch(input, init);
29
+ return undiciFetch(input, init);
29
30
  }
30
- return fetch(input, { ...init, dispatcher: proxyAgent });
31
+ return undiciFetch(input, { ...init, dispatcher: proxyAgent });
31
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vietor/agent-core",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",