-
Notifications
You must be signed in to change notification settings - Fork 321
Open
Labels
Description
Currently the asTool() helper on Agent only supports toolName, toolDescription, and customOutputExtractor.
However, the underlying runner.run() already supports a maxTurn parameter, which controls the maximum number of turns for the run.
We need to allow users of asTool() to configure this value directly.
Current code (simplified)
asTool(options: {
toolName?: string;
toolDescription?: string;
customOutputExtractor?: (
output: RunResult<TContext, Agent<TContext, any>>,
) => string | Promise<string>;
}): FunctionTool {
const { toolName, toolDescription, customOutputExtractor } = options;
return tool({
name: toolName ?? toFunctionToolName(this.name),
description: toolDescription ?? '',
...
execute: async (data, context) => {
const runner = new Runner();
const result = await runner.run(this, data.input, {
context: context?.context,
});
...
},
});
}
Requested change
Add a new maxTurn?: number option to the asTool() options.
Pass it through to runner.run().
Proposed signature:
asTool(options: {
toolName?: string;
toolDescription?: string;
maxTurn?: number;
customOutputExtractor?: (
output: RunResult<TContext, Agent<TContext, any>>,
) => string | Promise<string>;
}): FunctionTool
Update the runner.run call:
const result = await runner.run(this, data.input, {
context: context?.context,
maxTurn,
});
This ensures that agents wrapped as tools can fully leverage the maxTurn functionality already available in runner.run(), enabling better control over multi-turn execution directly from the tool API.
What do you think? (I can open PR)