Login Sign Up

Building Conversational Autonomous Multi-Agents

Conversational multi-agent systems allow AI assistants to collaborate, providing feedback, reasoning, and emergent behaviors. The GPT Assistants Playground supports both siloed (separate) and conversational (interactive) assistants, enabling structured and dynamic workflows.

Conversational Autonomous Multi-Agents
Conversational Autonomous Multi-Agents

Creating a Multi-Agent Conversational Thread

The following example demonstrates how two AI assistants collaborate over a shared thread to debug and verify Python code.

Example Code: agentic_conversation_btree.py

import py_trees

import textwrap

import time

from playground.api import create_thread, create_assistant_action_on_thread, create_assistant_condition_on_thread

root = py_trees.composites.Sequence("RootSequence", memory=True)

bug_file = """

# code not shown

"""
thread = create_thread()  #1

debug_code = create_assistant_action_on_thread(  #2

    thread=thread,

    action_name="Debug code",

    assistant_name="Python Debugger",

    assistant_instructions=textwrap.dedent(f"""

    Here is the code with bugs in it:

    {bug_file}

    Run the code to identify the bugs and fix them.

    Be sure to test the code to ensure it runs without errors or throws any exceptions.

    """),

)

root.add_child(debug_code)
verify = create_assistant_condition_on_thread(  #3

    thread=thread,

    condition_name="Verify",

    assistant_name="Python Coding Assistant",

    assistant_instructions=textwrap.dedent(

        """

    Verify the solution fixes the bug and there are no more issues.

    Verify that no exceptions are thrown when the code is run.

    Reply with SUCCESS if the solution is correct, otherwise return FAILURE.

    If you are happy with the solution, save the code to a file called fixed_bug.py.

    """,

    ),

)

root.add_child(verify)

tree = py_trees.trees.BehaviourTree(root)

while True:

    tree.tick()    

    if root.status == py_trees.common.Status.SUCCESS:

        break  #4

    time.sleep(20)

Code Breakdown

  • #1: Creates a conversation thread shared by assistants.
  • #2: A debugging assistant identifies and fixes the bugs in the code.
  • #3: A verification assistant ensures the bug is fixed and saves the corrected file.
  • #4: The process runs until both debugging and verification succeed.

Running the Example

  1. Save the script as agentic_conversation_btree.py.
  2. Run it in VS Code or execute it directly using:
    python agentic_conversation_btree.py
  3. Once completed, check assistant_outputs/fixed_bug.py for the corrected code.

By leveraging multi-agent conversation, you enable AI assistants to collaborate efficiently, ensuring faster debugging and enhanced automation.