Fields
idstringGenerated for this question.
questionstringWhat it is asking.
optionsarraySuggested answers, when it offered any.
It needs onQuestion
const agent = api.agents.create({
runtime: "local", machine: pc, model,
onQuestion: async ({ question, options }) => {
console.log(question, options);
return await readAnswerFromTheUser(); // a string
},
onEvent: (e) => {
if (e.type === "question") showQuestion(e.id, e.question, e.options);
if (e.type === "question_result") closeQuestion(e.id, e.answer);
},
});def on_question(request):
print(request["question"], request["options"])
return read_answer_from_the_user() # a string
agent = api.agents.create(runtime="local", machine=pc, model=model, on_question=on_question)The tool is only wired when the callback is there. An agent without it has no way to ask, and is instructed to make a judgement call or explain what is blocking instead — which is a different run, not a stuck one.
question_result
{ type: "question_result", id, answer } // "" when nothing was returned# The ask_user tool returns what on_question answered, or None when no callback is set
{"answer": "the second option"}An empty answer is passed to the agent as an empty answer; it is not an error, and the loop continues.
When it asks
- The request is ambiguous and the choice is the user's.
- Two attempts at the same approach have failed — it is told to ask rather than try a third.
A subagent never asks
ask_user is one of the three tools a subagent does not get. It is told it cannot talk to the user and must report back instead — so a question always comes from the main run, and never carries parentId.