AgentScope Multi-Agent Platform

repository·main·Indexed 12 days ago

https://github.com/agentscope-ai/agentscope

A production-ready, flexible multi-agent framework designed for agentic LLMs. AgentScope 2.0 focuses on modular building blocks for model reasoning and tool-use, featuring a multi-tenant Agent Service with FastAPI and Redis, long-term memory solutions via AgenticMemoryMiddleware and ReMe, and RAG capabilities supporting vector stores like Milvus Lite, MongoDB, and Elasticsearch.

Tokens
24.8K
Snippets
67
Records
98
Agent score
96%

What's inside AgentScope

  1. Overview of AgentScope Agent Service capabilities

    main

    AgentScope provides an out-of-the-box Agent Service based on FastAPI, designed to transform agents into multi-tenant, multi-session applications. It includes a pre-built Web UI (found in examples/web_ui) and supports the following core capabilities:

    • Service: Multi-tenancy, multi-session isolation, FastAPI backend, and pre-built Web UI.
    • Agent Teams: Leader–Worker orchestration, built-in team tools, and task planning.
    • Message Channels: Integration with IM platforms like Lark (Feishu), Discord, and custom channels via message routing.
    • RAG Service: Blob storage, Index Workers, and multi-tenant retrieval.
    • MCP & Skill Hub: Browsing Hubs (e.g., GitHub MCP Registry, ClawHub), installing skills to your library, and adding them to workspaces.
    • Resource Sharing: Resource management for groups and organizations, including shared models, MCP services, skills, and workspaces.
    • Persistence: SQL & NoSQL persistence for agent states and sessions.
    • Scheduling: Scheduled tasks, agent wake-ups, and background task offloading.
  2. Overview of AgentScope 2.0 Building Blocks

    main

    AgentScope 2.0 provides several core abstractions to build agentic applications:

    Building blockDescription
    ReActReasoning-acting loop with structured output, realtime interruption & resume, and batched tool acting
    ToolkitManagement of Python tools, MCP servers, and skills (includes built-in coding tools like shell, file edit, search)
    ModelSupport for LLM, embedding, and TTS across providers like OpenAI, Anthropic, Gemini, DashScope, DeepSeek, etc.
    ContextMiddleware for automatic compaction, tool-result offload, and context injection (system prompt, RAG, memory)
    Event SystemUnified event bus streaming reasoning, tool calls, and multimodal content to the frontend
    Permission & HITLFine-grained control over tools/resources and Human-In-The-Loop (HITL) confirmation
    MiddlewareComposable hooks for the agent loop (reply, reasoning, acting, model calling, etc.)
    MemoryAgentic memory with backends like ReMe or Mem0
    Workspace / SandboxIsolated execution environments (Local, Docker, Apple Container, E2B, K8s, etc.)
  3. How Mem0Middleware memory modes work

    main

    The mode parameter determines how the middleware interacts with the agent and what the LLM sees.

    static_control

    The middleware operates automatically without the agent's explicit involvement.

    1. Pre-reply: Queries mem0 with the latest user message.
    2. At ReplyStartEvent: Appends an AssistantMsg(name="memory", ...) to the agent's context immediately after the user message. This makes the retrieved memory part of the context for the reasoning loop.
    3. Post-reply: Writes the new (user, assistant) exchange back to mem0.

    agent_control

    The middleware provides tools for the agent to manage its own memory. You must explicitly add these tools to the agent's toolkit.

    • Tools provided: search_memory(keywords, limit) and add_memory(thinking, content).
    • The agent is given a system prompt hint that these tools exist, but no automatic retrieval or write-back occurs.

    both (Default)

    Both patterns are active. Memories are automatically retrieved and appended to the context, AND the agent has access to the memory tools for explicit on-demand search and saving.

    # Example of agent_control mode
    from agentscope.agent import Agent
    from agentscope.tool import Toolkit
    
    mw = Mem0Middleware(user_id="alice", mode="agent_control")
    agent = Agent(
        ...,
        toolkit=Toolkit(tools=await mw.list_tools()),
        middlewares=[mw],
    )
  4. Compare AgentScope RAG Vector Backends

    main

    Choose a vector backend based on your requirements for persistence and infrastructure:

    BackendInstall ExtraExternal ServicePersistenceBest For
    Qdrantagentscope[rag]NoNo (:memory:)Quick start / tests
    Milvus Liteagentscope[vdb-milvus]NoYes (local .db)Local dev with persistence
    MongoDBagentscope[vdb-mongodb]YesYes (server)Teams already on MongoDB
    Elasticsearchagentscope[vdb-elasticsearch]YesYes (server)Teams on Elastic or needing distributed kNN search
  5. Configure memory scoping with `user_id` and `agent_id`

    main

    Mem0 uses user_id and agent_id to tag and filter memories. By default, the middleware uses agent.name as the agent_id.

    You can control how strictly memories are siloed using the scope_search_by_agent flag:

    scope_search_by_agentBehavior
    True (default)Strict per-agent silos. Memories are filtered by both user_id AND agent_id. Agent A cannot see Agent B's memories even if they share a user_id
    FalseRead-broad, write-narrow. All agents for the same user share a single memory pool (searched by user_id only), but each memory still records which agent_id wrote it

    When to use scope_search_by_agent=False: Use this when a single user has multiple specialized agents (e.g., a researcher and a coder) that should share discoveries about the user.

  6. Use AgenticMemoryMiddleware for long-term memory

    main

    The AgenticMemoryMiddleware provides a long-term memory solution using human-readable Markdown files. Unlike traditional RAG systems, it does not require a vector database or an embedding model.

    Key Characteristics:

    • Persistence: Memory is stored as Markdown files on disk, meaning a fresh Agent instance can recall facts from previous sessions if they share the same workspace directory.
    • Scope: Memory is scoped to a specific workdir. Reusing the same workdir allows the Agent to access previously stored information.
    • Mechanism: The middleware automatically includes a MEMORY.md index in the system prompt. It uses this index and the frontmatter of individual topic files to select and inject relevant memory contents as hints for the Agent.
  7. Manage the lifecycle of AppleContainerWorkspace

    main

    The AppleContainerWorkspace follows an asynchronous lifecycle managed via initialize() or the async with context manager.

    • Initialization: When entering the async with block (or calling initialize()), the container is created, the base image is pulled (if not cached), the gateway venv is bootstrapped (via apt-get, uv, and pip), and the MCP gateway starts.
    • Execution: Once initialized, you can access the backend to execute commands.
    • Cleanup: When exiting the async with block (or calling close()), the container is stopped and removed. Note: Filesystem state is not persisted.
    • Idempotency: A second initialize() call on the same container name is a no-op if the container is already running.
    import asyncio
    from agentscope.workspace import AppleContainerWorkspace
    
    async def main():
        async with AppleContainerWorkspace() as ws:
            # Container is created, bootstrapped, gateway is running.
            backend = ws.get_backend()
            result = await backend.exec_shell(["echo", "hello"])
            print(result.stdout)
    
        # Container is stopped and removed.
    
    asyncio.run(main())
  8. Guidelines for contributing new Agents

    main

    AgentScope currently maintains a single core agent class: agentscope.agent.Agent. This class integrates memory, tools, MCP, formatter, and models.

    • For specific domains or specialized agents: Do not add new classes to agentscope.agent. Instead, contribute them as examples.
    • For new top-level Agent classes: If you believe a use case requires a new top-level class, you must:
      1. Open an issue describing the use case and why the existing Agent class is insufficient.
      2. Wait for the core team to discuss the design.
      3. Only begin implementation after design approval. PRs introducing new agent classes without prior discussion will be rejected.
  9. How AgentScope-as-mem0-backend works

    main

    When you provide chat_model and embedding_model to build_mem0_config, AgentScope acts as the backend for mem0 through the following mechanism:

    1. Provider Registration: It registers AgentScopeLLM and AgentScopeEmbedding in mem0's factory under the provider name "agentscope".
    2. Config Substitution: It substitutes standard mem0 LlmConfig and EmbedderConfig with specialized subclasses that allow the "agentscope" provider name.
    3. Adapter Routing: It builds an AsyncMemory instance where .llm and .embedding_model calls are routed through AgentScope adapters.
    4. Async Bridging: It bridges mem0's synchronous API to AgentScope's asynchronous models using a persistent background event loop, ensuring connection pools (like those in Ollama's AsyncClient) are maintained across calls.

    Note on Dimensions: Ensure your embedding model's dimensions match the vector store's requirements. For example, mem0's default Qdrant expects 1536 dimensions (matching DashScope's text-embedding-v2).

  10. AgentScope 2.0 SDK Building Blocks

    main

    AgentScope 2.0 provides a suite of modules to build production-ready agents:

    ModuleDescription
    ReActReasoning-Action loop supporting structured output, real-time interruption/resumption, and batch tool execution.
    ToolkitsAutonomous tool management including Python tools, MCP, and Skill. Includes built-in Shell, File Edit, and Search tools.
    ModelsSupport for LLM, Embedding, and TTS from providers like OpenAI, Anthropic, Gemini, DashScope, DeepSeek, Moonshot, xAI, and Ollama.
    ContextMiddleware for automatic compression, tool result offloading, and context injection (System Prompts, RAG, Memory).
    Event SystemA unified event bus that streams reasoning, tool calls, and multimodal content (text, image, audio) to the frontend.
    Permissions & HITLFine-grained control over tools and resources, including confirmation and bypass modes.
    MiddlewareComposable hooks for the agent loop (Reply, Reasoning, Action, Model Call, Permission Check, etc.).
    MemoryAgentic Memory with switchable backends like ReMe or Mem0.
    Workspaces / SandboxesIsolated execution environments including Local, Docker, Apple Container, Bubblewrap, E2B, OpenSandbox, Daytona, and K8s.
  11. Understand model example test types

    main

    The model example scripts are categorized by suffixes indicating the complexity and features being tested:

    SuffixFile PatternWhat it covers
    call*_call.pyBasic text call + two-round tool calling + structured output
    multiagent*_multiagent.pyMulti-agent scenario using MultiAgentFormatter
    multimodal*_multimodal.pyImage + text multimodal input
    multiagent_multimodal*_multiagent_multimodal.pyMulti-agent + multimodal combined
  12. Implement lazy imports for optional dependencies

    main

    To keep the core import agentscope lightweight, any dependency that is not listed in the base [project.dependencies] (i.e., those belonging to optional extras like gemini, ollama, xai, service, or storage) must be imported lazily inside functions rather than at the top of the module.

    This ensures that ImportError is only raised when the specific functionality requiring that extra is actually invoked.

    def some_function():
        import google.genai  # Lazy import from `gemini` extra
        # ... use google.genai here
    def some_function():
        import google.genai  # 来自 `gemini` extra,惰性导入
        # ... 在这里使用 google.genai