I was setting up a new multi-agent workflow in AutoGen yesterday and had a bit of a scare. I configured a `UserProxyAgent` with code execution enabled, and the `AssistantAgent` almost ran a `terraform apply` that would have spun up several expensive EC2 instances I didn't need. It was a good reminder of a powerful, sometimes overlooked, safety feature.
You can enforce a human approval step for any code execution, especially for commands with potential cost or security impact. It's done by setting `human_input_mode` to "ALWAYS" on your `UserProxyAgent`. This forces the agent to ask for confirmation before running *any* code block it receives.
Here's a quick snippet from my Terraform-focused setup:
```python
from autogen import UserProxyAgent, AssistantAgent
user_proxy = UserProxyAgent(
name="UserProxy",
human_input_mode="ALWAYS", # This is the key
code_execution_config={"work_dir": "terraform"},
is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE")
)
terraform_assistant = AssistantAgent(
name="TerraformAssistant",
system_message="You are a Terraform expert. Provide code but do not run it unless the human approves.",
llm_config={"config_list": config_list},
)
```
With this, the workflow pauses and presents the proposed code in the console, waiting for a 'y' or 'n' input. For cost control, you can get more granular by implementing custom validation logic, but starting with "ALWAYS" is a great way to avoid surprises.
It's a simple setting, but it turns AutoGen from a potential runaway train into a collaborative tool. I now use it by default for any agent that might touch infrastructure or production data. It adds a minor delay but saves so much anxiety.
-- Amy
Cloud cost nerd. No, I don't use Reserved Instances.
Setting human_input_mode to ALWAYS is a basic start, but it's a blunt instrument. You're still relying on the human to catch every expensive command in real time. That's an operational risk.
The real control should be at the permissions layer. The system should prevent the agent from even proposing a terraform apply on production without specific, pre-approved context. Otherwise you're just building a manual approval queue for a system designed to automate.
Trust, but audit.
That's a really good point about shifting control to the permissions layer. It reminds me of the principle of least privilege in traditional CI/CD. Maybe a hybrid approach is needed? Something like a "gated" mode where the system checks a predefined list of dangerous commands and only asks for human input on those, while letting everything else run. Do you know if there are any plugins or patterns emerging for that in AutoGen?
still learning