src / agents / tools / plan.ts
import { tool, type Tool } from "@lmstudio/sdk";
import { z } from "zod";
import { okResult } from "../../core/result";
import type { AgentPlanItem } from "../runStore";
import type { AgentToolContext } from "./context";
/** `set_plan` — the run's durable plan. */
export function createSetPlanTool(ctx: AgentToolContext): Tool {
const { state, beforeTool } = ctx;
return tool({
name: "set_plan",
description:
"Replace the durable execution plan. Keep items concrete and update statuses as work proceeds.",
parameters: {
items: z.array(
z.object({
text: z.string(),
status: z.enum(["pending", "in_progress", "completed", "blocked"]).optional(),
}),
),
},
implementation: async (input: {
items: Array<{ text: string; status?: AgentPlanItem["status"] }>;
}) => {
await beforeTool("set_plan");
state.plan = input.items.slice(0, 30).map((item, index) => ({
id: `step_${index + 1}`,
text: item.text.slice(0, 500),
status: item.status ?? "pending",
}));
await ctx.store.event(state, {
type: "plan",
summary: `Plan updated with ${state.plan.length} item(s).`,
});
return okResult({
operation: "agent.plan",
summary: `Stored ${state.plan.length} plan item(s).`,
data: { plan: state.plan },
facts: state.plan.map((item) => `${item.status}: ${item.text}`),
});
},
});
}
src / agents / tools / plan.ts
import { tool, type Tool } from "@lmstudio/sdk";
import { z } from "zod";
import { okResult } from "../../core/result";
import type { AgentPlanItem } from "../runStore";
import type { AgentToolContext } from "./context";
/** `set_plan` — the run's durable plan. */
export function createSetPlanTool(ctx: AgentToolContext): Tool {
const { state, beforeTool } = ctx;
return tool({
name: "set_plan",
description:
"Replace the durable execution plan. Keep items concrete and update statuses as work proceeds.",
parameters: {
items: z.array(
z.object({
text: z.string(),
status: z.enum(["pending", "in_progress", "completed", "blocked"]).optional(),
}),
),
},
implementation: async (input: {
items: Array<{ text: string; status?: AgentPlanItem["status"] }>;
}) => {
await beforeTool("set_plan");
state.plan = input.items.slice(0, 30).map((item, index) => ({
id: `step_${index + 1}`,
text: item.text.slice(0, 500),
status: item.status ?? "pending",
}));
await ctx.store.event(state, {
type: "plan",
summary: `Plan updated with ${state.plan.length} item(s).`,
});
return okResult({
operation: "agent.plan",
summary: `Stored ${state.plan.length} plan item(s).`,
data: { plan: state.plan },
facts: state.plan.map((item) => `${item.status}: ${item.text}`),
});
},
});
}