Coding With Agent

边界控制

清晰的边界指的是当一个功能或者问题解决后,及时的告诉 Agent,这个问题已经解决了。避免在后续的问题处理时,Agent 还想着之前的问题。比如我经常在解决完一个问题后,不论最后是真的 Agent 帮我解决了,还是我手动解决了,我都会在问下一个问题时,告诉他:非常好,上面这个问题已经解决了,接下来帮我解决另一个问题。

同样的道理,当你觉得一个比较整体的问题解决后,不再依赖这块上下文,最好新建一个 Agent 会话,这也是一种边界控制。防止你在处理新问题时,被之前的上下文干扰。

先分析再动手

现在 Agent 默认是直接帮你改代码,但有时候可能会过度设计,或者改的思路跟你想要的不一致。如果再回退代码,重新改文案,其实有些费时间。所以一般在解决稍微复杂的问题前,我会在末尾先加一个 ”先分析,不修改代码” 的提示。这样 Agent 就会按照 1、2、3 等几个点,把它的思路列出来,这时候我再判断是全部执行还是挑其中几个来执行,这样生成的代码基本就会是想要的。

及时同步上下文的变更

有时候 Agent 在解决不了某个问题的时候,需要手动改代码。但 Agent 大概率会在后续解决问题时,重新覆盖掉手动改好的代码。这时候就需要将手动改的内容,及时发给 Agent,让它更新上下文,以免后续反复覆盖。还有一种方式,就是尽量自己不动手改,再小的改动也指引 Agent 帮你更改,避免上下文不同步的问题。

适时的进行重构

首先是进行文件拆分。有些核心逻辑的文件,随着功能扩展会越来越大,Agent 对于这种大文件(上千行),很容易出现反复更改不到位的情况。所以当发现添加某个逻辑导致文件行数激增后,尽量在这次变更完后,做一次拆分重构。如果有开发经验,可以直接指引 Agent 对那块逻辑进行拆分后引用。如果不确定怎么拆分,可以直接问,让 Agent 给出思路后,再进行拆分。小文件对 Agent 其实更友好。

除了拆分,还有复用。当新的会话缺乏之前的上下文时,Agent 可能会重复生成一段已有的逻辑,如果发现后,可以指引它,“哪个文件已经有这块逻辑了,你看下是不是可以复用”。一般 Agent 就会反应过来。这也是基于后续一致性和扩展等因素考虑。

不符合预期就及时停掉

有时候看到 Agent 已经开始操作不符合预期的文件,或者分析的方向已经偏离了,可以选择及时停止。回头看下是不是问题没有给足上下文参考或者是限制不够明确。如果都不确定,可以用上面说的先分析再动手的技巧,让 Agent 先返回思路。不要想着 Agent 暂时搞错了,回过神就好了,其实最后哪怕对了,中间也会浪费很多时间。

手动复制文件

有时候代码已经生成了,可能就那几行代码,Agent 总是改不到位,或改完代码片段重复的问题。这时候可以停掉,选择自己手动复制或者删除多余代码片段的方式。然后告诉 Agent,“这个问题我已经解决了,下一个问题”。这个问题我发现最近 Agent 变聪明了,实在改不动,它就把文件删了,重新建一个。

及时提交代码

建议在新建一个边界前,都先对之前的代码进行提交。这样能避免 Agent 发挥“超常”后,代码被搞乱,回不去了。虽然现在 Agent 的回退也很好用,但做好版本管理还是更稳妥。

### GitHub Copilot Agent Configuration and Usage GitHub Copilot is an AI pair programmer that helps developers write code more efficiently by suggesting lines of code or entire functions inside supported editors like Visual Studio Code, Neovim, and JetBrains IDEs. To configure and use the GitHub Copilot effectively: #### Installation For using GitHub Copilot within Visual Studio Code, ensure installation through the marketplace extension[^1]. Once installed, restart VS Code to enable full functionality. #### Configuration Settings Several settings can be adjusted via `settings.json` in Visual Studio Code for better integration with personal coding styles: ```json { "github.copilot.enable": { "*": true, "yaml": false, "plaintext": false }, "editor.quickSuggestions": { "strings": true } } ``` This JSON snippet configures Copilot suggestions across all languages except YAML and plaintext while enabling quick suggestion prompts even when typing strings. #### Using Copilot Effectively To leverage prompt engineering techniques alongside Copilot's capabilities, consider crafting clear comments describing intended functionalities before writing actual implementation logic. This approach enhances semantic understanding between human intent and machine-generated responses: ```python # Generate a function named 'calculate_area' which takes two parameters length and width. def calculate_area(length, width): pass ``` In this example, adding descriptive TODO-like comments guides Copilot towards generating appropriate implementations automatically. #### Custom Environments Integration When working with custom environments such as those provided by Piston[^2], integrating these setups into development workflows allows testing generated codes under specified conditions without leaving familiar tools behind. For instance, setting up environment variables or specifying dependencies ensures accurate behavior during execution phases. #### CLI Tools Support Tools like Blessed-Vue offer unique ways to extend terminal interactions using modern web technologies[^3]. Combining such utilities with Copilot could lead to innovative solutions where command-line interfaces are enhanced with rich graphical elements powered by frameworks like Vue.js. --related questions-- 1. How does one customize GitHub Copilot’s language model fine-tuning process? 2. What best practices should be followed when documenting intentions for optimal Copilot assistance? 3. Can specific project requirements influence how well Copilot performs its task augmentation role? 4. Are there any limitations regarding file size or complexity affecting Copilot performance? 5. Is it possible to integrate other third-party services directly from within Copilot sessions?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值