How mannaandpoem/openmanus works
Project type and purpose
• OpenManus is an open‑source Python framework for building general AI agents (single‐agent or multi‑agent), orchestrating “flows” of prompts, LLM calls, tool invocations, and sandboxed execution.
• It provides a CLI interface (main.py, run_flow.py, run_mcp.py), a modular agent toolkit (app/agent), prompt templates (app/prompt), LLM wrappers (app/llm), a sandboxed execution environment (app/sandbox), and a library of tools (app/tool).
File structure
Top‑level:
• main.py, run_flow.py, run_mcp.py: entrypoints
• app/: core framework
• agent/: base and specialized agent classes
• flow/: flow definitions and factory
• llm.py: interface to external LLM APIs
• prompt/: prompt‐template modules
• sandbox/: client, core manager, terminal, exceptions
• tool/: abstraction and concrete tool implementations (search, file ops, Python execution, etc.)
• config/: TOML/JSON examples for API keys and settings
• tests/: unit tests for sandbox
• examples/: usage examples
README insights
• CLI usage is primary.
• Supports multiple LLM providers (OpenAI, Anthropic, Azure, etc.).
• Optional browser automation (Playwright).
• Encourages configuration via config/config.toml.
We recommend producing two views:
A. System Context (C4 Level 1)
• External System: “Cloud Browser Automation” (optional)
• External System: “File System / Local Shell”
• Developer → OpenManus CLI (“runs commands, inputs ideas”)
• OpenManus CLI → LLM API Provider (“HTTP requests for completions”)
• OpenManus CLI → Cloud Browser Automation (“Playwright calls if enabled”)
• OpenManus CLI → File System / Local Shell (“reads/writes files, runs Python”)
1. CLI Application (main.py, run_flow.py, run_mcp.py)
• Responsibilities: parse commands, load config, bootstrap agent/flow
2. Configuration Loader (app/config.py)
• Parses TOML/JSON into runtime settings
3. Agent Orchestrator (app/agent/*)
• BaseAgent + specialized agents (browser, mcp, swe, react, toolcall, manus)
• Factory to instantiate based on CLI flags
4. Flow Engine (app/flow/*)
• Defines flow patterns (planning, base) and flow_factory
• Manages multi‑step interaction logic
5. Prompt Module (app/prompt/*)
• Templates for each agent/flow
6. LLM Client (app/llm.py)
• Wraps HTTP calls to configured LLM provider
7. Sandbox Manager (app/sandbox/core/manager.py)
• Creates/tears down ephemeral Docker or in‑process sandboxes
8. Sandbox Terminal (app/sandbox/core/terminal.py)
• Executes shell commands in sandbox
9. Tool Runner (app/tool/*)
• Abstract base plus tool_collection for Python exec, searches, file ops, etc.
• CLI App → Config Loader → returns settings → CLI App
• CLI App → Agent Orchestrator → selects Flow Engine
• Flow Engine ↔ Prompt Module (generates prompts)
• Flow Engine → LLM Client → returns LLM response
• LLM Client → External LLM API
• Flow Engine → Tool Runner / Sandbox Manager → executes external code/actions
• Tool Runner → External Browser Automation (if browser tool used)
• Sandbox Manager → Local Docker / OS Shell → returns execution result
Architectural Patterns & Design Principles
• Modular containers for separation of concerns (CLI, config, agent, flow, llm, sandbox, tools)
• Factory pattern for agent and flow instantiation (flow_factory, agent base factory)
• Strategy pattern for tools and prompts (each tool/prompt is a pluggable module)
• Dependency injection via config loader
Elements to Capture
• Clear component names matching code (e.g., “app/agent/browser.py”)
• Configurable integration points (LLM APIs, browser, Docker)
• Factories and pluggable modules