Eventos

pregunta

{ type: "question", id, question, options }

El agente te está pidiendo algo y se ha detenido a esperar. La misma forma que un permiso, diferente significado: aquí quiere una respuesta, no una aprobación.

needs onQuestionthe loop waitsquestion_result follows
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

Campos

idstring

Generado para esta pregunta.

questionstring

Lo que está pidiendo.

optionsarray

Se sugiere que responda, cuando se ofreció alguna.

Necesita una pregunta

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)
Sin la pregunta no hay ask_user

La herramienta sólo está conectada cuando la devolución de llamada está allí. Un agente sin ella no tiene forma de preguntar, y se le instruye que haga una llamada de juicio o explique lo que está bloqueando en su lugar — que es una ejecución diferente, no una atascada.

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"}

Una respuesta vacía se pasa al agente como respuesta vacía; no es un error, y el bucle continúa.

Cuando pregunta

  • La solicitud es ambigua y la elección es del usuario.
  • Dos intentos de un mismo enfoque han fracasado, se dice que pidan en lugar de intentar un tercero.

Un subagente nunca pregunta

ask_user es una de las tres herramientas que un subagente no consigue. Se le dice que no puede hablar con el usuario y debe informar de nuevo en su lugar — por lo que una pregunta siempre viene de la ejecución principal, y nunca lleva parentId.