Skip to content

xenodium/acp.el

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

acp.el

This project needs your funding

As you pay for those useful LLM tokens, consider sponsoring development and maintenance of this project.

acp.el enables us to build better integrations and tools into our beloved Emacs text editor. With your help, I can make this effort more sustainable.

Thank you!

Alvaro

acp.el

acp.el implements the Agent Client Protocol (ACP) for Emacs as per agentclientprotocol.com.

ACP is a standardized protocol for communicating with LLM agents like Gemini CLI, Claude Code, etc.

Note: This package is in the very early stages, isn’t yet API stable, and is bound to change.

Install

Prerequisites

Install an LLM agent command-line tool like:

Package Installation

Clone the repository and add to your Emacs load path:

(add-to-list 'load-path "/path/to/acp.el/")
(require 'acp)

Sample Usage

Initialization

(setq client (acp-make-client :command "gemini"
                              :command-params '("--experimental-acp")
                              :environment-variables (when api-key
                                                       (list (format "GEMINI_API_KEY=%s" "your-api-key")))))

(acp-send-request
 :client client
 :request (acp-make-initialize-request :protocol-version 1)
 :on-success (lambda (response)
               (message "Initialize success: %s" response))
 :on-failure (lambda (error)
               (message "Initialize failed: %s" error)))

Initialize success:

((protocolVersion . 1)
 (authMethods . [((id . oauth-personal)
                  (name . Log in with Google)
                  (description . :null))
                 ((id . gemini-api-key)
                  (name . Use Gemini API key)
                  (description . Requires setting the `GEMINI_API_KEY` environment variable))
                 ((id . vertex-ai)
                  (name . Vertex AI)
                  (description . :null))])
 (agentCapabilities (loadSession . :false)
                    (promptCapabilities (image . t)
                                        (audio . t)
                                        (embeddedContext . t))))

Typically, you’d need to send a sequence of requests before you can send the agent prompts to interact with:

  1. acp-make-initialize-request
  2. acp-make-authenticate-request (not needed for Claude Code)
  3. acp-make-session-new-request

You may now send the agent prompts with:

  1. acp-make-session-prompt-request

Subscriptions

(acp-subscribe-to-requests client
                           (lambda (request)
                             (message "Received request: %s" request)))

(acp-subscribe-to-notifications client
                                (lambda (notification)
                                  (message "Received notification: %s" notification)))

Cleanup

(acp-shutdown client)

Logging

Logging can be enabled via:

(setq acp-logging-enabled t)

Look out for *acp log* and *acp traffic* buffers.

The *acp traffic* is particularly useful to inspecting incomng or outgoing traffic.

traffic.gif

APIs

acp-logs-bufferGet CLIENT logs buffer.
acp-make-authenticate-requestInstantiate an “authenticate” request.
acp-make-claude-clientCreate Claude Code ACP client with API-KEY.
acp-make-clientCreate an ACP client.
acp-make-gemini-clientCreate a Gemini ACP client with API-KEY.
acp-make-initialize-requestInstantiate an “initialize” request.
acp-make-session-cancel-requestInstantiate a “session/cancel” request.
acp-make-session-new-requestInstantiate a “session/new” request.
acp-make-session-prompt-requestInstantiate an “session/prompt” request.
acp-make-session-request-permission-responseInstantiate a “session/request_permission” response.
acp-reset-logsReset CLIENT log buffers.
acp-send-requestSend REQUEST from CLIENT.
acp-send-responseSend a request RESPONSE from CLIENT.
acp-shutdownShutdown ACP CLIENT and release resources.
acp-subscribe-to-errorsSubscribe to agent errors using CLIENT.
acp-subscribe-to-notificationsSubscribe to incoming CLIENT notifications.
acp-subscribe-to-requestsSubscribe to incoming CLIENT requests.

FAQ

Why not use jsonrpc.el?

That was my initial intention, though it doesn’t seem possible with Content-Length automatically appended to requests sent. If you do know of a way, I’d love to know.

About

An ACP (Agent Client Protocol) implementation in Emacs lisp as per https://agentclientprotocol.com

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published