CodeArts Agent supports incorporating context to improve Q&A accuracy. Context helps the agent understand the background and intent of your question better to generate more practical and valuable answers.
A variety of context types are currently supported, including files, folders, symbols, Git changes, terminal output, problems, and knowledge bases. All contexts can be flexibly combined and seamlessly associated with your input to build richer and more accurate Q&A scenarios.
Constraints
Table 1 Constraints | Category | Description |
| Quantity | A maximum of 20 contexts can be added at a time. |
| Size | The context size must not exceed four times the context window of the currently used model. For example, if GLM-5.2 (which supports a context window of 202.8K tokens) is used and your context is in a file, the file size should be kept within 811.2K (202.8K × 4) tokens. For details about the context length supported by each model, see Table 2. |
Adding Context
- Log in to CodeArts Agent IDE as instructed in Quick Start.
- Add a context.
- Method 1: Enter # in the input box and select the required context type from the displayed menu.
- Method 2: Click
in the input box, choose Add Context, and select the required context from the displayed menu.
- Context usage example
For example, when you open a project and need to fix a bug in the login function, CodeArts Agent can help you quickly locate and rectify the fault based on the context.
- File: src/auth/login.js file (View the login logic.)
- Folder: src/components (View the existing structure.)
- Git: View the latest related commits and learn the change history.
- Problems: View error logs and learn about specific error information.
- Terminal: View the test output and details about the test failure.
- Rules: View security specifications for bug fixing.
Supported Context Types
CodeArts Agent supports multiple context types, which can be flexibly combined. Your input can also be combined with the context to form a complete requirement expression. Multiple context types are supported, including files, folders, symbols, Git changes, terminal outputs, problems, and knowledge bases.
File
You can ask questions about one or more files or edit them.
Procedure:
In the chat window of CodeArts Agent, enter # in the input box, or choose
> Add Context. Click File and select the file you want from the list. To add multiple files, repeat the preceding operations.
Click a referenced file in the input box to locate the target file.
Folder
You can query and modify all content in a specified folder. When you need to perform batch operations on a code module, you only need to select the corresponding project directory to complete related tasks.
Procedure:
In the chat window of CodeArts Agent, enter # in the input box, or choose
> Add Context. Click Folder and select the folder you want from the list. To add multiple folders, repeat the preceding operations.
Click a referenced folder in the input box to open the target folder in the explorer.
Symbol
You can reference code symbols such as functions, classes, and variables as the context.
Procedure:
In the chat window of CodeArts Agent, enter # in the input box, or choose
> Add Context. Click Symbol and select the function, class, or variable to be referenced.
When CodeArts Agent is switched to the (custom) agent mode, symbols cannot be added as contexts.
Git
You can analyze code changes committed to the code repository, helping developers easily view each code change and clearly understand the project evolution and quality trend.
Procedure:
In the chat window of CodeArts Agent, enter # in the input box, or choose
> Add Context. Click Git and select the commit code or checkpoint to be referenced from the list.
Terminal
You can quickly locate historical commands and execution results through the terminal.
Procedure:
In the chat window of CodeArts Agent, enter # in the input box, or choose
> Add Context. Click Terminal and select TerminalFull (complete command history) or TerminalLastCommand (last terminal command) as required.
Problems
You can use Problems to quickly reference compilation error information, analyze all problems, and provide corresponding solutions.
Procedure:
In the chat window of CodeArts Agent, enter # in the input box, or choose
> Add Context. Click Problems and ask questions on the error information.
Knowledge Bases
You can use knowledge bases to ask questions about the overall knowledge system, improving the capabilities of code generation and R&D Q&A scenarios. Before using this function, you need to create a knowledge base. For details, see Knowledge Bases.
Procedure:
In the chat window of CodeArts Agent, enter # in the input box, or choose
> Add Context. Click Knowledge Bases and select the required knowledge base and knowledge set.
Rules
You can customize rules to help CodeArts Agent better understand the code repository structure and comply with project specifications. These rules can be automatically loaded or invoked by CodeArts Agent, or manually applied by you. Create rules before using them. For details, see Rules.
To manually apply a rule, perform the following operations:
In the chat window of CodeArts Agent, enter # in the input box, or choose
> Add Context. Click Rules and select the rule you want from the list. To add multiple rules, repeat the preceding operations.
Using the Editor Content as the Context
When you edit code files in CodeArts Agent, it can view the active file by default. You can directly ask CodeArts Agent questions related to this file, such as asking about a specific block of code within it.
In the code editor, select the corresponding code. Right-click and choose CodeArts Agent: Add Code to Chat to add the selected content to the chat box as the context.
Context Compression
CodeArts Agent provides a context window to display the token usage in the current chat, helping you view the context usage and avoid affecting the chat continuity.
When your development proceeds around a topic, the chat content accumulates and the context window is about to overflow. You can compress the current context. CodeArts Agent automatically summarizes the context, reducing the usage cost and improving the response efficiency.
When you want to discuss a new topic or start a new task, you are advised to start a new chat. This can effectively avoid interference from irrelevant historical records, so that CodeArts Agent can more accurately understand and respond to your requirements.
Figure 1 Context window
Table 2 Context compression rules | Mode | Model | Context Limit | Context Compression Mode |
| Ask | GLM-5.1 GLM-5.2 | 202.8K tokens | - Manual compression: If context usage goes over 10% of the limit, click Summarize.
- Automatic compression: When the total token count of the current and historical chats exceeds 90% of the limit, the context is automatically compressed.
|
| Agent Custom agent | GLM-5.1 GLM-5.2 | 202.8K tokens | Automatic compression: When the total token count of the current and historical chats exceeds 90% of the limit, the context is automatically compressed. |