Core Architecture
OpenManus is built on an agent-based architecture with a hierarchical inheritance pattern:
- BaseAgent (app/agent/base.py): The foundation class that provides:
- Memory management
- State transitions
- Execution loop control
- Stuck state detection
- ReActAgent (app/agent/react.py): Extends BaseAgent with:
- Think-Act cycle pattern
- Abstract methods for thinking and acting
- ToolCallAgent (app/agent/toolcall.py): Extends ReActAgent with:
- Tool/function calling capabilities
- Tool execution handling
- Response processing
- BrowserAgent (app/agent/browser.py): Extends ToolCallAgent with:
- Browser control capabilities
- Screenshot handling
- Browser state management
- Manus (app/agent/manus.py): The main agent class that extends BrowserAgent with:
- Additional tools (Python execution, browser use, string replacement)
- Context-aware thinking process
Main Components
- Entry Points:
main.py: Simple CLI interface to run the Manus agentrun_mcp.py: Alternative version using MCP toolrun_flow.py: Experimental multi-agent version
- Tools System (app/tool/):
browser_use_tool.py: Web browser automationpython_execute.py: Safe Python code executionstr_replace_editor.py: Text manipulation
- LLM Integration (app/llm.py):
- Handles communication with language models
- Manages tool calling format
- Memory and State Management (app/schema.py):
- Defines message structure
- Maintains agent state
- Handles tool calls
- Configuration (app/config.py):
- Manages system settings
- Browser configuration
Execution Flow
When you run python main.py:
- The script creates a Manus agent instance
- It prompts the user for input
- The agent processes the input through its run method
- The agent executes a series of think-act cycles:
- Think: Processes the current state and decides what to do
- Act: Executes the decided actions using tools
- The agent continues until it reaches a conclusion or hits the maximum step limit
Key Features
- Browser Automation: Can navigate websites, interact with elements, and extract content
- Python Code Execution: Can run Python code in a sandboxed environment
- Planning Capabilities: Uses LLM for planning and reasoning
- Error Handling: Detects stuck states and has robust error recovery
- Extensibility: Modular design allows for adding new tools and capabilities
How to Use OpenManus
As seen in the README.md, you can run OpenManus in several ways:
- Basic usage:
python main.py - MCP tool version:
python run_mcp.py - Multi-agent version:
python run_flow.py
The agent is designed to handle a wide range of tasks through natural language instructions, leveraging its tools to accomplish complex goals.