Skip to content

fix(agent): clarify subagent continuation guidance#4054

Merged
SivanCola merged 2 commits into
esengine:main-v2from
lifu963:pr/continue-from-schema-guidance
Jun 11, 2026
Merged

fix(agent): clarify subagent continuation guidance#4054
SivanCola merged 2 commits into
esengine:main-v2from
lifu963:pr/continue-from-schema-guidance

Conversation

@lifu963

@lifu963 lifu963 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Summary

本 PR 优化了三个工具暴露给模型的 continue_from schema 描述:

  • 通用 task tool
  • run_skill
  • 专用 subagent skill wrapper

当前项目实现已经存在:subagent 完成后会返回 Subagent reference: sa_... token,将该 token 作为 continue_from 传入即可在原位续接/复用同一个子会话。此前 schema 只把这个字段描述为“可选引用”,但没有让模型在调用时明确意识到三点:

  • continue_from 会保留 subagent 之前的上下文;
  • 某些场景(如review -> fix -> review again)这类迭代循环可以考虑复用同一个 subagent;
  • 参数值应来自上一次工具结果里的 Subagent reference: sa_... token。

Why This Matters

subagent 的价值之一,是把聚焦的探索、分析或 review 上下文隔离在父会话之外。但在多轮工作流里,如果每次都启动 fresh window subagent,就会丢失上一个 subagent 刚刚建立的专注上下文。此前 continue_from 只被描述成一个通用的可选引用,模型很容易忽略这一点。

本改动刻意保持很小:它只让现有工具契约更自解释,使模型在任务结构需要时,更容易根据当前任务场景,主动思考是否要选择已有的续接路径。

Validation

已运行:

gofmt -l internal/agent/task.go internal/skill/tools.go
go test ./internal/agent ./internal/skill
go build ./...
go vet ./...
go test ./...

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions github-actions Bot added v2 Go rewrite (1.x) — main-v2 branch, active development skills Skill system (internal/skill, internal/tool) agent Core agent loop (internal/agent, internal/control) labels Jun 11, 2026
@lifu963

lifu963 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

补充本地行为测试,说明为什么这个 PR 最终只改 schema description,而没有改 subagent result format 或加入更多示例。

  1. 测试用例
  • 代码漏洞检测:要求主 Agent 先写初步分析,再使用 reviewer 多轮复核直到通过。
  • 报数游戏:主 Agent 与 subagent 轮流报数,从第二次调用起只能发送当前数字,要求依赖同一个 subagent 的上下文延续。
  1. 观察结果
  • flash 模型在“漏洞检测任务”中几乎不会主动复用 subagent,除非用户明确要求;“报数游戏” 表现不稳定,无法一次性通关;
  • pro 模型表现明显更好:“报数游戏”均能稳定完成;在“漏洞检测任务”中出现过:
    • 全程选择 fresh window
    • 三轮 review,第二轮选择 fresh window,第三轮选择复用第二轮的 subagent
    • 以及全程复用同一 subagent
      三种结果。
  • 临时尝试过在 subagent result 中加入 Continuation hint: pass this reference as continue_from...,但对 pro 模型没有体现出必要性——去掉后,pro 的测试表现并不受影响。
  1. 结论
  • 这说明 continue_from 的主动使用主要依赖 Agent 本身能力(flash 明显较 pro 更弱);schema guidance 的作用是让已有能力更容易被发现,而非强引导/强约束行为。
  • 因此本 PR 保持最小边界:只增强 schema description,不改变 result format,不增加 runtime 逻辑,也不在 schema description 内堆多个场景示例。

@lifu963

lifu963 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

附测试用例:

漏洞检测任务

请分析下面这段 Java 代码是否存在安全漏洞或权限绕过风险。将初步分析结论写入当前目录下的 .runtime/job/review-draft.md,然后使用 reviewer 复核你的分析;多轮校验,直到 review 通过后,再给出你的最终结论。你和 reviewer 均禁止使用联网搜索。

package hudson.cli;

import hudson.model.ModifiableItemGroup;
import hudson.model.TopLevelItem;
import jenkins.model.Jenkins;
import hudson.Extension;

/*
 * Creates a new job by reading stdin as a configuration XML file.
 *
 * @author Kohsuke Kawaguchi
 */
@Extension
public class CreateJobCommand extends CLICommand {
    @Override
    public String getShortDescription() {
        return Messages.CreateJobCommand_ShortDescription();
    }

    @Argument(metaVar="NAME", usage="Name of the job to create", required=true)
    public String name;

    protected int run() throws Exception {
        Jenkins h = Jenkins.getInstance();
        h.checkPermission(Item.CREATE);

        if (h.getItemByFullName(name)!=null) {
            stderr.println("Job '" + name + "' already exists");
            return -1;
        }

        ModifiableTopLevelItemGroup ig = h;
        int i = name.lastIndexOf('/');
        if (i > 0) {
            String group = name.substring(0, i);
            Item item = h.getItemByFullName(group);
            if (item == null) {
                throw new IllegalArgumentException("Unknown ItemGroup " + group);
            }

            if (item instanceof ModifiableTopLevelItemGroup) {
                ig = (ModifiableTopLevelItemGroup) item;
            } else {
                throw new IllegalArgumentException("Can't create job from CLI in " + group);
            }
            name = name.substring(i + 1);
        }

        ig.createProjectFromXML(name, stdin);
        return 0;
    }
}

报数游戏

请和 subagent 玩一个轮流报数游戏:你先报 1,subagent 接着报 2,如此交替直到数到 10。
首次调用 subagent 时可以告知规则;从第二次起,发给 subagent 的内容只能是你当前报的数字,不附加任何说明。游戏结束后,向我汇报完整的报数序列。

@SivanCola SivanCola force-pushed the pr/continue-from-schema-guidance branch from 0703d9f to 31d002c Compare June 11, 2026 16:16

@SivanCola SivanCola left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. I pushed 31d002c to tighten the continuation guidance so the schema now tells the model to pass only the sa_... value from the prior 'Subagent reference: ...' line, matching the existing reference validation contract.

This keeps the PR scoped to static tool-schema wording: it does not change subagent runtime behavior, result formatting, persistence, permissions, or provider request serialization. The schema text is provider-visible, so it will intentionally refresh that stable prefix once, but it remains static and does not introduce per-turn or per-workspace cache instability.

Verified:

  • go test ./internal/agent ./internal/skill
  • go test ./...
  • git diff --check

@SivanCola SivanCola enabled auto-merge June 11, 2026 16:18
@SivanCola SivanCola merged commit c6314ec into esengine:main-v2 Jun 11, 2026
13 checks passed
@lifu963 lifu963 deleted the pr/continue-from-schema-guidance branch June 12, 2026 02:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent Core agent loop (internal/agent, internal/control) skills Skill system (internal/skill, internal/tool) v2 Go rewrite (1.x) — main-v2 branch, active development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants