github / github/copilot-cli

`copilot --acp` does not work with `--agent`

未關閉
#3,942 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
area:agents area:non-interactive
主要語言
Shell
星號
11.2k
分支
1.9k
平均合併
14 小時 16 分鐘
30 天內合併 PR
6

描述

### Describe the bug

Hello! First let me thank you for your hard work. Here is below my described issue. I used copilot a bit to help on having a proper reproducer command and a potential hint. Thanks a lot guys!

---

I created a custom agent in `~/.copilot/agents/test.agent.md`
```
---
name: test
description: A minimal test custom agent
tools: []
---
You are the test custom agent. Always respond by saying: "Hello from test custom agent!"
```

When I launch copilot in "human mode" with `copilot --agent test` it works.
```
● Selected custom agent: test
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
❯ hello
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
● Hello from test custom agent!
```

However when I try to use use ACP, with `copilot --acp --agent test`. It ALWAYS use the default Copilot agent. I can only use my custom agent as subagent, for example by saying "use test agent for <...>".

It seems like when using `--acp`, the `--agent` option is totally ignored.

### Affected version

GitHub Copilot CLI 1.0.65

### Steps to reproduce the behavior

## How to reproduce

#### 1. Create a minimal custom agent file in ~/.copilot/agents/test.agent.md:
```
---
name: test
description: A minimal test custom agent
tools: []
---
You are the test custom agent. Always respond by saying: "Hello from test custom agent!"
```

#### 2. Run this single command in your terminal to initialize a session and print the active agent configuration:
```
(echo '{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"protocolVersion":1,"clientCapabilities":{},"clientInfo":{"name":"test"}}}'; echo '{"jsonrpc":"2.0","id":1,"method":"session/new","params":{"cwd":"'"$(pwd)"'","mcpServers":[]}}'; sleep 6) | copilot --acp --agent test --yolo | grep -o '"id":"agent"[^}]*"currentValue":"[^"]*"'
```

## Expected behaviour
The active agent configuration option should reflect the command-line override ("test"):
```
"id":"agent","name":"Agent","currentValue":"test"
```

## Actual behaviour
The active agent configuration is empty, falling back to standard Copilot:
```
"id":"agent","name":"Agent","currentValue":""
```

### Expected behavior

Copilot should be launched in ACP with my custom agent as main agent. I want my session to have only the tools and context I have defined in my subagent, not with the general copilot gent. I don't want my custom agent to be available just as a tool.

## Expected behaviour
The active agent configuration option should reflect the command-line override ("test"):
```
"id":"agent","name":"Agent","currentValue":"test"
```

### Additional context

- Operating System: Linux (Kernel v24.16.0 or similar)
- CPU Architecture: x86_64 / x64 (installed as @github/copilot-linux-x64)
- Terminal Emulator: Ghostty (term/ghostty)
- Shell: Bash (v5.x)
- Copilot Version: v1.0.65
[copilot-acp-agent-bug.log](https://github.com/user-attachments/files/29375552/copilot-acp-agent-bug.log)

---

## Analysis by Copilot himself

- When starting in `--acp` server mode, the CLI action handler calls `startServerMode({...}, authManager)`. However, the parsed value of `--agent` (`t.agent` / `agentName`) is completely omitted from the configuration object passed to `startServerMode`.
- There is no way for the ACP client to specify the agent in the `session/new` params, and the ACP server does not implement the `session/set_config_option` method, making it impossible to change the active agent after session creation.

An analysis of the bundled index.js reveals exactly where the flow breaks:

#### 1. CLI Flag Parser:
The parser registers the --agent option correctly:
.option("--agent ", "Specify a custom agent to use")

#### 2. Server Mode Activation Block:
When `--acp` is supplied, the CLI invokes `startServerMode` like so:
```js
let { startServerMode: ee } = await Promise.resolve().then(() => (tIn(), Sto));
await ee({
port: de,
stdio: $,
logDir: G,
logLevel: b,
settings: p,
shutdownService: d,
featureFlags: r
}, a)
```
Notice that `t.agent` (the custom agent command-line argument) is completely omitted here! The starting server is never supplied with the `--agent` option context.

#### 3. ACP Protocol Limitations:
- The JSON-RPC request for `session/new` (`Ny.SESSION_CREATE`) does not include any parameter to define or activate an agent dynamically.
- While the ACP protocol schema defines a `session/set_config_option` method, the `registerMethods` routing mechanism on the server lacks an implementation of `setSessionConfigOption` (it is defined in the type definitions/client adapter `OSe` but is completely absent from the actual server class router).

### Suggestion for fix:
Pass the command-line override into `startServerMode` configuration parameters and use it to define the initial/default `currentValue` of the `"agent"` configuration option during session setup.

貢獻指南

開啟貢獻指南

研究方向

Start by tracing the ACP launch path in the bundled index.js from the --acp action to startServerMode, checking how the parsed --agent value is handled. Review session/new and the registerMethods routing mentioned in the report, then run the supplied reproducer and confirm that the agent configuration reports "test" rather than an empty value.

由索引模型根據 Issue 內容生成。

評估

技術堆疊
shell
領域
cli
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
冷清
描述清晰度
基本清楚
新手友好度
66/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。