How modelscope/agentscope works
Project Type and Purpose
• AgentScope is a Python-based multi-agent platform and SDK for building LLM-powered applications.
• It provides a core library (src/agentscope/…) with abstractions for agents, messages, memory, pipelines, RPC/server, and UI (Studio).
• It also supplies example applications (e.g., applications/multisource_rag_app), deployment scripts (scripts/), documentation (docs/), and tests (tests/).
Top-Level Architecture Components
• Core Library (Python package under src/agentscope):
• Agents: dialog, RAG, React, user, dictionary agents
• Message & Memory: message/, memory/
• Models: wrappers for OpenAI, DashScope, Gemini, Zhipu, Ollama, LiteLLM, Yi, PostAPI, Anthropic
• Service Layer: retrieval, web search, code execution, file I/O, SQL queries, multi-modality, web browser control
• Manager & RPC: actor-based distribution (manager/), gRPC definitions (rpc/), server launcher and servicer
• Pipelines & Strategy: composite workflows (pipelines/, strategy/)
• Prompt: generation, optimization, formatting
• Studio UI: backend (studio/), frontend assets (HTML/CSS/JS under studio/static), Gradio integration
• Example Multi-Source RAG Application (applications/multisource_rag_app):
• Agents and utilities for context management, retrieval, summarization, reranking, query rewrite
• Knowledge stores: local files and Elasticsearch
• Async model orchestration (async_model/)
• Gradio frontend (studio/gradio_with_feedback.py), server entrypoint (copilot_server.py)
• Deployment & Service Scripts (scripts/): setups for Ollama, FastChat, vLLM, Flask+Transformers/Mo delScope
• Documentation & Testing: Sphinx tutorial docs under docs/tutorial, unit tests under tests/
Component Interactions and Data Flows
• An application instantiates one or more Agent objects. Messages (Msg) flow between agents over in-process calls or via RPC for distributed mode.
• ModelWrapper components abstract LLM API calls; these may be local (Flask, FastChat, vLLM) or remote (OpenAI, DashScope, etc.).
• The service layer is invoked by agents to fetch external data (web search, SQL, file ops, code execution).
• Pipelines chain multiple agents or services in series/parallel with conditionals and loops.
• The Manager/Launcher handles actor lifecycles and scheduling; gRPC (rpc_agent.proto) is used for inter-process communication.
• Studio UI communicates with the backend via WebSocket or HTTP to render dialogues, pipelines, and multi-modal outputs in the browser/Gradio.
Architectural Patterns and Principles
• Actor Model: Each agent or service runs as an independent actor (possibly remote).
• Adapter/Wrapper Pattern: ModelWrapper and Service classes abstract differences among LLM APIs and services.
• Pipeline Composition: Functional and class-based pipelines allow conditional and sequential execution.
• Layered Separation:
• API Layer (ModelWrapper, Service)
• Business Logic (Agents, Pipelines, Strategies)
• Orchestration Layer (Manager, RPC, Studio server)
• Presentation Layer (Studio frontend, Gradio)
• Configuration-Driven: JSON/YAML configs under configs/ drive agent and knowledge behaviors.