How to beginner · 3 min read

How to use human input mode in AutoGen

Quick answer
Use AutoGen's human input mode by configuring the agent to pause and accept manual input during execution, enabling interactive workflows. This is done by setting up a human input function or handler that the AutoGen agent calls to receive user responses dynamically.

PREREQUISITES

  • Python 3.8+
  • pip install autogen
  • Basic understanding of AutoGen agent workflows

Setup

Install the autogen Python package and ensure you have Python 3.8 or higher. Set up your environment and import necessary modules.

bash
pip install autogen

Step by step

Below is a complete example demonstrating how to enable human input mode in AutoGen. The agent pauses and waits for user input during its execution.

python
from autogen import AutoAgent

# Define a human input handler function
# This function will be called by the agent to get input from the user

def human_input_handler(prompt: str) -> str:
    print(f"Agent asks: {prompt}")
    user_response = input("Your response: ")
    return user_response

# Initialize the AutoAgent with human input mode enabled
agent = AutoAgent(human_input=human_input_handler)

# Example workflow where the agent requests human input
response = agent.run("Please provide your name.")
print(f"Agent received human input: {response}")
output
Agent asks: Please provide your name.
Your response: Alice
Agent received human input: Alice

Common variations

You can customize human input mode by integrating GUI input dialogs instead of console input, or by asynchronously handling input in web apps. Also, you can switch models or chain human input with AI completions for hybrid workflows.

python
import asyncio
from autogen import AutoAgent

async def async_human_input_handler(prompt: str) -> str:
    # Example async input simulation
    print(f"Agent asks asynchronously: {prompt}")
    await asyncio.sleep(1)  # simulate wait
    return "Simulated async user input"

agent = AutoAgent(human_input=async_human_input_handler)

async def main():
    response = await agent.run_async("What is your favorite color?")
    print(f"Agent received: {response}")

asyncio.run(main())
output
Agent asks asynchronously: What is your favorite color?
Agent received: Simulated async user input

Troubleshooting

  • If the agent does not pause for input, ensure the human_input parameter is correctly set to a callable that returns a string.
  • For GUI apps, verify the input handler integrates properly with the event loop.
  • If input blocks indefinitely, check that your environment supports interactive input (e.g., not running in a non-interactive script).

Key Takeaways

  • Enable human input mode by passing a callable to the AutoAgent's human_input parameter.
  • Human input handlers can be synchronous or asynchronous depending on your app environment.
  • Use human input mode to create interactive AI workflows that combine manual and automated steps.
Verified 2026-04
Verify ↗