Skip to content

An AI-powered search engine with a generative UI

feat: force todoWrite tool on first step in planning mode

Yoshiki Miura49f2d14b0efe
diff --git a/lib/agents/researcher.ts b/lib/agents/researcher.ts
index c7ff8314..784ecfdd 100644
--- a/lib/agents/researcher.ts
+++ b/lib/agents/researcher.ts
@@ -130,6 +130,10 @@ export function researcher({
...todoTools
}
+ // Check if we should force todoWrite on first step
+ const shouldForceTodoWrite =
+ searchMode === 'planning' && writer && 'todoWrite' in todoTools
+
// Return an agent instance
return new Agent({
model: getModel(model),
@@ -141,6 +145,17 @@ export function researcher({
...(modelConfig?.providerOptions && {
providerOptions: modelConfig.providerOptions
}),
+ // Force todoWrite tool on first step for planning mode
+ ...(shouldForceTodoWrite && {
+ prepareStep: async ({ stepNumber }) => {
+ if (stepNumber === 0) {
+ return {
+ toolChoice: { type: 'tool', toolName: 'todoWrite' }
+ }
+ }
+ return undefined
+ }
+ }),
experimental_telemetry: {
isEnabled: isTracingEnabled(),
functionId: 'research-agent',