Skip to main content

A production-ready runtime framework for agent applications, providing secure sandboxed execution environments and scalable deployment solutions with multi-framework support.

Project description

AgentScope Runtime v1.0

GitHub Repo PyPI Downloads Python Version Last Commit License Code Style GitHub Stars GitHub Forks Build Status Cookbook DeepWiki A2A MCP Discord DingTalk

[Cookbook] [ไธญๆ–‡README] [Samples]

A Production-Ready Runtime Framework for Intelligent Agent Applications

AgentScope Runtime is a full-stack agent runtime that tackles two core challenges: efficient agent deployment and secure sandbox execution. It ships with foundational services such as short- and long-term memory plus agent state persistence, along with hardened sandbox infrastructure. Whether you need to orchestrate production-grade agents or guarantee safe tool interactions, AgentScope Runtime provides developer-friendly workflows with complete observability.

In V1.0, these services are exposed via an adapter pattern, enabling seamless integration with the native modules of different agent frameworks while preserving their native interfaces and behaviors, ensuring both compatibility and flexibility.


๐Ÿ†• NEWS

  • [2025-12] We have released AgentScope Runtime v1.0, introducing a unified โ€œAgent as APIโ€ white-box development experience, with enhanced multi-agent collaboration, state persistence, and cross-framework integration. This release also streamlines abstractions and modules to ensure consistency between development and production environments. Please refer to the CHANGELOG for full update details and migration guide.

โœจ Key Features

  • ๐Ÿ—๏ธ Deployment Infrastructure: Built-in services for agent state management, conversation history, long-term memory, and sandbox lifecycle control
  • ๐Ÿ”ง Framework-Agnostic: Not tied to any specific agent framework; seamlessly integrates with popular open-source and custom implementations
  • โšก Developer-Friendly: Offers AgentApp for easy deployment with powerful customization options
  • ๐Ÿ“Š Observability: Comprehensive tracking and monitoring of runtime operations
  • ๐Ÿ”’ Sandboxed Tool Execution: Isolated sandbox ensures safe tool execution without affecting the system
  • ๐Ÿ› ๏ธ Out-of-the-Box Tools & One-Click Adaptation: Rich set of ready-to-use tools, with adapters enabling quick integration into different frameworks

[!NOTE]

About Framework-Agnostic: Currently, AgentScope Runtime supports the AgentScope framework. We plan to extend compatibility to more agent development frameworks in the future. This table shows the current versionโ€™s adapter support for different frameworks. The level of support for each functionality varies across frameworks:

Framework/Feature Message/Event Tool Service
AgentScope โœ… โœ… โœ…
LangGraph โœ… ๐Ÿšง ๐Ÿšง
AutoGen ๐Ÿšง โœ… ๐Ÿšง
Microsoft Agent Framework ๐Ÿšง ๐Ÿšง ๐Ÿšง
Agno โœ… โœ… ๐Ÿšง

๐Ÿ’ฌ Contact

Welcome to join our community on

Discord DingTalk

๐Ÿ“‹ Table of Contents


๐Ÿš€ Quick Start

Prerequisites

  • Python 3.10 or higher
  • pip or uv package manager

Installation

From PyPI:

# Install core dependencies
pip install agentscope-runtime

# Install extension
pip install "agentscope-runtime[ext]"

# Install preview version
pip install --pre agentscope-runtime

(Optional) From source:

# Pull the source code from GitHub
git clone -b main https://github.com/agentscope-ai/agentscope-runtime.git
cd agentscope-runtime

# Install core dependencies
pip install -e .

Agent App Example

This example demonstrates how to create an agent API server using agentscope ReActAgent and AgentApp. To run a minimal AgentScope Agent with AgentScope Runtime, you generally need to implement:

  1. @agent_app.init โ€“ Initialize services/resources at startup
  2. @agent_app.query(framework="agentscope") โ€“ Core logic for handling requests, must use stream_printing_messages to yield msg, last for streaming output
  3. @agent_app.shutdown โ€“ Clean up services/resources on exit
import os

from agentscope.agent import ReActAgent
from agentscope.model import DashScopeChatModel
from agentscope.formatter import DashScopeChatFormatter
from agentscope.tool import Toolkit, execute_python_code
from agentscope.pipeline import stream_printing_messages

from agentscope_runtime.engine import AgentApp
from agentscope_runtime.engine.schemas.agent_schemas import AgentRequest
from agentscope_runtime.adapters.agentscope.memory import (
    AgentScopeSessionHistoryMemory,
)
from agentscope_runtime.engine.services.agent_state import (
    InMemoryStateService,
)
from agentscope_runtime.engine.services.session_history import (
    InMemorySessionHistoryService,
)

agent_app = AgentApp(
    app_name="Friday",
    app_description="A helpful assistant",
)


@agent_app.init
async def init_func(self):
    self.state_service = InMemoryStateService()
    self.session_service = InMemorySessionHistoryService()

    await self.state_service.start()
    await self.session_service.start()


@agent_app.shutdown
async def shutdown_func(self):
    await self.state_service.stop()
    await self.session_service.stop()


@agent_app.query(framework="agentscope")
async def query_func(
    self,
    msgs,
    request: AgentRequest = None,
    **kwargs,
):
    session_id = request.session_id
    user_id = request.user_id

    state = await self.state_service.export_state(
        session_id=session_id,
        user_id=user_id,
    )

    toolkit = Toolkit()
    toolkit.register_tool_function(execute_python_code)

    agent = ReActAgent(
        name="Friday",
        model=DashScopeChatModel(
            "qwen-turbo",
            api_key=os.getenv("DASHSCOPE_API_KEY"),
            stream=True,
        ),
        sys_prompt="You're a helpful assistant named Friday.",
        toolkit=toolkit,
        memory=AgentScopeSessionHistoryMemory(
            service=self.session_service,
            session_id=session_id,
            user_id=user_id,
        ),
        formatter=DashScopeChatFormatter(),
    )
    agent.set_console_output_enabled(enabled=False)

    if state:
        agent.load_state_dict(state)

    async for msg, last in stream_printing_messages(
        agents=[agent],
        coroutine_task=agent(msgs),
    ):
        yield msg, last

    state = agent.state_dict()

    await self.state_service.save_state(
        user_id=user_id,
        session_id=session_id,
        state=state,
    )


agent_app.run(host="127.0.0.1", port=8090)

The server will start and listen on: http://localhost:8090/process. You can send JSON input to the API using curl:

curl -N \
  -X POST "http://localhost:8090/process" \
  -H "Content-Type: application/json" \
  -d '{
    "input": [
      {
        "role": "user",
        "content": [
          { "type": "text", "text": "What is the capital of France?" }
        ]
      }
    ]
  }'

Youโ€™ll see output streamed in Server-Sent Events (SSE) format:

data: {"sequence_number":0,"object":"response","status":"created", ... }
data: {"sequence_number":1,"object":"response","status":"in_progress", ... }
data: {"sequence_number":2,"object":"message","status":"in_progress", ... }
data: {"sequence_number":3,"object":"content","status":"in_progress","text":"The" }
data: {"sequence_number":4,"object":"content","status":"in_progress","text":" capital of France is Paris." }
data: {"sequence_number":5,"object":"message","status":"completed","text":"The capital of France is Paris." }
data: {"sequence_number":6,"object":"response","status":"completed", ... }

Sandbox Example

These examples demonstrate how to create sandboxed environments and execute tools within them, with some examples featuring interactive frontend interfaces accessible via VNC (Virtual Network Computing):

[!NOTE]

Current version requires Docker or Kubernetes to be installed and running on your system. Please refer to this tutorial for more details.

If you plan to use the sandbox on a large scale in production, we recommend deploying it directly in Alibaba Cloud for managed hosting: One-click deploy sandbox on Alibaba Cloud

Base Sandbox

Use for running Python code or shell commands in an isolated environment.

from agentscope_runtime.sandbox import BaseSandbox

with BaseSandbox() as box:
    # By default, pulls `agentscope/runtime-sandbox-base:latest` from DockerHub
    print(box.list_tools()) # List all available tools
    print(box.run_ipython_cell(code="print('hi')"))  # Run Python code
    print(box.run_shell_command(command="echo hello"))  # Run shell command
    input("Press Enter to continue...")

GUI Sandbox

Provides a virtual desktop environment for mouse, keyboard, and screen operations.

GUI Sandbox
from agentscope_runtime.sandbox import GuiSandbox

with GuiSandbox() as box:
    # By default, pulls `agentscope/runtime-sandbox-gui:latest` from DockerHub
    print(box.list_tools()) # List all available tools
    print(box.desktop_url)  # Web desktop access URL
    print(box.computer_use(action="get_cursor_position"))  # Get mouse cursor position
    print(box.computer_use(action="get_screenshot"))       # Capture screenshot
    input("Press Enter to continue...")

Browser Sandbox

A GUI-based sandbox with browser operations inside an isolated sandbox.

GUI Sandbox
from agentscope_runtime.sandbox import BrowserSandbox

with BrowserSandbox() as box:
    # By default, pulls `agentscope/runtime-sandbox-browser:latest` from DockerHub
    print(box.list_tools()) # List all available tools
    print(box.desktop_url)  # Web desktop access URL
    box.browser_navigate("https://www.google.com/")  # Open a webpage
    input("Press Enter to continue...")

Filesystem Sandbox

A GUI-based sandbox with file system operations such as creating, reading, and deleting files.

GUI Sandbox
from agentscope_runtime.sandbox import FilesystemSandbox

with FilesystemSandbox() as box:
    # By default, pulls `agentscope/runtime-sandbox-filesystem:latest` from DockerHub
    print(box.list_tools()) # List all available tools
    print(box.desktop_url)  # Web desktop access URL
    box.create_directory("test")  # Create a directory
    input("Press Enter to continue...")

Mobile Sandbox

Provides a sandboxed Android emulator environment that allows executing various mobile operations, such as tapping, swiping, inputting text, and taking screenshots.

Mobile Sandbox
Prerequisites
  • Linux Host: When running on a Linux host, this sandbox requires the binder and ashmem kernel modules to be loaded. If they are missing, execute the following commands on your host to install and load the required modules:

    # 1. Install extra kernel modules
    sudo apt update && sudo apt install -y linux-modules-extra-`uname -r`
    
    # 2. Load modules and create device nodes
    sudo modprobe binder_linux devices="binder,hwbinder,vndbinder"
    sudo modprobe ashmem_linux
    
  • Architecture Compatibility: When running on an ARM64/aarch64 architecture (e.g., Apple M-series chips), you may encounter compatibility or performance issues. It is recommended to run on an x86_64 host.

from agentscope_runtime.sandbox import MobileSandbox

with MobileSandbox() as box:
    # By default, pulls 'agentscope/runtime-sandbox-mobile:latest' from DockerHub
    print(box.list_tools()) # List all available tools
    print(box.mobile_get_screen_resolution()) # Get the screen resolution
    print(box.mobile_tap([500, 1000])) # Tap at coordinate (500, 1000)
    print(box.mobile_input_text("Hello from AgentScope!")) # Input text
    print(box.mobile_key_event(3)) # Sends a HOME key event (KeyCode: 3)
    screenshot_result = box.mobile_get_screenshot() # Get the current screenshot
    input("Press Enter to continue...")

[!NOTE]

To add tools to the AgentScope Toolkit:

  1. Wrap sandbox tool with sandbox_tool_adapter, so the AgentScope agent can call them:

    from agentscope_runtime.adapters.agentscope.tool import sandbox_tool_adapter
    
    wrapped_tool = sandbox_tool_adapter(sandbox.browser_navigate)
    
  2. Register the tool with register_tool_function:

    toolkit = Toolkit()
    Toolkit.register_tool_function(wrapped_tool)
    

Configuring Sandbox Image Registry, Namespace, and Tag

1. Registry

If pulling images from DockerHub fails (for example, due to network restrictions), you can switch the image source to Alibaba Cloud Container Registry for faster access:

export RUNTIME_SANDBOX_REGISTRY="agentscope-registry.ap-southeast-1.cr.aliyuncs.com"
2. Namespace

A namespace is used to distinguish images of different teams or projects. You can customize the namespace via an environment variable:

export RUNTIME_SANDBOX_IMAGE_NAMESPACE="agentscope"

For example, here agentscope will be used as part of the image path.

3. Tag

An image tag specifies the version of the image, for example:

export RUNTIME_SANDBOX_IMAGE_TAG="preview"

Details:

  • Default is latest, which means the image version matches the PyPI latest release.
  • preview means the latest preview version built in sync with the GitHub main branch.
  • You can also use a specified version number such as 20250909. You can check all available image versions at DockerHub.
4. Complete Image Path

The sandbox SDK will build the full image path based on the above environment variables:

<RUNTIME_SANDBOX_REGISTRY>/<RUNTIME_SANDBOX_IMAGE_NAMESPACE>/runtime-sandbox-base:<RUNTIME_SANDBOX_IMAGE_TAG>

Example:

agentscope-registry.ap-southeast-1.cr.aliyuncs.com/agentscope/runtime-sandbox-base:preview

Serverless Sandbox Deployment

AgentScope Runtime also supports serverless deployment, which is suitable for running sandboxes in a serverless environment, Alibaba Cloud Function Compute (FC) or Alibaba Cloud AgentRun.

First, please refer to the documentation to configure the serverless environment variables. Make CONTAINER_DEPLOYMENT to fc or agentrun to enable serverless deployment.

Then, start a sandbox server, use the --config option to specify a serverless environment setup:

# This command will load the settings defined in the `custom.env` file
runtime-sandbox-server --config fc.env

After the server starts, you can access the sandbox server at baseurl http://localhost:8000 and invoke sandbox tools described above.

๐Ÿ“š Cookbook


๐Ÿ—๏ธ Deployment

The AgentApp exposes a deploy method that takes a DeployManager instance and deploys the agent.

  • The service port is set as the parameter port when creating the LocalDeployManager.

  • The service endpoint path is set as the parameter endpoint_path to /process when deploying the agent.

  • The deployer will automatically add common agent protocols, such as A2A, Response API.

After deployment, users can access the service at `http://localhost:8090/process:

from agentscope_runtime.engine.deployers import LocalDeployManager

# Create deployment manager
deployer = LocalDeployManager(
    host="0.0.0.0",
    port=8090,
)

# Deploy the app as a streaming service
deploy_result = await app.deploy(deployer=deployer)

After deployment, users can also access this service using the Response API of the OpenAI SDK:

from openai import OpenAI

client = OpenAI(base_url="http://0.0.0.0:8090/compatible-mode/v1")

response = client.responses.create(
  model="any_name",
  input="What is the weather in Beijing?"
)

print(response)

Besides, DeployManager also supports serverless deployments, such as deploying your agent app to ModelStudio or AgentRun.

from agentscope_runtime.engine.deployers import ModelStudioDeployManager
# Create deployment manager
deployer = ModelstudioDeployManager(
    oss_config=OSSConfig(
        access_key_id=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_ID"),
        access_key_secret=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
    ),
    modelstudio_config=ModelstudioConfig(
        workspace_id=os.environ.get("MODELSTUDIO_WORKSPACE_ID"),
        access_key_id=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_ID"),
        access_key_secret=os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
        dashscope_api_key=os.environ.get("DASHSCOPE_API_KEY"),
    ),
)

# Deploy to ModelStudio
result = await app.deploy(
    deployer,
    deploy_name="agent-app-example",
    telemetry_enabled=True,
    requirements=["agentscope", "fastapi", "uvicorn"],
    environment={
        "PYTHONPATH": "/app",
        "DASHSCOPE_API_KEY": os.environ.get("DASHSCOPE_API_KEY"),
    },
)

For more advanced serverless deployment guides, please refer to the documentation.


๐Ÿค Contributing

We welcome contributions from the community! Here's how you can help:

๐Ÿ› Bug Reports

  • Use GitHub Issues to report bugs
  • Include detailed reproduction steps
  • Provide system information and logs

๐Ÿ’ก Feature Requests

  • Discuss new ideas in GitHub Discussions
  • Follow the feature request template
  • Consider implementation feasibility

๐Ÿ”ง Code Contributions

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

For detailed contributing guidelines, please see CONTRIBUTE.


๐Ÿ“„ License

AgentScope Runtime is released under the Apache License 2.0.

Copyright 2025 Tongyi Lab

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Contributors โœจ

All Contributors

Thanks goes to these wonderful people (emoji key):

Weirui Kuang
Weirui Kuang

๐Ÿ’ป ๐Ÿ‘€ ๐Ÿšง ๐Ÿ“†
Bruce Luo
Bruce Luo

๐Ÿ’ป ๐Ÿ‘€ ๐Ÿ’ก
Zhicheng Zhang
Zhicheng Zhang

๐Ÿ’ป ๐Ÿ‘€ ๐Ÿ“–
ericczq
ericczq

๐Ÿ’ป ๐Ÿ“–
qbc
qbc

๐Ÿ‘€
Ran Chen
Ran Chen

๐Ÿ’ป
jinliyl
jinliyl

๐Ÿ’ป ๐Ÿ“–
Osier-Yi
Osier-Yi

๐Ÿ’ป ๐Ÿ“–
Kevin Lin
Kevin Lin

๐Ÿ’ป
DavdGao
DavdGao

๐Ÿ‘€
FlyLeaf
FlyLeaf

๐Ÿ’ป ๐Ÿ“–
jinghuan-Chen
jinghuan-Chen

๐Ÿ’ป
Yuxuan Wu
Yuxuan Wu

๐Ÿ’ป ๐Ÿ“–
Fear1es5
Fear1es5

๐Ÿ›
zhiyong
zhiyong

๐Ÿ’ป ๐Ÿ›
jooojo
jooojo

๐Ÿ’ป ๐Ÿ›
Zheng Dayu
Zheng Dayu

๐Ÿ’ป ๐Ÿ›
quanyu
quanyu

๐Ÿ’ป
Grace Wu
Grace Wu

๐Ÿ’ป ๐Ÿ“–
LiangQuan
LiangQuan

๐Ÿ’ป
ls
ls

๐Ÿ’ป ๐ŸŽจ
iSample
iSample

๐Ÿ’ป ๐Ÿ“–
XiuShenAl
XiuShenAl

๐Ÿ’ป ๐Ÿ“–
Farruh Kushnazarov
Farruh Kushnazarov

๐Ÿ“–
fengxsong
fengxsong

๐Ÿ›
Wang
Wang

๐Ÿ’ป ๐Ÿ›
Add your contributions

This project follows the all-contributors specification. Contributions of any kind welcome!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agentscope_runtime-1.0.2.tar.gz (398.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agentscope_runtime-1.0.2-py3-none-any.whl (514.1 kB view details)

Uploaded Python 3

File details

Details for the file agentscope_runtime-1.0.2.tar.gz.

File metadata

  • Download URL: agentscope_runtime-1.0.2.tar.gz
  • Upload date:
  • Size: 398.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for agentscope_runtime-1.0.2.tar.gz
Algorithm Hash digest
SHA256 0e4449e967f892f4f8b3b9e8b28d87b98aab2cd1c8e79a2de9e924c67a27a824
MD5 1ae46c33e1117140a21e61052b41d972
BLAKE2b-256 a3caa763dcd459640e9541143b72182ddee1a4336453770caeef6cc24fe6bbd2

See more details on using hashes here.

File details

Details for the file agentscope_runtime-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for agentscope_runtime-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 637090b4898874f12c28aab91f9b594d605dd34cfd0cbd716e1baa2289b8ee5a
MD5 3458bcb062bdef352635515adf950c0a
BLAKE2b-256 7dfb3bbe7708edb11e6028ec8465b2875730c7e869a7cb58ef0c5c3fbced0f46

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page