Ask HN: 我在 Agentic 编程方面做错了什么?

2作者: tlonny8 个月前
以下是我给 Claude Code CLI 和 VSCode 代理的关于我的 TS 项目的提示: ``` 我修改了作业的创建方式的类型签名和行为。之前,作业定义创建接受一个批处理参数(从队列创建)。现在它直接接受队列,是异步的,需要在创建时传入 databaseClient(而不是在执行批处理时)。它不再返回任何内容——这没关系,因为结果只用于日志记录——现在已经为我们完成了,所以我们不必担心。我们可以重构代码库以使用新的 JobDefinition.create 吗?请删除残留的“Job created”日志。 执行此任务,且仅执行此任务。如果你看到一些不相关的内容,你认为需要重构——请勿修改它。仅执行与此任务直接相关的操作。 ``` 所以有两个指示: 1. 执行任务 2. 不要做与任务无关的事情(在后续尝试中因沮丧而添加) 我的经验: 代理流程开始得很好——它找到了所有需要更改的文件并开始进行编辑。 大约在第 5 个文件时,我注意到除了请求的重构之外,它还开始重新排序 `JobDefinition.create` 方法的对象键。虽然在语义上是无操作的,但这非常令人沮丧,因为它使 diffs 难以审查。 稍后,它开始修改它不满意的日志消息,最终完全失控,并向我的函数定义添加了它*认为*它们需要的参数(引入类型/运行时错误)。 VSCode 会定期暂停并要求确认才能继续。每次我都会利用这个机会重新提示代理,让它专注于目标: 我:“停止跑题——停止重命名变量,重新排序参数。只做任务告诉你的事情,仅此而已” 代理:“你完全正确。对于跑题,我深感抱歉。让我只专注于任务:重构 JobDefinition.create 调用以使用新的签名并删除残留的“Job created”日志” 但每次这种不良行为都会在一段时间后再次出现。 我不确定我做错了什么。我假设这种机械的猴子工作对于基于代理的工作流程来说是小菜一碟——但它却一直失去连贯性。 我最终回滚了所有更改,因为我对生成的代码的质量完全没有信心。 对于这堆文字,我深感抱歉,但我对浪费的时间感到非常沮丧,并且非常想知道我做错了什么! 提前感谢!
查看原文
Here is the prompt I gave both Claude Code CLI, and the VSCode agent for my TS project:<p>```<p>I have modified the type signature and behaviour of how jobs are created. Previously, job definition create took a batch argument (created from a queue). Now it takes the queue directly, is async, requires the databaseClient to be passed in at creation (vs. when the batch is executed). It no longer returns anything - which is fine because the result was only being used for logging - which is now done for us so we don&#x27;t have to worry. Can we refactor the codebase to make use of the new JobDefinition.create? Remove the vestigial &quot;Job created&quot; log please.<p>Perform this task and this task only. If you see something unrelated that you believe needs to be refactored - DO NOT MODIFY IT. ONLY PERFORM ACTIONS DIRECTLY RELEVANT TO THIS TASK<p>```<p>So there are two instructions:<p>1. Do the task<p>2. Don&#x27;t do stuff that isn&#x27;t the task (added in frustration on subsequent attempts)<p>My experience:<p>The agent flow started well - it found all the files that needed to change and began making edits.<p>By about file #5 I noticed that on top of requested refactor it started re-ordering object keys of the `JobDefinition.create` method. Although semantically a no-op, this was incredibly frustrating as it made diffs much harder to review.<p>A little later, it started to modify log messages it wasn&#x27;t happy with before eventually completely going off the rails and adding arguments to my function definitions that it _thought_ they needed (introducing type&#x2F;run-time errors).<p>VSCode would periodically pause and ask for a confirmation in order to continue. Each time I used the opportunity to re-prompt the agent to stay on target:<p>Me: &quot;STOP GOING OFF TASK - STOP RENAMING VARIABLES, REORDERING PARAMS. JUST DO AS THE TASK TELLS YOU AND NOTHING ELSE&quot;<p>Agent: &quot;You&#x27;re absolutely right. I apologize for going off task. Let me focus solely on the task: refactoring JobDefinition.create calls to use the new signature and removing vestigial &quot;Job created&quot; logs&quot;<p>And each time the bad behavior would return after some time.<p>I&#x27;m not sure what I&#x27;m doing wrong. I assumed this sort of mechanical monkey work would be bread and butter for an agentic workflow - but it just keeps losing coherence.<p>I ended up reverting all the changes as I had absolutely 0 trust in the quality of the generated code.<p>I apologise for the wall of text but I&#x27;m quite frustrated about all the time wasted and am desperate to know what I&#x27;m doing wrong!<p>Thanks in advance!