오픈 매뉴스의 멀티 에이전트 프레임워크 분석

프로젝트 개요

최근 오픈AI와 딥서치 등의 발전으로 인해 AI 에이전트의 역할이 더욱 중요해지고 있습니다. 본 문서에서는 오픈 매뉴스(Open Manus) 프로젝트를 통해 이들 에이전트가 어떻게 작동하는지 상세히 살펴보겠습니다.

1. 프로젝트 구조

오픈 매뉴스는 크게 네 가지 주요 모듈로 구성됩니다:

  • 에이전트(agent/): 기본 기능을 제공합니다.
  • 플로우(flow/): 작업 흐름 관리를 담당합니다.
  • 프롬프트(prompt/): 각 모듈의 시스템 명령어를 정의합니다.
  • 툴(tool/): 확장 가능한 도구 모음을 제공합니다.
app/
    config.py
    exceptions.py
    llm.py
    logger.py
    schema.py
    __init__.py
    agent/
        base.py
        manus.py
        planning.py
        react.py
        swe.py
        toolcall.py
        __init__.py
    flow/
        base.py
        flow_factory.py
        planning.py
        __init__.py
    prompt/
        manus.py
        planning.py
        swe.py
        toolcall.py
        __init__.py
    tool/
        base.py
        bash.py
        browser_use_tool.py
        create_chat_com

1.1 루트 디렉토리

루트 디렉토리에는 설정 파일과 예외 처리, 로깅 관련 코드가 포함되어 있습니다. 여기서는 llm.pyschema.py에 집중하겠습니다.

1.1.1 LLM 관리 (llm.py)

llm.py는 대형 언어 모델(LLM) API 호출을 캡슐화하며, 메시지 포맷팅, 토큰 카운팅, API 요청 및 재시도 전략을 제공합니다.

class LanguageModelManager:
    def ask(self, messages):
        # 메시지 포맷팅 및 API 호출
        pass

    def ask_tool(self, messages, tools):
        # 도구 호출 API
        pass
1.1.2 스키마 정의 (schema.py)

schema.py는 대화 메시지, 도구 호출, 대화 메모리의 데이터 구조를 정의합니다.

from enum import Enum

class Role(Enum):
    USER = "user"
    ASSISTANT = "assistant"

class ToolChoice(Enum):
    NONE = "none"
    REQUIRED = "required"
    AUTO = "auto"

class Message:
    def __init__(self, role, content):
        self.role = role
        self.content = content

class Memory:
    def __init__(self):
        self.messages = []
    
    def add_message(self, message):
        self.messages.append(message)

2. 에이전트 모듈

에이전트 모듈은 오픈 매뉴스의 핵심 부분이며, 여러 서브 모듈로 나뉩니다.

2.1 주 에이전트 (manus.py)

manus.py는 전체 오픈 매뉴스의 동작을 조율하는 주 에이전트입니다.

class MainAgent:
    def __init__(self):
        self.available_tools = [
            PythonExecute(), WebSearch(), BrowserUseTool(), FileSaver(), Terminate()
        ]

    def execute_task(self, task_name):
        for tool in self.available_tools:
            if tool.name == task_name:
                return tool.execute()

2.2 코드 실행 에이전트 (swe.py)

SWEAgent는 시스템 터미널과 상호작용하여 명령어를 실행할 수 있습니다.

class SWEAgent:
    def __init__(self):
        self.available_tools = [
            Bash(), StrReplaceEditor(), Terminate()
        ]
    
    async def think(self):
        working_dir = await self.bash.execute("pwd")
        next_step_prompt = self.next_step_prompt.format(current_dir=working_dir)
        return await super().think()

2.3 작업 계획 에이전트 (planning.py)

PlanningAgent는 작업을 분해하고 실행 계획을 만듭니다.

class PlanningAgent:
    def analyze_task(self, task):
        steps = task.split(';')
        return steps
    
    def create_plan(self, steps):
        plan = {}
        for step in steps:
            plan[step] = 'pending'
        return plan

2.4 도구 호출 에이전트 (toolcall.py)

ToolCallAgent는 도구 호출의 전체 과정을 관리합니다.

class ToolCallAgent:
    async def think(self):
        response = await self.llm.ask_tool(messages=self.messages, tools=self.available_tools)
        self.tool_calls = response.tool_calls
        return bool(self.tool_calls)

    async def act(self):
        results = []
        for command in self.tool_calls:
            result = await self.execute_tool(command)
            results.append(result)
        return "\n\n".join(results)

3. 플로우 관리

flow/ 디렉토리는 작업 흐름 관리를 담당합니다.

3.1 기본 플로우 (base.py)

BaseFlow 클래스는 다수의 에이전트 간의 실행 흐름을 관리합니다.

class BaseFlow:
    def manage_steps(self, steps):
        status = {}
        for step in steps:
            status[step] = 'in_progress'
        return status

3.2 작업 계획 플로우 (planning.py)

PlanningFlow는 작업의 생성, 실행, 진행 상태 추적 및 요약을 담당합니다.

class PlanningFlow(BaseFlow):
    def track_progress(self, tasks):
        progress = {}
        for task in tasks:
            progress[task] = 'completed'
        return progress

4. 프롬프트 관리

prompt/ 디렉토리는 각 에이전트의 프롬프트 템플릿을 정의합니다.

4.1 주 에이전트 프롬프트 (manus.py)

주 에이전트의 프롬프트는 다양한 도구를 사용하여 복잡한 요청을 효율적으로 처리하도록 설계되었습니다.

SYSTEM_PROMPT = "당신은 OpenManus, 모든 종류의 작업을 처리할 수 있는 AI 어시스턴트입니다."
NEXT_STEP_PROMPT = "다음 단계를 선택하세요: PythonExecute, FileSaver, BrowserUseTool, WebSearch, Terminate."

4.2 작업 계획 에이전트 프롬프트 (planning.py)

작업 계획 에이전트의 프롬프트는 구조화된 작업 계획을 만들도록 지시합니다.

PLANNING_SYSTEM_PROMPT = "당신은 작업을 분석하고 구조화된 계획을 만드는 전문가입니다."
NEXT_STEP_PROMPT = "다음 단계를 결정하세요: Create, update, mark_step, finish."

4.3 코드 실행 에이전트 프롬프트 (swe.py)

코드 실행 에이전트의 프롬프트는 명확한 코드 작성 및 명령 실행을 강조합니다.

SYSTEM_PROMPT = "명령줄에서 직접 작업하는 자율 프로그래머입니다."
NEXT_STEP_TEMPLATE = "(현재 디렉토리: {cwd})\nbash-$"

5. 도구 확장

tool/ 디렉토리는 확장 가능한 도구 모음을 제공합니다.

class BashTool:
    def execute(self, command):
        # 명령 실행 로직
        pass

class BrowserUseTool:
    def open_page(self, url):
        # 웹 페이지 열기 로직
        pass

태그: LLM 에이전트 오픈매뉴스 플로우관리 프롬프트

7월 5일 03:31에 게시됨