Integrate AgentsMon with AutoGPT to monitor autonomous agent commands, web browsing, and file operations.
``bash
pip install agentsmon
`
This installs the AgentsMon Python SDK which includes AgentsMonAutoGPTHooks for AutoGPT integration.
The Python SDK provides a ready-made hooks class that monitors AutoGPT's command execution, browsing, file operations, and thinking phases. No need to write your own plugin -- just import and use:
`python
from agentsmon.autogpt import AgentsMonAutoGPTHooks
import os
hooks = AgentsMonAutoGPTHooks(
endpoint=os.getenv("AGENTSMON_URL", "http://localhost:18800"),
agent_id=os.getenv("AUTOGPT_AGENT_ID", "autogpt-main")
)
`
The AgentsMonAutoGPTHooks class provides:
-- tracks command execution -- tracks the thinking/planning phase -- tracks web browsing -- tracks file writes -- tracks file readsAll events are sent asynchronously and non-blocking -- if AgentsMon is unreachable, your agent continues unaffected.
Add to your AutoGPT main.py or agent loop:
`python
from agentsmon.autogpt import AgentsMonAutoGPTHooks
import os
hooks = AgentsMonAutoGPTHooks(
endpoint=os.getenv("AGENTSMON_URL", "http://localhost:18800"),
agent_id=os.getenv("AUTOGPT_AGENT_ID", "autogpt-main")
)
def execute_command(command_name: str, arguments: dict) -> str:
# Monitor the command
hooks.on_command(command_name, arguments)
# Handle specific commands
if command_name == "browse_website":
hooks.on_browse(arguments.get("url", ""))
elif command_name == "write_to_file":
hooks.on_write_file(arguments.get("filename", ""))
elif command_name == "read_file":
hooks.on_read_file(arguments.get("filename", ""))
# Execute the actual command
return original_execute(command_name, arguments)
`
If you cannot modify AutoGPT source, use the SDK's log forwarder:
`python
from agentsmon.autogpt import AgentsMonAutoGPTHooks
hooks = AgentsMonAutoGPTHooks(
endpoint="http://localhost:18800",
agent_id="autogpt-agent"
)
`
AutoGPT is autonomous -- it can execute any command. AgentsMon Shield mode lets you block unsafe actions before they run:
`python
from agentsmon import AgentsMonGuard
from agentsmon.autogpt import AgentsMonAutoGPTHooks
import os
guard = AgentsMonGuard(
endpoint=os.getenv("AGENTSMON_URL", "http://localhost:18800"),
agent_id="autogpt-main"
)
hooks = AgentsMonAutoGPTHooks(
endpoint=os.getenv("AGENTSMON_URL", "http://localhost:18800"),
agent_id="autogpt-main"
)
def execute_command(command_name: str, arguments: dict) -> str:
# Check with guard before executing
result = guard.check_command(f"{command_name} {arguments}")
if result.blocked:
return f"BLOCKED by AgentsMon: {result.reason}"
# Also check file access
if command_name in ("write_to_file", "read_file"):
file_result = guard.check_file(arguments.get("filename", ""), command_name.split("_")[0])
if file_result.blocked:
return f"BLOCKED by AgentsMon: {file_result.reason}"
# Monitor the command
hooks.on_command(command_name, arguments)
# Execute the actual command
return original_execute(command_name, arguments)
`
Shield mode calls AgentsMon's security engines (sandbox monitor, behavioral analyzer, prompt injection scanner) synchronously and returns a verdict before the action runs.
| AutoGPT Action | AgentsMon Event | Data Captured |
|---------------|-----------------|---------------|
| Command execution | command | Command name, arguments |
| Thinking/planning | command | Thought summary |
| Web browsing | http_request | URL, method |
| File write | file_access | File path, write operation |
| File read | file_access | File path, read operation |
`bash
curl http://localhost:18800/api/events?platform=autogpt
curl http://localhost:18800/api/agents?platform=autogpt
curl http://localhost:18800/api/events/anomalies?platform=autogpt
`
`yaml
services:
agentsmon:
build: ./agentsmon/backend
ports: ["18800:18800"]
autogpt:
image: significantgravitas/auto-gpt
environment:
- AGENTSMON_URL=http://agentsmon:18800
depends_on: [agentsmon]
`
In your AutoGPT Dockerfile or requirements:
`
agentsmon
`
AutoGPT is autonomous -- it can execute any command. AgentsMon is especially important here:
)`bash
curl http://localhost:18800/api/trust/level/autogpt-main
curl http://localhost:18800/api/sandbox/violations?agentId=autogpt-main
``