A popular view is that the essence of an AI Agent is to build more effective Prompt
. This statement, while not comprehensive, points out the Prompt
engineering at the heart of Agent development. In this paper, we will delve into Cline
source code, dissecting its Prompt
Architecture and details of the design.
System Prompt: The Cornerstone and Soul of the Agent
System Prompt
is a core asset for AI applications. In GitHub
On, a collection of various AI applications System Prompt
The fact that the warehouse has received tens of thousands of star ratings is a testament to its importance.Cline
(used form a nominal expression) System Prompt
The design is not static text, but a highly structured set of instructions dynamically generated based on contextual, instrumental, and modeling information, the source code of which is located in the src/core/prompts/system.ts
The
System Prompt
The identity was first set for the model:
You are Cline, a highly skilled software engineer with extensive knowledge in many programming languages, frameworks, design patterns, and best practices.
TOOL USE: Defining the Language of Action
Cline
(used form a nominal expression) Prompt
The design clearly shows how to guide the model step-by-step through the task, with the core of the design being the fine-grained management of the tool. This mechanism is designed with the same idea of ReAct (Reasoning and Acting)
The framework coincides with the cycle of "think-act-observe" to solve complex problems.
1. Tool call format
Prompt
The syntax of the tool call is first defined, requiring the model to use the XML
Labeled output ensures machine readability and parsing stability.
<tool_name>
<parameter1_name>value1</parameter1_name>
<parameter2_name>value2</parameter2_name>
...
</tool_name>
2. List of tools and examples
System Prompt
A detailed listing of all built-in tools, including functional descriptions, parameter descriptions, and usage examples. For example.write_to_file
The tool is extremely well defined, making it clear that files are overwritten if they exist, created if they don't, and will automatically handle directory creation.
## write_to_file
Description: Request to write content to a file at the specified path. If the file exists, it will be overwritten with the provided content. If the file doesn't exist, it will be created. This tool will automatically create any directories needed to write the file.
Parameters:
- path: (required) The path of the file to write to (relative to the current working directory ${cwd.toPosix()})
- content: (required) The content to write to the file. ALWAYS provide the COMPLETE intended content of the file, without any truncation or omissions. You MUST include ALL parts of the file, even if they haven't been modified.
Usage:
<write_to_file>
<path>File path here</path>
<content>
Your file content here
</content>
</write_to_file>
Cline
Built-in coverage of command line, file system, browser interaction and even MCP
(Meta-level Control Protocol) of more than a dozen tools that form a bridge between the model and the outside world.
3. Guidelines for the use of tools
Prompt
Clear Chain of Thought (CoT) guidelines are provided to guide the model on how to think and make decisions:
- Evaluation Information: in
<thinking>
Think within the tags. - Selection Tools: Select the most appropriate tool for the task.
- single-step implementation: Call one tool at a time and wait for the results before proceeding to the next step.
- constructor call: Use of prescribed
XML
Format. - Waiting for feedback: After each tool call, the system returns the execution result and the model has to wait for this feedback.
This step-by-step execution and wait-for-confirmation mechanism ensures the accuracy of task disassembly and the controllability of each step of the operation, significantly improving the success rate of complex tasks.
Document editing: a fine guide to core scenarios
File editing is the most high-frequency and core function of the Code Generation Agent.Cline
exist Prompt
In particular, it reinforces the importance of write_to_file
cap (a poem) replace_in_file
A guide to both tools and a set of best practice workflows for document editing:
- Scope of the assessment: Before editing, evaluate the scope of changes and decide which tool to use.
- refinement: Small, targeted modifications to use
replace_in_file
The - Refactoring or Creation: When refactoring extensively or creating new files, use the
write_to_file
The - synchronized state: After a file has been edited, the system provides a complete and up-to-date view of the file. The model must use this latest content as a baseline for subsequent operations, which avoids inconsistencies in the state caused by formatting or manual modifications by the user.
Plan Mode vs. Act Mode: Separation of Strategy and Execution
Cline
Two modes of operation are introduced:Plan Mode
cap (a poem) Act Mode
. When working on complex tasks, the user can first enter the Plan Mode
, allowing the model to develop high-level strategies, such as analyzing the code structure, identifying modifications, and encouraging the use of diagrams (e.g., Mermaid) for visual presentation. Once planning is complete, switch to Act Mode
The model will strictly follow the established plan, step by step execution of specific operations. This "plan first, execute later" model effectively improves the success rate of complex tasks and code quality.
Rules and Fences
Prompt
The rules (RULES) section of the model defines the boundaries of the model's behavior in an extremely strong tone, through bolding and so on. For exampleprohibitedutilization ~
maybe $HOME
refers to the user's home directory.prohibitedutilization cd
command.necessarilyWaiting for user confirmation. These explicit "bans" form the behavioral guardrails of the model, reducing uncertainty and potentially destructive operations.
Core goals and iterative cycles
Prompt
At the end of the process, it is clear that the Cline
Overall workflow for processing tasks:
- Analysis and disassembly: Analyze user tasks, set clear sub-goals and sequence them.
- Iterative execution: Processes subgoals sequentially, one tool at a time. Prior to invocation, the
<thinking>
tab to analyze the environment, select tools, and check parameters. - Parameter checking: If the necessary parameters are missing, theprohibitedinvocation tool, but instead use the
ask_followup_question
The tool requests information from the user. - Mission accomplished: After all goals are completed, use the
attempt_completion
The tool submits the final results. - Avoiding circular conversations: Response in progressshould notAvoid pointless conversations by ending with a question or a request for more help.
Extensibility and Customization of Prompt
Cline
(used form a nominal expression) Prompt
The system is not static and offers multiple levels of customization capabilities, allowing users to inject specific knowledge and workflows based on project needs.
Customizing System Prompt
Cline
Allows the user to add a user name to the project's root directory in the .clinerules/
folder to add custom commands. These directives are appended to the System Prompt
the end of the book as the most effective addition. Interestingly, theCline
The code even considers loading the Cursor
maybe Windsurf
rules document that demonstrates the openness of its design.
if (localCursorRulesFileInstructions) {
customInstructions += localCursorRulesFileInstructions + "nn"
}
// ...
Slash Command and Workflow
pass (a bill or inspection etc) /
triggered Slash Command
Shortcut entries are provided for specific tasks. For example./reportBug
A set of pre-defined bug feedback processes can be triggered. These commands correspond to the Prompt
The clip is in the src/core/prompts/commands.ts
Defined in.
Taking it a step further, users can create Workflow
Self-defining commands. In the .clinerules/workflows/
directory to create the Markdown
file, you can define a multi-step task flow. These customized Workflow
The same will be done with /
The commands appear in the chat box, providing a great convenience for users to encapsulate complex tasks.
@ Mention: dynamic injection context
@
The symbols in the Cline
for referencing external resources, dynamically injecting context into the Prompt
in. The user can @
a file path.Cline
will wrap the complete contents of that file in the <file_content>
In-tag sent to the model.
<file_content path="path/to/file">
[Complete file content]
</file_content>
In addition to the documents.@
It is also possible to refer to issues, command line history, and even URLs. this feature can be extended, for example, through the @
Docking the internal knowledge base allows Cline
Expertise in specific areas.
Memory Bank: Building Long-Term Memory
Memory Bank
be Cline
A solution designed to address the problem of long-term memory loss in LLM. The idea is to maintain a core set of documents about a project, and when an Agent loses the historical context in a new task, it can read these "notes" to get a quick overview of the project. This is conceptually similar to a manual, structured RAG
(Retrieval Enhanced Generation) System.
Users can find out more about this in the .clinerules/
directory to create the memory-bank.md
(math.) genusCline
The official example recommends a set of documentation structure, including project profile, technical architecture, development status, etc.
It is worth noting thatCline
The team promotes the use of Memory Bank
hit the nail on the head Mermaid
charts, they argue, "The best way to communicate with AI is not natural language - it's the structured language of workflow."
Realistic Considerations for Model Adaptation: The Case of Claude 4
Cline
In version 3.17.9 it is Claude 4
The model provides specialized Prompt
Adaptation. The official blog mentions that in order to solve the Claude 4
In dealing with errors in search and replace operations, they adjusted the delimiter to use the -
cap (a poem) +
substitute for <
cap (a poem) >
, thereby increasing the success rate of editing.
This detail reveals an important engineering reality:Prompt
Not "write once, run everywhere". Different models differ in terms of command adherence, formatting preferences, and output stability. Therefore, in a multi-model environment, model-specific Prompt
The refined testing and tuning of the system is a critical part of ensuring stability and reliability.
openrouter Website statistics show that the length and complexity of Cline's Prompt far exceeds that of other applications
Cline
(used form a nominal expression) Prompt
The design embodies highly modular and defensive programming ideas. It transforms a general-purpose language model into a focused, reliable, and efficient software engineering assistant through detailed instructions, rich context, clear rules, and multiple levels of customization. While this "no-nonsense" Prompt
The design will consume a lot of Token
The Agent's success rate is higher, but it is exchanged for a higher degree of certainty and success in performing complex tasks.