Access the AgentScope (Java) application

Updated at:

Cloud Monitor 2.0 LLM observability uses a Java Agent to collect observability data from AgentScope Java applications. Based on the OpenTelemetry standard, the Java Agent automatically instruments your application and reports trace data to Cloud Monitor 2.0. After the integration, you can monitor the running status of your AI application in real time.

Framework introduction

AgentScope is an open source multi-agent application development framework from Alibaba. It provides agent types such as ReActAgent, includes built-in model adapters such as DashScope, and supports tool calling, memory management, and multi-agent collaboration. AgentScope Java is the Java implementation of the framework and lets you build LLM applications in the JVM ecosystem.

Data collected

After you integrate your AgentScope Java application with Cloud Monitor 2.0, automatic monitoring covers the following data:

  • Agent execution traces.

  • Model calls, including the token usage and the input and output content of each large language model call.

  • Tool calls, including the call details of each tool registered in the Toolkit.

  • ReAct steps, including the action and the observation of each round.

Prerequisites

  • JDK 17 or later is installed to run the AgentScope Java application.

  • The maximum heap memory of the target JVM is greater than 300 MB.

  • Cloud Monitor 2.0 is activated and a workspace is created.

Integration procedure

Get the integration parameters from the Cloud Monitor 2.0 console, and then install the Java Agent for your AgentScope Java application.

Get the integration parameters

  1. Log on to the Cloud Monitor 2.0 console and select the target workspace.

  2. In the left-side navigation pane, click Integration Center.

  3. In the AI application observability section, select the AgentScope Java integration.

  4. Enter an application name, select the connection type that matches your deployment environment, and then obtain the LicenseKey.

    Record the following parameters:

Parameter

Description

LicenseKey

The key that authenticates data writes to Cloud Monitor 2.0.

Workspace

The identifier of the Cloud Monitor 2.0 workspace.

RegionId

The region that the application reports data to, for example, cn-hangzhou.

Application name

The name under which the application appears in Cloud Monitor 2.0.

Install the Java Agent

Select the tab that matches your deployment environment and follow the steps to install the Java Agent and report data to Cloud Monitor 2.0:

Container Service for Kubernetes (ACK) and Container Compute Service (ACS)

ack-onepilot component

The Application Monitoring agent installation assistant (ack-onepilot) is an essential component for integrating agents for various programming languages. It automatically prepares the Application Monitoring agent package and configures the agent's reporting environment within your containers. For more information about how ack-onepilot works, see How the ack-onepilot component works.

To ensure a smooth experience, ack-onepilot automatically upgrades the mounted agent to the latest version when your application restarts and a new agent version is available. If you prefer to manage the agent version yourself instead of using automatic updates, you can control the agent version. For more information, see Control the agent version.

Step 1: Install the ack-onepilot component

  1. Log on to the ACK console. On the Clusters page, click the name of the cluster.

  2. In the navigation pane on the left, click Add-ons, then locate ack-onepilot.

    Important

    The ack-onepilot version must be 5.1.0 or later.

  3. Click Install on the ack-onepilot card.

    Note
    • By default, the ack-onepilot component supports 1,000 pods. For every additional 1,000 pods in the cluster, you must add 0.5 CPU cores and 512 MB memory for the component.

    • If you install ack-onepilot in an ACS cluster, configure accessKey and accessKeySecret at the bottom of the installation card. Use the AccessKey ID and AccessKey secret of your Alibaba Cloud account. For information about how to obtain them, see Create an AccessKey. Make sure that the Alibaba Cloud account has the AliyunARMSFullAccess and AliyunSTSAssumeRoleAccess permissions.

  4. On the page that appears, you can configure the parameters. We recommend that you use the default values. Click OK.

    Note

    After you install ack-onepilot, you can upgrade, configure, or uninstall it on the Add-ons page.

Step 2: Grant ARMS permissions

ACK managed cluster

If your ACK managed cluster lacks an ARMS Addon Token, you must manually grant permissions to access ARMS resources. Otherwise, skip to Step 3.

Check whether ARMS Addon Token exists in a cluster.

  1. Log on to the ACK console. On the Clusters page, click the name of the cluster to go to the cluster details page.

  2. In the left-side navigation pane, choose Configurations > Secrets. In the upper part of the page, set Namespace to kube-system and check whether addon.arms.token exists.

Note

If a cluster has ARMS Addon Token, ARMS performs password-free authorization on the cluster. ARMS Addon Token may not exist in some ACK managed clusters. We recommend that you check whether an ACK managed cluster has ARMS Addon Token before you use ARMS to monitor applications in the cluster. If the cluster has no ARMS Addon Token, you must authorize the cluster to access ARMS.

Manually add permission policies

  1. Log on to the ACK console. On the Clusters page, click the name of the cluster.

  2. On the Basic Information tab of the Cluster Information page, click the link next to Worker RAM Role in the Cluster Resources section.

  3. On the Permissions tab, click Grant Permission.

  4. In the Grant Permission panel, add the following two access policies and click Confirm Grant Permission.

    • AliyunTracingAnalysisFullAccess: full access to Managed Service for OpenTelemetry.

    • AliyunARMSFullAccess: full access to ARMS.

ACK dedicated and registered clusters

To monitor applications in an ACK dedicated cluster or an ACK One registered cluster, ensure that the corresponding Alibaba Cloud account has the AliyunARMSFullAccess and AliyunSTSAssumeRoleAccess permissions. For information about how to add permissions, see Manage RAM user permissions.

After installing the ack-onepilot component, you must also provide an AccessKey pair with the required ARMS permissions to the component.

Method 1: Provide AccessKeys in Helm
  1. Log on to the ACK console. In the left navigation pane, click Clusters.

  2. On the Clusters page, click the name of the target cluster. In the navigation pane on the left, choose Applications > Helm. Next to the ack-onepilot component, click Update.

  3. Replace accessKey and accessKeySecret with your AccessKey ID and AccessKey Secret, then click OK.

    Note

    For information about how to obtain an AccessKey pair, see Create an AccessKey pair.

    image

  4. Restart the application deployment.

Method 2: Import AccessKeys with a secret
  1. Log on to the Container Service for Kubernetes console. In the navigation pane on the left, select Clusters.

  2. On the Clusters page, click the name of the target cluster. In the navigation pane on the left, choose Configurations > Secrets.

  3. Select the ack-onepilot namespace, create a secret, and add your AccessKey pair.

    Note

    For information about how to obtain an AccessKey pair, see Create an AccessKey pair.

    image

  4. In the navigation pane on the left, choose Workloads > Deployments. Click the ack-onepilot component, which is typically named ack-onepilot-ack-onepilot and located in the ack-onepilot namespace.

  5. On the details page of the component, click Edit in the upper-right corner. In the Environment Variables section, add ONE_PILOT_ACCESSKEY and ONE_PILOT_ACCESSKEY_SECRET. Configure them to reference the secret's values, then click OK.

    image

ASK/ECI cluster

To monitor applications in an ACK Serverless cluster or a cluster that is integrated with Elastic Container Instance (ECI), go to the Cloud Resource Access Authorization page to grant permissions. Then, restart all pods of the ack-onepilot component.

Step 3: Enable Application Monitoring for Java applications

The following YAML example shows how to create a Deployment with Application Monitoring enabled:

Expand to view the complete sample YAML file (Java)

apiVersion: v1
kind: Namespace
metadata:
  name: arms-demo
---
apiVersion: apps/v1 # for versions before 1.8.0 use apps/v1beta1
kind: Deployment
metadata:
  name: arms-springboot-demo
  namespace: arms-demo
  labels:
    app: arms-springboot-demo
spec:
  replicas: 2
  selector:
    matchLabels:
      app: arms-springboot-demo
  template:
    metadata:
      labels:
        app: arms-springboot-demo
        armsPilotAutoEnable: "on"
        armsPilotCreateAppName: "arms-k8s-demo"
        armsPilotAppWorkspace: "workspace"   # Replace with the name of your workspace.
        one-agent.jdk.version: "OpenJDK18"
    spec:
      containers:
        - resources:
            limits:
              cpu: 0.5
          image: registry.cn-hangzhou.aliyuncs.com/arms-docker-repo/arms-springboot-demo:v0.1
          imagePullPolicy: Always
          name: arms-springboot-demo
          env:
            - name: SELF_INVOKE_SWITCH
              value: "true"
            - name: COMPONENT_HOST
              value: "arms-demo-component"
            - name: COMPONENT_PORT
              value: "6666"
            - name: MYSQL_SERVICE_HOST
              value: "arms-demo-mysql"
            - name: MYSQL_SERVICE_PORT
              value: "3306"
---
apiVersion: apps/v1 # for versions before 1.8.0 use apps/v1beta1
kind: Deployment
metadata:
  name: arms-springboot-demo-subcomponent
  namespace: arms-demo
  labels:
    app: arms-springboot-demo-subcomponent
spec:
  replicas: 2
  selector:
    matchLabels:
      app: arms-springboot-demo-subcomponent
  template:
    metadata:
      labels:
        app: arms-springboot-demo-subcomponent
        armsPilotAutoEnable: "on"
        armsPilotCreateAppName: "arms-k8s-demo-subcomponent"
        armsPilotAppWorkspace: "workspace"   # Replace with the name of your workspace.
        one-agent.jdk.version: "OpenJDK18"
    spec:
      containers:
        - resources:
            limits:
              cpu: 0.5
          image: registry.cn-hangzhou.aliyuncs.com/arms-docker-repo/arms-springboot-demo:v0.1
          imagePullPolicy: Always
          name: arms-springboot-demo-subcomponent
          env:
            - name: SELF_INVOKE_SWITCH
              value: "false"
            - name: MYSQL_SERVICE_HOST
              value: "arms-demo-mysql"
            - name: MYSQL_SERVICE_PORT
              value: "3306"
---
apiVersion: v1
kind: Service
metadata:
  labels:
    name: arms-demo-component
  name: arms-demo-component
  namespace: arms-demo
spec:
  ports:
    - name: arms-demo-component-svc
      port: 6666
      targetPort: 8888
  selector:
    app: arms-springboot-demo-subcomponent
---
apiVersion: apps/v1 # for versions before 1.8.0 use apps/v1beta1
kind: Deployment
metadata:
  name: arms-demo-mysql
  namespace: arms-demo
  labels:
    app: mysql
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
        - resources:
            limits:
              cpu: 0.5
          image: registry.cn-hangzhou.aliyuncs.com/arms-docker-repo/arms-demo-mysql:v0.1
          name: mysql
          ports:
            - containerPort: 3306
              name: mysql
---
apiVersion: v1
kind: Service
metadata:
  labels:
    name: mysql
  name: arms-demo-mysql
  namespace: arms-demo
spec:
  ports:
    - name: arms-mysql-svc
      port: 3306
      targetPort: 3306
  selector:
    app: mysql
---
  1. Log on to the ACK console. In the left navigation pane, click Clusters.

  2. On the Clusters page, click the name of your cluster. In the left navigation pane, click Workloads > Deployments.

  3. On the Stateless page, click more icon > YAML Edit next to the target application. To create an application, click Create from YAML.

  4. In the YAML file, add the following labels to the spec.template.metadata section.

    labels:
      armsPilotAutoEnable: "on"
      armsPilotCreateAppName: "deployment-name"    # Replace deployment-name with the name of your application.
      armsPilotAppWorkspace: "workspace"  # Replace with the name of your workspace.
      aliyun.com/app-language: java
    apiVersion: v1
    kind: Namespace
    metadata:
      name: arms-demo
    ---
    apiVersion: apps/v1 # for versions before 1.8.0 use apps/v1beta1
    kind: Deployment
    metadata:
      name: arms-springboot-demo
      namespace: arms-demo
      labels:
        app: arms-springboot-demo
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: arms-springboot-demo
      template:
        metadata:
          labels:
            app: arms-springboot-demo
            armsPilotAutoEnable: "on"
            armsPilotCreateAppName: "arms-k8s-demo"
            armsPilotAppWorkspace: "workspace"
        spec:
          containers:
            - resources:
                limits:
                  cpu: 0.5
              image: registry.cn-hangzhou.aliyuncs.com/arms-docker-repo/arms-springboot-demo:v0.1
  5. Click Update.

Manual installation

Install the agent

  1. Log on to the Cloud Monitor 2.0 console, and select a workspace. In the left navigation pane, click Integration Center.

  2. Click the Java Application Monitor card and then click Manual Installation.

  3. Download the agent package using one of the following methods:

    • From the console -- In the Java Application Monitor panel, follow the download prompts.

    • From the command line -- Run the wget command for your region. Select your region from the table below.

    wget commands by region

    Region

    Public endpoint

    VPC endpoint

    China (Hangzhou)

    wget "http://arms-apm-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    wget "http://arms-apm-cn-hangzhou.oss-cn-hangzhou-internal.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    China (Shanghai)

    wget "http://arms-apm-cn-shanghai.oss-cn-shanghai.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    wget "http://arms-apm-cn-shanghai.oss-cn-shanghai-internal.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    China (Qingdao)

    wget "http://arms-apm-cn-qingdao.oss-cn-qingdao.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    wget "http://arms-apm-cn-qingdao.oss-cn-qingdao-internal.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    China (Beijing)

    wget "http://arms-apm-cn-beijing.oss-cn-beijing.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    wget "http://arms-apm-cn-beijing.oss-cn-beijing-internal.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    China (Zhangjiakou)

    wget "http://arms-apm-cn-zhangjiakou.oss-cn-zhangjiakou.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    wget "http://arms-apm-cn-zhangjiakou.oss-cn-zhangjiakou-internal.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    China (Hohhot)

    wget "http://arms-apm-cn-huhehaote.oss-cn-huhehaote.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    wget "http://arms-apm-cn-huhehaote.oss-cn-huhehaote-internal.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    China (Ulanqab)

    wget "http://arms-apm-cn-wulanchabu.oss-cn-wulanchabu.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    wget "http://arms-apm-cn-wulanchabu.oss-cn-wulanchabu-internal.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    China (Shenzhen)

    wget "http://arms-apm-cn-shenzhen.oss-cn-shenzhen.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    wget "http://arms-apm-cn-shenzhen.oss-cn-shenzhen-internal.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    China (Heyuan)

    wget "http://arms-apm-cn-heyuan.oss-cn-heyuan.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    wget "http://arms-apm-cn-heyuan.oss-cn-heyuan-internal.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    China (Guangzhou)

    wget "http://arms-apm-cn-guangzhou.oss-cn-guangzhou.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    wget "http://arms-apm-cn-guangzhou.oss-cn-guangzhou-internal.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    China (Chengdu)

    wget "http://arms-apm-cn-chengdu.oss-cn-chengdu.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    wget "http://arms-apm-cn-chengdu.oss-cn-chengdu-internal.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    China (Hong Kong)

    wget "http://arms-apm-cn-hongkong.oss-cn-hongkong.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    wget "http://arms-apm-cn-hongkong.oss-cn-hongkong-internal.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    Singapore

    wget "http://arms-apm-ap-southeast-1.oss-ap-southeast-1.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    wget "http://arms-apm-ap-southeast-1.oss-ap-southeast-1-internal.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    Malaysia (Kuala Lumpur)

    wget "http://arms-apm-ap-southeast-3.oss-ap-southeast-3.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    wget "http://arms-apm-ap-southeast-3.oss-ap-southeast-3-internal.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    Indonesia (Jakarta)

    wget "http://arms-apm-ap-southeast-5.oss-ap-southeast-5.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    wget "http://arms-apm-ap-southeast-5.oss-ap-southeast-5-internal.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    Japan (Tokyo)

    wget "http://arms-apm-ap-northeast-1.oss-ap-northeast-1.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    wget "http://arms-apm-ap-northeast-1.oss-ap-northeast-1-internal.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    Germany (Frankfurt)

    wget "http://arms-apm-eu-central-1.oss-eu-central-1.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    wget "http://arms-apm-eu-central-1.oss-eu-central-1-internal.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    UK (London)

    wget "http://arms-apm-eu-west-1.oss-eu-west-1.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    wget "http://arms-apm-eu-west-1.oss-eu-west-1-internal.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    US (Virginia)

    wget "http://arms-apm-us-east-1.oss-us-east-1.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    wget "http://arms-apm-us-east-1.oss-us-east-1-internal.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    US (Silicon Valley)

    wget "http://arms-apm-us-west-1.oss-us-west-1.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    wget "http://arms-apm-us-west-1.oss-us-west-1-internal.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    SAU (Riyadh - Partner Region)

    wget "http://arms-apm-me-central-1.oss-me-central-1.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

    wget "http://arms-apm-me-central-1.oss-me-central-1-internal.aliyuncs.com/AliyunJavaAgent.zip" -O AliyunJavaAgent.zip

  4. Extract the downloaded ZIP file to a working directory:

    unzip AliyunJavaAgent.zip -d <working-directory>

    Replace <working-directory> with the directory where you want to install the agent.

  5. Add the AppName and LicenseKey parameters.

    On the Java Application Monitoring panel, obtain the LicenseKey. The AppName parameter specifies the application in ARMS to connect to. You can customize the application name. In a distributed architecture, an application can contain multiple peer instances.

    Important

    The LicenseKey is specific to each workspace. You must obtain a new LicenseKey for a new workspace.

    You can add the AppName and LicenseKey in one of the following ways.

    • Method 1 (Recommended): In the startup script, replace {LicenseKey} and {AppName} with the LicenseKey that you obtained from the console and the AppName of your application.

    • Method 2: If you want to reuse the startup script for different applications, you can specify the LicenseKey and AppName by modifying the agent configuration file. To do this, perform the following steps:

      Note

      For agent versions earlier than 4.4.0, this method connects the application to the default workspace.

      1. In the version file that you unzipped in the previous step, check the Java agent version.

      2. Modify the agent configuration file.

        Agents of version 4.0.0 and later

        In the agent directory, create a file named arms-agent.properties and add the following configurations. Then, add -Dotel.javaagent.configuration-file=/path/to/arms-agent.properties to the startup command or add the OTEL_JAVAAGENT_CONFIGURATION_FILE=/path/to/arms-agent.properties environment variable to enable the configuration file.

        arms.licenseKey={LicenseKey} 
        arms.appName={AppName}

        Agents earlier than version 4.0.0

        In the arms-agent.config file within the agent package, add the following configurations.

        arms.licenseKey={LicenseKey} 
        arms.appName={AppName}
        Note

        For more information about other configuration items in the agent configuration file, see Modify the Java agent configuration file and the default reporting region.

  6. Add the connection command to the startup command.

    Replace {user.workspace} with the directory where you unzipped the agent installation package. Replace demoApp.jar with the actual path of your JAR package.

    Note
    • If you are using an agent version earlier than 2.7.3.5, replace AliyunJavaAgent/aliyun-java-agent.jar in this topic with ArmsAgent/arms-bootstrap-1.7.0-SNAPSHOT.jar. We recommend that you upgrade the agent to the latest version as soon as possible.

    • On a Windows operating system, replace / with \ and replace the .sh file extension with .bat in the script.

    • Agents of V2.7.1.4 and later support application security. To enable application security when you connect to Application Monitoring, add -Darms.appsec.enable=true to the script. For more information about the billing rules for application security, see Billing.

    Runtime environment

    Steps

    Spring Boot or other Java applications that are started using the java -jar command

    Add the -javaagent parameter to the startup command. Make sure that the -javaagent parameter is placed before the -jar parameter.

    java -javaagent:/{user.workspace}/AliyunJavaAgent/aliyun-java-agent.jar -Darms.licenseKey={LicenseKey} -Darms.appName={AppName} -Darms.workspace={workspace} -jar demoApp.jar

    Tomcat

    Add the following configuration to the {TOMCAT_HOME}/bin/setenv.sh file.

    JAVA_OPTS="$JAVA_OPTS -javaagent:/{user.workspace}/AliyunJavaAgent/aliyun-java-agent.jar -Darms.licenseKey={LicenseKey} -Darms.appName={AppName} -Darms.workspace={workspace} " 

    If your Tomcat version does not have the setenv.sh configuration file, open the {TOMCAT_HOME}/bin/catalina.sh file and add the preceding configuration after JAVA_OPTS. For an example, see line 256 of catalina.sh.

    Jetty

    Add the following configuration to the {JETTY_HOME}/start.ini configuration file.

    aliyun-java-agent.jar --exec
    -javaagent:/{user.workspace}/AliyunJavaAgent/aliyun-java-agent.jar
    -Darms.licenseKey={LicenseKey}
    -Darms.appName={AppName} 
    -Darms.workspace={workspace} 

    To deploy multiple instances of the same application on a single server, use the -Darms.agentId parameter (a logical ID) to differentiate JVM processes. For example:

    java -javaagent:/{user.workspace}/AliyunJavaAgent/aliyun-java-agent.jar -Darms.licenseKey={LicenseKey} -Darms.appName={AppName} -Darms.workspace={workspace} -Darms.agentId=001 -jar demoApp.jar
  7. Restart the Java application.

Sample code

The following example uses AgentScope Java 2.0.1 to build a minimal runnable agent. The agent performs one model call and one tool call. Before you run the example, install JDK 17 or later and set the DASHSCOPE_API_KEY environment variable.

Add the Maven dependencies

Add the AgentScope Java 2.0.1 dependencies to the pom.xml file of your Maven project. Add agentscope-core for basic capabilities such as ReActAgent, add agentscope-harness if you need Harness capabilities, and add agentscope-extensions-model-dashscope to call models through DashScope:

<dependencies>
  <dependency>
    <groupId>io.agentscope</groupId>
    <artifactId>agentscope-core</artifactId>
    <version>2.0.1</version>
  </dependency>
  <dependency>
    <groupId>io.agentscope</groupId>
    <artifactId>agentscope-extensions-model-dashscope</artifactId>
    <version>2.0.1</version>
  </dependency>
  <!-- Add this dependency if you need Harness capabilities -->
  <dependency>
    <groupId>io.agentscope</groupId>
    <artifactId>agentscope-harness</artifactId>
    <version>2.0.1</version>
  </dependency>
</dependencies>

Create a minimal agent

Write a minimal agent that calls a tool. Import the DashScopeChatModel model adapter from io.agentscope.extensions.model.dashscope, and register the tool through the Toolkit:

import io.agentscope.core.agent.ReActAgent;
import io.agentscope.core.message.Msg;
import io.agentscope.core.message.MsgRole;
import io.agentscope.core.message.TextBlock;
import io.agentscope.core.tool.Toolkit;
import io.agentscope.core.tool.Tool;
import io.agentscope.core.tool.ToolParam;
import io.agentscope.extensions.model.dashscope.DashScopeChatModel;

public class QuickStart {
    public static void main(String[] args) {
        Toolkit toolkit = new Toolkit();
        toolkit.registerTool(new SimpleTools());

        DashScopeChatModel model = DashScopeChatModel.builder()
            .apiKey(System.getenv("DASHSCOPE_API_KEY"))
            .modelName("qwen-plus")
            .build();

        ReActAgent agent = ReActAgent.builder()
            .name("TravelAgent")
            .sysPrompt("You are a travel assistant. Use tools when needed.")
            .model(model)
            .toolkit(toolkit)
            .build();

        Msg msg = Msg.builder()
            .role(MsgRole.USER)
            .content(TextBlock.builder()
                .text("What time is it in Hangzhou? Give me one travel tip.")
                .build())
            .build();

        Msg response = agent.call(msg).block();
        System.out.println(response.getTextContent());
    }
}

class SimpleTools {
    @Tool(name = "get_time", description = "Get current local time")
    public String getTime(
            @ToolParam(name = "city", description = "City name") String city) {
        return city + ": " + java.time.LocalDateTime.now()
            .format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
    }
}

Verify the integration

After you run the application, go to the AI application observability page in the Cloud Monitor 2.0 console. You should see at least one trace that contains AGENT, LLM, and TOOL spans. For more information, see the View monitoring details section.

View monitoring details

  1. In the Cloud Monitor 2.0 console, select the target workspace. In the left-side navigation pane, choose All features > AI application observability.

  2. On the AI application list page, find the integrated AgentScope Java application and click the application name to go to the details page, where you can view the trace details of the application.

    On the application details page, you can view the following trace information:

  • Overview: the trace ID, start time, total duration, and total tokens.

  • Trace timeline: the complete agent call chain and the duration of each span, organized by span hierarchy.

  • Span type filter: filter spans by AGENT, STEP, LLM, or TOOL to locate a node.

  • Span details: click a span to view its information in the panel on the right. For example, an LLM span shows Input Messages, which contains the system prompt and the user question, and Output Messages, which contains the model response and the tool call details.

Span type

Description

AGENT

The root span, which covers the agent execution.

STEP

One round of the ReAct loop.

LLM

A model call, including the input and output token counts.

TOOL

A tool call, for example, get_time.

References

  • AgentScope Java official documentation: the API reference and more usage notes of AgentScope Java 2.0.1.

  • Java Agent troubleshooting: how to troubleshoot exceptions that occur during Java Agent integration or data reporting.

  • For the Java Agent installation topics for ACK and ACS clusters and for other environments, see the Integration procedure section.