mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-04-25 08:26:22 +02:00
support ask-human in sync mode
This commit is contained in:
parent
38a8700fa9
commit
9e89a81c8d
2 changed files with 28 additions and 2 deletions
|
|
@ -48,6 +48,8 @@ function mapAgentTool(t: z.infer<typeof AgentTool>): Tool {
|
|||
switch (t.name) {
|
||||
case "bash":
|
||||
return BashTool;
|
||||
case "ask-human":
|
||||
return AskHumanTool;
|
||||
default:
|
||||
throw new Error(`Unknown builtin tool: ${t.name}`);
|
||||
}
|
||||
|
|
@ -154,7 +156,7 @@ export class AgentNode implements Step {
|
|||
|
||||
const { fullStream } = streamText({
|
||||
model: openai("gpt-4.1"),
|
||||
// model: google("gemini-2.5-pro"),
|
||||
// model: google("gemini-2.5-flash"),
|
||||
messages: convertFromMessages(input),
|
||||
system: this.agent.instructions,
|
||||
stopWhen: stepCountIs(1),
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import { executeCommand } from "./command-executor.js";
|
|||
import { loadWorkflow } from "./utils.js";
|
||||
import { AssistantMessage } from "../entities/message.js";
|
||||
import { executeWorkflow } from "./exec-workflow.js";
|
||||
import readline from "readline";
|
||||
|
||||
async function execMcpTool(agentTool: z.infer<typeof AgentTool> & { type: "mcp" }, input: any): Promise<any> {
|
||||
// load mcp configuration from the tool
|
||||
|
|
@ -65,6 +66,22 @@ async function execBashTool(agentTool: z.infer<typeof AgentTool>, input: any): P
|
|||
};
|
||||
}
|
||||
|
||||
async function execAskHumanTool(agentTool: z.infer<typeof AgentTool>, input: any): Promise<any> {
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
});
|
||||
|
||||
let p = new Promise<string>((resolve, reject) => {
|
||||
rl.question(`>> Provide answer to: ${input.question}:\n\n`, (answer) => {
|
||||
resolve(answer);
|
||||
rl.close();
|
||||
});
|
||||
});
|
||||
const answer = await p;
|
||||
return answer;
|
||||
}
|
||||
|
||||
async function execWorkflowTool(agentTool: z.infer<typeof AgentTool> & { type: "workflow" }, input: any): Promise<any> {
|
||||
let lastMsg: z.infer<typeof AssistantMessage> | null = null;
|
||||
for await (const event of executeWorkflow(agentTool.name, input.message)) {
|
||||
|
|
@ -97,6 +114,13 @@ export async function execTool(agentTool: z.infer<typeof AgentTool>, input: any)
|
|||
case "workflow":
|
||||
return execWorkflowTool(agentTool, input);
|
||||
case "builtin":
|
||||
return execBashTool(agentTool, input);
|
||||
switch (agentTool.name) {
|
||||
case "bash":
|
||||
return execBashTool(agentTool, input);
|
||||
case "ask-human":
|
||||
return execAskHumanTool(agentTool, input);
|
||||
default:
|
||||
throw new Error(`Unknown builtin tool: ${agentTool.name}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue