Access the AgentScope (Java) application
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.ReActsteps, including the action and the observation of each round.
Prerequisites
JDK 17 or later is installed to run the
AgentScopeJava 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
Log on to the Cloud Monitor 2.0 console and select the target workspace.
In the left-side navigation pane, click Integration Center.
In the AI application observability section, select the
AgentScopeJava integration.Enter an application name, select the connection type that matches your deployment environment, and then obtain the
LicenseKey.Record the following parameters:
Parameter | Description |
| The key that authenticates data writes to Cloud Monitor 2.0. |
Workspace | The identifier of the Cloud Monitor 2.0 workspace. |
| The region that the application reports data to, for example, |
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
Log on to the ACK console. On the Clusters page, click the name of the cluster.
In the navigation pane on the left, click Add-ons, then locate ack-onepilot.
ImportantThe ack-onepilot version must be 5.1.0 or later.
Click Install on the ack-onepilot card.
NoteBy 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.
On the page that appears, you can configure the parameters. We recommend that you use the default values. Click OK.
NoteAfter 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.
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.
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
-
Log on to the ACK console. In the left navigation pane, click Clusters.
On the Clusters page, click the name of the target cluster. In the navigation pane on the left, choose . Next to the ack-onepilot component, click Update.
Replace
accessKeyandaccessKeySecretwith your AccessKey ID and AccessKey Secret, then click OK.NoteFor information about how to obtain an AccessKey pair, see Create an AccessKey pair.

Restart the application deployment.
Method 2: Import AccessKeys with a secret
Log on to the Container Service for Kubernetes console. In the navigation pane on the left, select Clusters.
On the Clusters page, click the name of the target cluster. In the navigation pane on the left, choose .
Select the ack-onepilot namespace, create a secret, and add your AccessKey pair.
NoteFor information about how to obtain an AccessKey pair, see Create an AccessKey pair.

In the navigation pane on the left, choose . Click the ack-onepilot component, which is typically named ack-onepilot-ack-onepilot and located in the ack-onepilot namespace.
On the details page of the component, click Edit in the upper-right corner. In the Environment Variables section, add
ONE_PILOT_ACCESSKEYandONE_PILOT_ACCESSKEY_SECRET. Configure them to reference the secret's values, then click OK.
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:
-
Log on to the ACK console. In the left navigation pane, click Clusters.
-
On the Clusters page, click the name of your cluster. In the left navigation pane, click .
On the Stateless page, click
> YAML Edit next to the target application. To create an application, click Create from YAML.In the YAML file, add the following
labelsto thespec.template.metadatasection.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: javaapiVersion: 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.1Click Update.
Manual installation
Install the agent
Log on to the Cloud Monitor 2.0 console, and select a workspace. In the left navigation pane, click Integration Center.
Click the Java Application Monitor card and then click Manual Installation.
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
wgetcommand for your region. Select your region from the table below.
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.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.
ImportantThe 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:
NoteFor agent versions earlier than 4.4.0, this method connects the application to the default workspace.
In the version file that you unzipped in the previous step, check the Java agent version.
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.propertiesto the startup command or add theOTEL_JAVAAGENT_CONFIGURATION_FILE=/path/to/arms-agent.propertiesenvironment 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}NoteFor more information about other configuration items in the agent configuration file, see Modify the Java agent configuration file and the default reporting region.
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.NoteIf 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.shfile extension with.batin 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=trueto 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 -jarcommandAdd 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.jarTomcat
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.jarRestart 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
In the Cloud Monitor 2.0 console, select the target workspace. In the left-side navigation pane, choose All features > AI application observability.
On the AI application list page, find the integrated
AgentScopeJava 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 |
LLM | A model call, including the input and output token counts. |
TOOL | A tool call, for example, |
References
AgentScopeJava official documentation: the API reference and more usage notes ofAgentScopeJava 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.