All Products
Search
Document Center

DataWorks:Code assistant

Last Updated:Jul 10, 2026

Data Agent lets you generate, optimize, explain, and test SQL and Python code through natural language. You can access it from the code editor or Data Agent Chat Ask mode.

Overview

Data Agent is powered by a large language model (LLM) and provides intelligent SQL and Python programming support for data developers. It offers two interaction methods: the code editor for real-time code completion and right-click shortcuts, and Data Agent Chat (Ask mode) for conversational Q&A. Core capabilities include code generation, refactoring, debugging, optimization, explanation, comment generation, testing, Code Q&A, intelligent Notebook cell generation, and cross-engine quick table search. You can enhance accuracy by adding context such as tables, nodes, Data Collections, Rules, or local files, and switch between different large language models. Data Agent works out of the box with no coding expertise required, improving the efficiency of data modeling, ETL development, and debugging.

Access

Code editor

Use case 1: Intelligent code completion

How to use: While you write code in a node, Data Agent predicts and suggests code snippets based on context such as existing code and referenced table structures. Suggestions appear automatically. Press Tab to accept a suggestion.

Use case 2: Right-click menu shortcuts

How to use: In the code editor, select the desired code, right-click, and choose Copilot from the context menu.

image

Data Agent Chat (Ask mode)

Ask mode is the default mode for Data Agent Chat and addresses specific coding problems in a Q&A format. It supports code generation, refactoring, debugging, comment generation, explanation, optimization, testing, Code Q&A, intelligent Notebook cell generation, and quick table search. You can also select code in the editor to provide context for your requests.

Quick start

Get started with Data Agent Chat (Ask mode) by following these steps.

Step 1: Open Data Agent Chat (Ask mode)

  • Log in to the DataWorks console. In the left-side navigation pane, choose Data Development and O&M > DataStudio. Select the desired workspace and click to enter Data Studio.

  • Click the image icon in the upper-right corner of the Data Studio page, to open Data Agent Chat (Ask mode).

Step 2: Add context (optional)

Add context to help Data Agent better understand your request. Enter @ in the dialog box or click the @ icon in the lower-right corner to open the context menu and select a context type.

The following context types are supported:

  • Table: Reference metadata from one or more tables.

  • Node/Code file: Reference the code within a specific node.

  • Data collection: Reference a Data Collection from Data Map.

  • Rules: Temporarily apply one or more rules to the current conversation.

  • Local file: Upload a local document as context.

Step 3: Switch the large language model (optional)

Data Agent uses the default model. You can click the image icon at the bottom of the dialog box to select a different large language model.

Step 4: Submit a question and engage in multi-turn conversations

Enter your request in the dialog box. You can ask follow-up questions or provide additional details in a multi-turn conversation to refine your intent until Data Agent produces the expected results.

Feature details

Data Agent Chat (Ask mode) generates SQL and Python code through natural language and provides code completion, refactoring, optimization, explanation, debugging, and test case generation. Core capabilities include:

Capability

Description

Example (you can say this to Data Agent)

Code generation/SQL generation

Generate code based on your instructions.

"Write an SQL query to find the top three products by sales amount for each city in the sales table."

Code rewriting/SQL rewriting

Rewrite specified code as required.

"Rewrite this SQL that uses JOIN to use window functions instead."

Code debugging/SQL debugging

Find and fix errors in specified code.

"This SQL throws an invalid identifier error. Help me find the issue."

Comment generation

Generate comments for specified code.

"Add comments in Chinese to this complex SQL logic to explain the purpose of each CTE."

Code explanation

Explain specified code.

"Explain what PARTITION BY and ROW_NUMBER() mean in this code."

Code optimization

Optimize specified code.

"This query is slow. Help me optimize it and identify any performance bottlenecks."

Code testing

Provide a testing plan for specified code.

"Design some test cases for this SQL that calculates user retention rates. What edge cases should be considered?"

Code Q&A

Answer questions about code syntax, functions, and more.

"What is the difference between the explode function and lateral view in MaxCompute?"

Notebook Cell smart generation

Intelligently generate a code cell in a notebook.

"Create a cell that uses pandas to read the /data/users.csv file and display the first 5 rows."

Quick table search

Enter keywords to find target tables.

"Find all tables related to 'user'."

Code generation / SQL generation

Description: Generate code from natural language instructions.

How to use: The following two methods are supported:

  • In the code editor, right-click a blank area and choose Copilot > SQL Statement Generation to open the Data Agent interface. Then enter a natural language request to have the large language model return the desired code.

  • In the code editor, click the image icon in the upper-right corner of the Data Studio page to open Data Agent Chat (Ask mode). In the input box, enter / and select Code generation. Then enter a natural language request to have the large language model return the desired code.

Code refactoring / SQL rewriting

Description: Rewrite specified code based on your requirements.

How to use: The following two methods are supported:

  • In the code editor, select the target code, right-click a blank area, and choose Copilot > SQL Statement Rewrite to open the Data Agent interface. Then enter your rewriting requirements.

  • In the code editor, select the target code, enter / in the Data Agent Chat (Ask mode) input box, select Code rewriting, enter your rewriting requirements, and click Send. Wait for Data Agent to return the results.

Code debugging / SQL correction

Description: Find and fix errors in specified code snippets.

How to use: The following two methods are supported:

  • In the code editor, select the target code, right-click a blank area, and choose Copilot > SQL Statement Rectification to open the Data Agent interface.

  • In the code editor, select the target code, enter / in the Data Agent Chat (Ask mode) input box, select Code Error correction, and click Send. Wait for Data Agent to return the results.

Comment generation

Description: Generate comments for specified SQL content to improve readability.

How to use: The following two methods are supported:

  • In the code editor, select the target code, right-click a blank area, and choose Copilot > Generate Comments to open the Data Agent interface.

  • In the code editor, select the target code, enter / in the Data Agent Chat (Ask mode) input box, select Generate Comments, and click Send. Wait for Data Agent to return the results.

Code explanation

Description: Explain specified SQL content to improve readability.

How to use: In the code editor, select the target code, enter / in the Data Agent Chat (Ask mode) input box, select Code interpretation, and click Send. Wait for Data Agent to return the results.

Code optimization

Description: Optimize selected SQL code to simplify logic, improve execution efficiency, and reduce database load.

How to use: In the code editor, select the target code, enter / in the Data Agent Chat (Ask mode) input box, select Code Optimization, and click Send. Wait for Data Agent to return the results.

Code testing

Description: Generate a testing plan and test code for selected SQL to verify whether each part works as expected.

How to use: In the code editor, select the target code, enter / in the Data Agent Chat (Ask mode) input box, select Code Testing, and click Send. Wait for Data Agent to return the results.

Code Q&A

Description: Explain SQL syntax or MaxCompute functions and provide usage examples.

How to use: In Data Agent Chat (Ask mode), enter your question in the input box and click Send. Wait for Data Agent to return the results.

Intelligent Notebook cell generation

Description: Generate a notebook cell from keywords.

How to use: In Data Agent Chat (Ask mode), enter / in the input box and select Intelligent Notebook Cell Generation. Then enter keywords in the editing window and click Send. Data Agent generates the corresponding notebook node.

Quick table search

Description: Search for target tables across all compute engines and data sources by keyword.

How to use: In Data Agent Chat (Ask mode), enter / in the input box and select Quick Find Table. Then enter keywords in the editing window and click Send. Data Agent returns tables that match the keywords across all associated compute engines and data sources.