skip ask-human when running workflow as tool

This commit is contained in:
Ramnique Singh 2025-11-11 12:38:27 +05:30
parent 54bdbe73c0
commit 88fc585cc2
2 changed files with 12 additions and 6 deletions

View file

@ -122,12 +122,12 @@ function convertFromMessages(messages: z.infer<typeof Message>[]): ModelMessage[
export class AgentNode implements Step {
private id: string;
private background: boolean;
private asTool: boolean;
private agent: z.infer<typeof Agent>;
constructor(id: string, background: boolean) {
constructor(id: string, asTool: boolean) {
this.id = id;
this.background = background;
this.asTool = asTool;
const agentPath = path.join(WorkDir, "agents", `${id}.json`);
const agent = fs.readFileSync(agentPath, "utf8");
this.agent = Agent.parse(JSON.parse(agent));
@ -144,6 +144,9 @@ export class AgentNode implements Step {
// tools["ask-human"] = AskHumanTool;
// }
for (const [name, tool] of Object.entries(this.agent.tools ?? {})) {
if (this.asTool && name === "ask-human") {
continue;
}
try {
tools[name] = mapAgentTool(tool);
} catch (error) {

View file

@ -161,7 +161,7 @@ function loadFunction(id: string) {
return func;
}
export async function* executeWorkflow(id: string, input: string, interactive: boolean = true): AsyncGenerator<z.infer<typeof RunEvent>, void, unknown> {
export async function* executeWorkflow(id: string, input: string, interactive: boolean = true, asTool: boolean = false): AsyncGenerator<z.infer<typeof RunEvent>, void, unknown> {
const runId = runIdGenerator.next();
yield* runFromState({
id,
@ -176,6 +176,7 @@ export async function* executeWorkflow(id: string, input: string, interactive: b
pendingToolCallId: null,
},
interactive,
asTool,
});
}
@ -256,6 +257,7 @@ export async function* resumeWorkflow(runId: string, input: string, interactive:
pendingToolCallId,
},
interactive,
asTool: false,
});
}
@ -264,8 +266,9 @@ async function* runFromState(opts: {
runId: string;
state: z.infer<typeof State>;
interactive: boolean;
asTool: boolean;
}) {
const { id, runId, state, interactive } = opts;
const { id, runId, state, interactive, asTool } = opts;
let stepIndex = state.stepIndex;
let messages = [...state.messages];
let workflow = state.workflow;
@ -288,7 +291,7 @@ async function* runFromState(opts: {
while (true) {
const step = workflow.steps[stepIndex];
const node = step.type === "agent" ? new AgentNode(step.id, interactive) : loadFunction(step.id);
const node = step.type === "agent" ? new AgentNode(step.id, asTool) : loadFunction(step.id);
yield* ly.logAndYield({
type: "step-start",