読み方のヒント

矢印ボタン(または ← → キー)でページを移動できます。

第3節 段階ごとに道具を絞る

3.2 決まった順番でつなぐ

handle は、次の順番で質問を処理します。

def handle(llm, session, toolbox, question, now, trace) -> Outcome:
    if needs_staff(question):
        return Outcome("handoff", None, HANDOFF)

    with trace.step("classify") as detail:
        kind = detail["kind"] = classify(llm, question)

    if kind == "other":
        return Outcome("other", kind, OTHER)

    if kind == "shop_info":
        with trace.step("docs") as detail:
            status, answer, hits = answer_from_docs(session, llm, question)
            ...
        return Outcome(status, kind, answer, sources=...)

    with trace.step(f"agent:{kind}") as detail:
        result = run_agent(llm, LimitedToolbox(toolbox, ROUTE_TOOLS[kind]), question, now)
        ...
段階LLMを呼ぶ回数使える道具
店員につなぐか(決まり)0なし
種類を決める1なし
other0なし(決まった文)
shop_info1(資料が見つかったとき)なし(/ask と同じ検索と答え)
product2〜5find_products
reservation2〜5find_products、draft_reservation

shop_info の段階は、エージェントではなく、/ask と同じ「探して、渡して、答えさせる」処理です。検索の言葉をLLMに決めさせないため、第1節の「車で行っても大丈夫ですか」で検索の言葉を誤った問題が起きません。質問の文そのもので探します。

12 / 22