DEV Community

ObservabilityGuy
ObservabilityGuy

Posted on

Managing Logs with Natural Language: A Practical Guide to Alibaba Cloud SLS Agent Skills

This article uses practical scenarios to introduce these skills, explain how to use them, and share best practices.

Over the past year, SLS has continued to enhance its CLI and Agent Skills, progressively integrating log collection, analysis, and monitoring into agent workflows. Users can describe their business goals in natural language and let an agent coordinate log ingestion, monitoring setup, and troubleshooting, reducing the need for manual configuration, command writing, and repeated queries.

SLS now offers 8 skills covering the full log lifecycle, from generation to use: SDK integration and log collection, Logstore creation and index configuration, and query and analysis, alerting, visualization, and root cause analysis. Each skill can be installed as needed and uses progressive context disclosure, loading relevant instructions only when a task requires them to reduce unnecessary context overhead.

This article uses practical scenarios to introduce these skills, explain how to use them, and share best practices.

Overview of Skills and Capabilities

Skill Capability Use Cases
alibabacloud-sls-query Query and Analysis Query and analyze logs online using SLS query syntax, SQL, or SPL; generate and optimize queries.
alibabacloud-loongcollector-ops Log Collection - Install and upgrade Logtail/LoongCollector on ECS instances, Linux hosts, ACK, or self-managed Kubernetes clusters - Manage collection configurations, machine groups, and their bindings - Troubleshoot missing collected data and abnormal machine group heartbeats
alibabacloud-sls-agent-workflow Resource Management and Composite Tasks Select and install SLS skills; create and manage Projects and Logstores; combine skills for log ingestion, index configuration, query and analysis, and alerting according to the task.
alibabacloud-sls-alerting Alert Management and Diagnostics Create and adjust alert rules; configure notification channels, recipients, and policies; enable, disable, or silence alerts; and identify what triggered an alert using alert history and source logs.
alibabacloud-sls-dashboard Dashboards and Visualization Create and modify dashboards, charts, and filter controls; troubleshoot display issues; and manage dashboard subscriptions.
alibabacloud-sls-data-agent Root Cause Analysis Invoke SLS Data Agent to retrieve, analyze, and visualize data for anomaly investigation and root cause analysis, with support for retaining sessions and asking follow-up questions across multiple turns.
alibabacloud-sls-index-config-management Index Management Manage Logstore indexes, generate configurations from log samples, and optimize field types and analytics settings for query requirements while balancing write throughput and storage costs.
alibabacloud-sls-sdk-guidance Quick SDK Integration Automatically select an SLS SDK based on the programming language and business scenario; provide dependency installation, initialization, and code examples; and support log writing, consumption, querying, and logging framework integration.

Example Scenario: Set Up Codex Usage Monitoring with a Single Prompt

For Codex usage monitoring, we want to know where tokens are being consumed, how much weekly quota remains, and when the quota resets. We can summarize these requirements in the following prompt for an agent:

Write a script to collect Codex token usage on this machine, including detailed input, output, cached, and other usage information, along with current quota consumption, and report it periodically. Use aliyun cli to send the data to the xxxx Project in SLS, create the corresponding Logstore and index configuration, and then create a dashboard showing daily and weekly token usage, a quota consumption curve, and token usage statistics across different dimensions. Finally, configure an alert to send an email to xxxx@example.com when the Codex weekly quota resets.
Enter fullscreen mode Exit fullscreen mode

The agent automatically completes several interconnected steps:

  1. Collect and report data: Write token usage and quota snapshots to the token-usage Logstore, continuously recording consumption, remaining quota, and reset times.
  2. Create the Logstore and configure indexes: Create the corresponding Logstore and configure indexing and analytics for fields such as token counts, quota percentages, and timestamps, so the data can be queried and analyzed directly.
  3. Build a dashboard: View token consumption by model, project, and session, track usage trends, and understand which tasks are consuming the quota.
  4. Configure email alerts: Periodically query weekly quota records, detect quota resets, and send an email when the conditions are met.

We recommend pairing this with browser-controlling skills or tools such as browser use, browser act, chrome use, playwright, or agent browser. This allows the agent to use a browser to verify and fine-tune dashboard display details for better visual results.

Below is an illustration of the dashboard created by the agent:

Dashboard created by the agent for Codex usage monitoring

Below is a screenshot of the email alert received when the Codex quota resets:

Email alert received when the Codex quota resets

This example shows how collection, indexing, querying, visualization, and alerting can work together toward a single business goal. By describing the requirement to “understand usage and receive a reminder when the quota is restored,” we enable the agent to turn it into a continuously running monitoring workflow.

Installation and Usage

Node.js is required to install skills with npx.

1. alibabacloud-sls-query

Query and analyze SLS logs online using SLS query syntax, SQL, and SPL, and generate and optimize queries. Search logs by field, count errors, rank API endpoints, and track changes in latency.

Installation command:

npx -y skills add aliyun/alibabacloud-aiops-skills --skill alibabacloud-sls-query -y --full-depth
Enter fullscreen mode Exit fullscreen mode

Scenario 1: Find the Top 10 API Endpoints by Error Count

Query prod-web/nginx-access in cn-hangzhou and count, for each request_uri,
the  requests with status 500 over the past hour. List the 10 API endpoints with the most errors, and provide the query and statistical results.
Enter fullscreen mode Exit fullscreen mode

Scenario 2: Compare Latency Trends

Analyze changes in average latency in prod-web/nginx-access over the past hour compared with the same period yesterday, aggregated by minute.

See Query Documentation.

2. alibabacloud-loongcollector-ops

  • Install and upgrade Logtail/LoongCollector on ECS instances, Linux hosts, ACK, or self-managed Kubernetes clusters
  • Manage collection configurations, machine groups, and their bindings
  • Troubleshoot missing collected data and abnormal machine group heartbeats

Supports host log collection setup, collection configuration adjustments, and basic troubleshooting.

Installation command:

npx -y skills add aliyun/alibabacloud-aiops-skills --skill alibabacloud-loongcollector-ops -y --full-depth
Enter fullscreen mode Exit fullscreen mode

Scenario 1: Set Up Host Log Collection

Install LoongCollector on ECS instance i-example in cn-hangzhou and collect /var/log/nginx/access.log
into prod-web/nginx-access.Configure the machine group and its bindings, and verify that the logs can be queried in SLS.
Enter fullscreen mode Exit fullscreen mode

Scenario 2: Troubleshoot Missing Collected Data

There have been no new logs recently in prod-web/nginx-access in cn-hangzhou.  
Check the associated collection configurations, machine group bindings, and member heartbeats. Identify where the problem is and recommend corrective actions.
Enter fullscreen mode Exit fullscreen mode

3. alibabacloud-sls-agent-workflow

Select and combine skills according to the task to create resources, collect logs, query and analyze data, and configure alerts. Supports composite tasks spanning Logstore and index creation, log writing, and query verification.

Installation command:

npx -y skills add aliyun/alibabacloud-aiops-skills --skill alibabacloud-sls-agent-workflow -y --full-depth
Enter fullscreen mode Exit fullscreen mode

Example Scenario: Write and Query Logs

Create Project=demo-sls and Logstore=app-logs in cn-hangzhou,
configure indexes for level, service, and message, and write a few test logs.
Then query ERROR logs and count them by service to verify the write and query results.
Enter fullscreen mode Exit fullscreen mode

4. alibabacloud-sls-alerting

Create and adjust alert rules; manage notification channels, recipients, and policies; and enable, disable, or silence alerts and reduce alert noise. Identify what triggered an alert using alert history and source logs, and analyze alert frequency and duration.

Installation command:

npx -y skills add aliyun/alibabacloud-aiops-skills --skill alibabacloud-sls-alerting -y --full-depth
Enter fullscreen mode Exit fullscreen mode

Scenario 1: Create a Log Alert

Create web-500-alert in prod-web in cn-hangzhou, using nginx-access as the data source.
Check the logs from the past 5 minutes every 1 minute, and trigger an alert when the number of requests with status=500 is at least 100.
Send an email to the existing notification recipient web-ops@example.com.
Enter fullscreen mode Exit fullscreen mode

Scenario 2: Analyze Historical Alerts

Analyze alerts for prod-web/web-500-alert in cn-hangzhou during the Beijing time interval
2026-10-08 09:00 to 10:00. Check the trigger causes, frequency, and duration,
and use the source logs to identify the API endpoints with concentrated errors. Provide supporting query evidence.
Enter fullscreen mode Exit fullscreen mode

“Every 1 minute” is the check frequency, while “the past 5 minutes” is the query window. Rule configuration, execution, and notification delivery must be verified separately. See Alerting Documentation.

5. alibabacloud-sls-dashboard

Create and modify dashboards, charts, and filter controls; troubleshoot display issues; and manage dashboard subscriptions. Turn query results into monitoring dashboards that display metrics such as request volume, error rate, and latency.

Installation command:

npx -y skills add aliyun/alibabacloud-aiops-skills --skill alibabacloud-sls-dashboard -y --full-depth
Enter fullscreen mode Exit fullscreen mode

Scenario 1: Create a Request Monitoring Dashboard

Create a request monitoring dashboard for prod-web/nginx-access in cn-hangzhou.
Display request volume per minute, the number of 5xx responses, and average request_time in seconds.
Add a service filter control, verify the queries first, and then publish the dashboard to prod-web.
Enter fullscreen mode Exit fullscreen mode

Scenario 2: Update an Existing Dashboard

Read the web-overview dashboard in prod-web in cn-hangzhou,
add a chart showing the top 10 request_uri values by error count, and retain the other charts and filter controls.
Verify the configuration after updating it.
Enter fullscreen mode Exit fullscreen mode

6. alibabacloud-sls-data-agent

Invoke SLS Data Agent to use a digital employee for data retrieval, processing, analysis, and visualization, supporting anomaly investigation and root cause analysis. Supports retaining analysis sessions, asking follow-up questions across multiple turns, and drilling down into logs.

This skill depends on StarOps digital employee capabilities. Before using it, prepare an available StarOps digital employee and the target Project.

Installation command:

npx -y skills add aliyun/alibabacloud-aiops-skills --skill alibabacloud-sls-data-agent -y --full-depth
Enter fullscreen mode Exit fullscreen mode

Example Scenario: Analyze Anomalies and Drill Down Further

Use SLS Data Agent and the digital employee apsara-ops to analyze 
request volume, error rate, and latency in prod-web/nginx-access in cn-hangzhou over the past hour. 
Identify anomalous time periods, and provide charts and analytical conclusions.
Enter fullscreen mode Exit fullscreen mode

You can ask a follow-up question in the same session:

Continue analyzing the anomalous time periods identified earlier. Compare error rates by API endpoint and identify the endpoint with the largest change.
Enter fullscreen mode Exit fullscreen mode

7. alibabacloud-sls-index-config-management

Manage Logstore indexes, generate configurations from log samples, and adjust field types and analytics settings to meet query requirements. Supports viewing, creating, modifying, and deleting indexes, as well as optimizing write throughput and storage costs.

Installation command:

npx -y skills add aliyun/alibabacloud-aiops-skills --skill alibabacloud-sls-index-config-management -y --full-depth
Enter fullscreen mode Exit fullscreen mode

Scenario 1: Generate an Index from a Log Sample

Generate an index configuration for the following log sample. It must support filtering by status, grouping by service,  
and calculating the average latency_ms. First provide the configuration JSON and field descriptions; do not apply any updates.  
{"status":500,"service":"order","latency_ms":238.5,"message":"timeout"}
Enter fullscreen mode Exit fullscreen mode

Scenario 2: Add a Field for Analysis

Read the index for prod-web/app-logs in cn-hangzhou, set latency_ms to type double,
and enable analytics to support average calculations. Retain the configurations for all other fields and describe the changes.
Enter fullscreen mode Exit fullscreen mode

8. alibabacloud-sls-sdk-guidance

Automatically select an SLS SDK based on the programming language and business scenario, and provide dependency installation, initialization, and code examples. Supports log writing, consumption, querying, and integration with logging frameworks such as Log4j2 and Logback.

Installation command:

npx -y skills add aliyun/alibabacloud-aiops-skills --skill alibabacloud-sls-sdk-guidance -y --full-depth
Enter fullscreen mode Exit fullscreen mode

Scenario 1: Select SDKs for Log Writing and Consumption

Select an SLS SDK for a Java 17 project. Logs must be written asynchronously in batches, and the consumer must support  
Consumer Group, checkpoint, and load balancing across multiple instances.  
Provide the rationale for your selection, Maven dependencies, and a minimal integration example.
Enter fullscreen mode Exit fullscreen mode

Scenario 2: Integrate Through Log4j2

The Java project already uses Log4j2, and we want to send logs through an Appender to  
prod-web/app-logs in cn-hangzhou. Provide the Maven dependencies and log4j2.xml configuration.
Enter fullscreen mode Exit fullscreen mode

See SDK Integration Documentation.

Configure Credentials

SLS skills primarily depend on Aliyun CLI and the SLS plugin. In addition to static AccessKeys, they support methods such as OAuth and EcsRamRole that do not require long-term AccessKeys to be configured. For all supported credential types and configuration methods, see Alibaba Cloud CLI: Configure and Manage Identity Credentials. Authentication alone is not sufficient; the corresponding RAM permissions for the resources are still required.

Credential Type Use Cases Supports Non-Interactive Configuration Configuration Details
AK Authenticate directly using the long-term AccessKey of an Alibaba Cloud account or RAM user. These credentials remain valid indefinitely and are relatively less secure. If you must use them, first consult AccessKey Best Practices. Yes Configure AK Credentials
OAuth Sign in through a browser using an Alibaba Cloud account, RAM user, or SSO, with support for MFA and passkeys (Passkey). No long-term AccessKey needs to be stored, providing a high level of security. No Configure OAuth Credentials
EcsRamRole When running the CLI on an ECS instance, automatically obtain temporary security credentials through the RAM role attached to the instance, without configuring or storing a long-term AccessKey. Yes Configure EcsRamRole Credentials
RamRoleArn Assume a RAM role and operate on resources as that role. Suitable for temporary privilege elevation or cross-account access. For example, a RAM user with basic permissions can assume a RAM role with resource management permissions, or access resources across Alibaba Cloud accounts. Uses temporary security credentials (STS Token). Yes Configure RAM Role Credentials
ChainableRamRoleArn Chained role assumption (role chaining) is suitable for accessing resources across multiple accounts. Yes Configure RAM Role Chain Credentials
OIDC Authenticate and assume a role using an ID Token issued by an external identity provider compatible with OIDC (OpenID Connect). Recommended for ACK/ACS Pods with RRSA (RAM Roles for Service Accounts) enabled. Yes Configure OIDC Credentials
CloudSSO Suitable for multi-account enterprise environments with CloudSSO and Resource Directory enabled. Like OAuth, this is an interactive authentication method that uses browser-based sign-in and supports MFA. No Configure CloudSSO Credentials
External Invoke an external executable to obtain credentials dynamically, either an AccessKey or a temporary security token. Suitable for custom credential providers. Yes Configure External Credentials
CredentialsURI Obtain temporary security credentials (STS Token) from an HTTP URI you provide. Suitable for self-managed credential distribution services. No Configure CredentialsURI Credentials
StsToken Manually provide temporary security credentials (STS Token). The token must be updated manually after it expires. Yes Configure StsToken Credentials
BearerToken Use a Bearer Token to authenticate to Alibaba Cloud API services. Suitable for automated scenarios such as CI/CD. Yes Configure BearerToken Credentials

Aliyun CLI can store credential and Region information in profiles, allowing quick switching between identities, Regions, and credential types. The default profile is named default. Use the following command to list existing profiles:

aliyun configure list
Enter fullscreen mode Exit fullscreen mode

The following sections explain how to configure several commonly used credential types. For other credential types and configuration methods, see Alibaba Cloud CLI: Configure and Manage Identity Credentials.

Static AccessKey

Configure a profile using a static AccessKey:

aliyun configure # Configure the default profile
aliyun configure --profile <profileName> # Configure a named profile; it is created automatically if it does not exist
Enter fullscreen mode Exit fullscreen mode

OAuth Sign-In and Authorization

OAuth setup is straightforward in environments where you can sign in to an Alibaba Cloud account through a browser, such as a local Mac on the office network. The first OAuth sign-in requires the account to be authorized.

You can then configure the specified profile using OAuth. A browser opens automatically for sign-in and authorization:

aliyun configure --mode OAuth --profile <profileName>
Enter fullscreen mode Exit fullscreen mode

Manage Project Resources Across Regions

alibabacloud-sls-query includes built-in cross-region Project discovery. If a Project cannot be found in the default Region, or the user is unsure which Region it belongs to, the agent searches for the Project globally, obtains its Region and Endpoint, and continues querying with the discovered Endpoint. This eliminates the need to find and set the Region or Endpoint manually.

You can also look up the Project manually as follows (the Endpoint must be fixed to cn-zhangjiakou.log.aliyuncs.com)

aliyun sls get-project --project <projectName> --cross-region true --endpoint cn-zhangjiakou.log.aliyuncs.com
Enter fullscreen mode Exit fullscreen mode

Frequently Asked Questions

Do I Need to Install the CLI and SLS Plugin in Advance?

They are required for cloud operations. The agent checks the CLI and SLS plugin and provides installation or upgrade guidance if either is missing or does not meet the version requirements. No access to cloud resources is needed when merely explaining configurations or generating code examples. See the Query Documentation and Alerting Documentation.

Can I Use an Intranet, Transfer Acceleration, or Custom Endpoint?

Yes. Specify the Endpoint in your request, for example cn-hangzhou-intranet.log.aliyuncs.com, and ensure that the runtime environment can access it. See the Query FAQ.

Which Skills Are Recommended?

alibabacloud-sls-query is the most strongly recommended skill, and we suggest installing it right away. It is very useful for querying and analyzing logs and generating SQL/SPL. Install other skills according to your actual needs.

How Can I Access Log Resources Managed by Normandy?

Aliyun CLI does not currently support Normandy authentication. We recommend installing and using the normandy-cli skill together with the alibabacloud-sls-query skill.

Conclusion

Through the official CLI and 8 Agent Skills, SLS connects log collection, SDK integration, resource and index management, query and analysis, alerting, visualization, and root cause analysis, covering the full log lifecycle. With multiple authentication methods and cross-region resource discovery, users can organize tasks around business goals while reducing environment setup, command writing, and tool switching.

The CLI now handles more than 1.1 million daily requests, while Skills handles more than 500,000 daily requests. The CLI’s daily request volume is approximately 700 times its level in February 2026. CLI and Skills are becoming everyday entry points to SLS for developers and operations engineers.

Going forward, we will expand the scenarios covered by these skills, improve multi-skill collaboration and the analysis of complex problems, and incorporate more proven operational workflows and troubleshooting experience into the skills. While improving execution accuracy and reliability, we will continue to develop SLS into an AI First, Agent Native observability platform, enabling agents to invoke and combine data, tools, and product capabilities naturally and unlock their full potential in data analysis, system diagnostics, and automated operations.

Top comments (0)