← Back to AgentsMon

AutoGPT Integration Guide

Integrate AgentsMon with AutoGPT to monitor autonomous agent commands, web browsing, and file operations.

Installation

``bash

pip install agentsmon

`

This installs the AgentsMon Python SDK which includes AgentsMonAutoGPTHooks for AutoGPT integration.

SDK 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:

All events are sent asynchronously and non-blocking -- if AgentsMon is unreachable, your agent continues unaffected.

Integration with AutoGPT

Option 1: Direct Hook (Recommended)

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")

)

In your command execution loop:

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)

`

Option 2: Webhook Forwarder

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"

)

The SDK can also tail AutoGPT logs and forward events automatically:

See agentsmon.autogpt.LogForwarder for details

`

Shield Mode

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.

Event Mapping

| 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 |

Verification

`bash

Check events are flowing

curl http://localhost:18800/api/events?platform=autogpt

Check agent was registered

curl http://localhost:18800/api/agents?platform=autogpt

Check for dangerous commands

curl http://localhost:18800/api/events/anomalies?platform=autogpt

`

Docker Deployment

`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

`

Security Considerations

AutoGPT is autonomous -- it can execute any command. AgentsMon is especially important here:

`bash

Check trust level for your AutoGPT agent

curl http://localhost:18800/api/trust/level/autogpt-main

View sandbox violations

curl http://localhost:18800/api/sandbox/violations?agentId=autogpt-main

``