In the previous ConversableAgent example we demonstrated that you were able to chat with an agent.

As you build your own workflows, you can decide if and how to use your human in the loop agents. As demonstrated previously, and in the following example, to do so, simply use the ConversableAgent and set the human_input_mode to ALWAYS.

Let’s start to build a more useful scenario, a classroom lesson planner, and create our human agent.

You’ll also see in this example that you can use the system_message property to give detailed instructions to agents.

from autogen import ConversableAgent

# Put your key in the OPENAI_API_KEY environment variable
llm_config = {"api_type": "openai", "model": "gpt-4o-mini"}

planner_system_message = """You are a classroom lesson agent.
Given a topic, write a lesson plan for a fourth grade class.
Use the following format:
<title>Lesson plan title</title>
<learning_objectives>Key learning objectives</learning_objectives>
<script>How to introduce the topic to the kids</script>
"""

my_agent = ConversableAgent(
    name="lesson_agent",
    llm_config=llm_config,
    system_message=planner_system_message,
)

# 1. Create our "human" agent
the_human = ConversableAgent(
    name="human",
    human_input_mode="ALWAYS",
)

# 2. Initiate our chat between the agents
the_human.initiate_chat(
    recipient=my_agent,
    message="Today, let's introduce our kids to the solar system."
    )
  1. Create our human-in-the-loop agent by setting its human_input_mode, and no llm_config is required.

  2. Our the_human agent starts a conversation by sending a message to lesson_planner. An agent’s initiate_chat method is used to start a conversation between two agents.

This creates a conversation between you and the lesson planner agent.