Hinweis
Die ACP-Unterstützung in GitHub Copilot-CLI befindet sich in öffentliche Vorschau und kann sich noch ändern.
Überblick
Das Agent-Clientprotokoll (ACP) ist ein Protokoll, das die Kommunikation zwischen Clients (z. B. Code-Editoren und IDEs) und Codierungs-Agents (z. B. Copilot-CLI) standardisiert. Weitere Informationen zu diesem Protokoll finden Sie in der offiziellen Einführung.
Anwendungsfälle
-
**IDE-Integrationen:** Integrieren Sie die Unterstützung für Copilot in jeden Editor oder jede Entwicklungsumgebung. -
**CI/CD-Pipelines:** Koordinieren Sie agentische Codierungsaufgaben in automatisierten Workflows. -
**Benutzerdefinierte Frontends:** Erstellen Sie spezielle Schnittstellen für bestimmte Entwicklerworkflows. -
**Multi-Agent-Systeme:** Koordinieren Sie Copilot mit anderen KI-Agents mithilfe eines Standardprotokolls.
Starten des ACP-Servers
GitHub Copilot-CLI kann mit dem Flag --acp als ACP-Server gestartet werden. Der Server unterstützt zwei Modi, stdio und TCP.
Stdiomodus (empfohlen für die IDE-Integration)
Standardmäßig wird beim Bereitstellen des --acp-Flags der stdio-Modus abgeleitet. Die --stdio Kennzeichnung kann auch zur Auflösung von Mehrdeutigkeiten zur Verfügung gestellt werden.
copilot --acp --stdio
TCP-Modus
Wenn das --port Flag in Kombination mit dem --acp Flag bereitgestellt wird, wird der Server im TCP-Modus gestartet.
copilot --acp --port 3000
Integration mit dem ACP-Server
Es gibt ein wachsendes Ökosystem von Bibliotheken, um programmgesteuert mit ACP-Servern zu interagieren. Da GitHub Copilot-CLI ordnungsgemäß installiert und authentifiziert sind, veranschaulicht das folgende Beispiel die Verwendung des Typescript-Clients zum Senden einer einzelnen Eingabeaufforderung und zum Drucken der KI-Antwort.
import * as acp from "@agentclientprotocol/sdk";
import { spawn } from "node:child_process";
import { Readable, Writable } from "node:stream";
async function main() {
const executable = process.env.COPILOT_CLI_PATH ?? "copilot";
// ACP uses standard input/output (stdin/stdout) for transport; we pipe these for the NDJSON stream.
const copilotProcess = spawn(executable, ["--acp", "--stdio"], {
stdio: ["pipe", "pipe", "inherit"],
});
if (!copilotProcess.stdin || !copilotProcess.stdout) {
throw new Error("Failed to start Copilot ACP process with piped stdio.");
}
// Create ACP streams (NDJSON over stdio)
const output = Writable.toWeb(copilotProcess.stdin) as WritableStream<Uint8Array>;
const input = Readable.toWeb(copilotProcess.stdout) as ReadableStream<Uint8Array>;
const stream = acp.ndJsonStream(output, input);
const client: acp.Client = {
async requestPermission(params) {
// This example should not trigger tool calls; if it does, refuse.
return { outcome: { outcome: "cancelled" } };
},
async sessionUpdate(params) {
const update = params.update;
if (update.sessionUpdate === "agent_message_chunk" && update.content.type === "text") {
process.stdout.write(update.content.text);
}
},
};
const connection = new acp.ClientSideConnection((_agent) => client, stream);
await connection.initialize({
protocolVersion: acp.PROTOCOL_VERSION,
clientCapabilities: {},
});
const sessionResult = await connection.newSession({
cwd: process.cwd(),
mcpServers: [],
});
process.stdout.write("Session started!\n");
const promptText = "Hello ACP Server!";
process.stdout.write(`Sending prompt: '${promptText}'\n`);
const promptResult = await connection.prompt({
sessionId: sessionResult.sessionId,
prompt: [{ type: "text", text: promptText }],
});
process.stdout.write("\n");
if (promptResult.stopReason !== "end_turn") {
process.stderr.write(`Prompt finished with stopReason=${promptResult.stopReason}\n`);
}
// Best-effort cleanup
copilotProcess.stdin.end();
copilotProcess.kill("SIGTERM");
await new Promise<void>((resolve) => {
copilotProcess.once("exit", () => resolve());
setTimeout(() => resolve(), 2000);
});
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
Weiterführende Lektüre
-
[Offizielle ACP-Dokumentation](https://agentclientprotocol.com/protocol/overview)