01-agents/5_escalation.py [75:112]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            tools=tool_schemas or None,
        )
        message = response.choices[0].message
        messages.append(message)

        # アシスタントの応答を表示
        if message.content:
            print(color("Assistant:", "yellow"), message.content)

        # ツール呼び出しがない場合はループを終了
        if not message.tool_calls:
            break

        # === 2. ツール呼び出しを処理 ===

        for tool_call in message.tool_calls:
            result = execute_tool_call(tool_call, tools_map)

            result_message = {
                "role": "tool",
                "tool_call_id": tool_call.id,
                "content": result,
            }
            messages.append(result_message)

    # ==== 3. 新しいメッセージを返す =====
    return messages[num_init_messages:]

# ツール呼び出しを実行する関数
def execute_tool_call(tool_call, tools_map):
    """指定されたツール呼び出しを実行します。"""
    name = tool_call.function.name
    args = json.loads(tool_call.function.arguments)

    print(color("Assistant:", "yellow"), color(f"{name}({args})", "magenta"))

    # 指定された引数で対応する関数を呼び出す
    return tools_map[name](**args)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



01-agents/7_orchestration.py [51:95]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            tools=tool_schemas or None,
        )
        message = response.choices[0].message
        messages.append(message)

        # アシスタントの応答を表示
        if message.content:
            print(color("Assistant:", "yellow"), message.content)

        # ツール呼び出しがない場合はループを終了
        if not message.tool_calls:
            break

        # === 2. ツール呼び出しを処理 ===

        for tool_call in message.tool_calls:
            result = execute_tool_call(tool_call, tools_map)

            result_message = {
                "role": "tool",
                "tool_call_id": tool_call.id,
                "content": result,
            }
            messages.append(result_message)

    # ==== 3. 新しいメッセージを返す =====
    return messages[num_init_messages:]

# ツール呼び出しを実行する関数
def execute_tool_call(tool_call, tools_map):
    """指定されたツール呼び出しを実行します。

    Args:
        tool_call (dict): 呼び出すツールの詳細。
        tools_map (dict): ツール名と関数のマッピング。

    Returns:
        any: ツールの実行結果。"""
    name = tool_call.function.name
    args = json.loads(tool_call.function.arguments)

    print(color("Assistant:", "yellow"), color(f"{name}({args})", "magenta"))

    # 指定された引数で対応する関数を呼び出す
    return tools_map[name](**args)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



