Skip to content

Commit f95f268

Browse files
author
Chojan Shang
committed
Deployed 927f558 with MkDocs version: 1.6.1
1 parent b83514c commit f95f268

File tree

7 files changed

+215
-143
lines changed

7 files changed

+215
-143
lines changed

404.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,12 @@
295295

296296

297297
<li class="md-nav__item">
298-
<a href="/agent-client-protocol-python/mini-swe-agent/" class="md-nav__link">
298+
<a href="/agent-client-protocol-python/releasing/" class="md-nav__link">
299299

300300

301301

302302
<span class="md-ellipsis">
303-
Mini SWE Agent
303+
Releasing
304304

305305
</span>
306306

index.html

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,15 @@
325325
</span>
326326
</a>
327327

328+
</li>
329+
330+
<li class="md-nav__item">
331+
<a href="#gemini-cli-bridge" class="md-nav__link">
332+
<span class="md-ellipsis">
333+
Gemini CLI bridge
334+
</span>
335+
</a>
336+
328337
</li>
329338

330339
<li class="md-nav__item">
@@ -373,12 +382,12 @@
373382

374383

375384
<li class="md-nav__item">
376-
<a href="mini-swe-agent/" class="md-nav__link">
385+
<a href="releasing/" class="md-nav__link">
377386

378387

379388

380389
<span class="md-ellipsis">
381-
Mini SWE Agent
390+
Releasing
382391

383392
</span>
384393

@@ -430,6 +439,15 @@
430439
</span>
431440
</a>
432441

442+
</li>
443+
444+
<li class="md-nav__item">
445+
<a href="#gemini-cli-bridge" class="md-nav__link">
446+
<span class="md-ellipsis">
447+
Gemini CLI bridge
448+
</span>
449+
</a>
450+
433451
</li>
434452

435453
<li class="md-nav__item">
@@ -460,13 +478,18 @@
460478

461479

462480

481+
<p><a href="https://agentclientprotocol.com/" >
482+
<img alt="Agent Client Protocol" src="https://zed.dev/img/acp/banner-dark.webp">
483+
</a></p>
463484
<h1 id="agent-client-protocol-sdk-python">Agent Client Protocol SDK (Python)<a class="headerlink" href="#agent-client-protocol-sdk-python" title="Permanent link">&para;</a></h1>
464485
<p>Welcome to the Python SDK for the Agent Client Protocol (ACP). The package ships ready-to-use transports, typed protocol models, and examples that stream messages to ACP-aware clients such as Zed.</p>
465486
<h2 id="what-you-get">What you get<a class="headerlink" href="#what-you-get" title="Permanent link">&para;</a></h2>
466487
<ul>
467-
<li>Fully typed dataclasses generated from the upstream ACP schema (<code>acp.schema</code>)</li>
468-
<li>Async agent base class and stdio helpers to spin up an agent in a few lines</li>
469-
<li>Examples that demonstrate streaming updates and tool execution over ACP</li>
488+
<li>Pydantic models generated from the upstream ACP schema (<code>acp.schema</code>)</li>
489+
<li>Async agent/client wrappers with JSON-RPC task supervision built in</li>
490+
<li>Process helpers (<code>spawn_agent_process</code>, <code>spawn_client_process</code>) for embedding ACP nodes inside Python applications</li>
491+
<li>Helper APIs in <code>acp.helpers</code> that mirror the Go/TS SDK builders for content blocks, tool calls, and session updates. They instantiate the generated Pydantic types for you, so call sites stay concise without sacrificing validation.</li>
492+
<li>Examples that showcase streaming updates, file operations, permission flows, and even a Gemini CLI bridge (<code>examples/gemini.py</code>)</li>
470493
</ul>
471494
<h2 id="getting-started">Getting started<a class="headerlink" href="#getting-started" title="Permanent link">&para;</a></h2>
472495
<ol>
@@ -478,11 +501,22 @@ <h2 id="getting-started">Getting started<a class="headerlink" href="#getting-sta
478501
python examples/echo_agent.py</code></li>
479502
<li>Point your ACP-capable client at the running process (for Zed, configure an Agent Server entry). The SDK takes care of JSON-RPC framing and lifecycle transitions.</li>
480503
</ol>
481-
<p>Prefer a guided tour? Head to the <a href="quickstart/">Quickstart</a> for step-by-step instructions, including how to run the agent from an editor or terminal.</p>
504+
<p>Prefer a guided tour? Head to the <a href="quickstart/">Quickstart</a> for terminal, editor, and programmatic launch walkthroughs.</p>
505+
<h2 id="gemini-cli-bridge">Gemini CLI bridge<a class="headerlink" href="#gemini-cli-bridge" title="Permanent link">&para;</a></h2>
506+
<p>If you have access to the Gemini CLI (<code>gemini --experimental-acp</code>), run:</p>
507+
<pre><code class="language-bash">python examples/gemini.py --yolo
508+
</code></pre>
509+
<p>Flags mirror the Go SDK example:</p>
510+
<ul>
511+
<li><code>--gemini /path/to/cli</code> or <code>ACP_GEMINI_BIN</code> to override discovery</li>
512+
<li><code>--model</code>, <code>--sandbox</code>, <code>--debug</code> forwarded verbatim</li>
513+
<li><code>--yolo</code> auto-approves permission prompts with sensible defaults</li>
514+
</ul>
515+
<p>An opt-in smoke test lives at <code>tests/test_gemini_example.py</code>. Enable it with <code>ACP_ENABLE_GEMINI_TESTS=1</code> (and optionally <code>ACP_GEMINI_TEST_ARGS</code>) when the CLI is authenticated; otherwise the test stays skipped.</p>
482516
<h2 id="documentation-map">Documentation map<a class="headerlink" href="#documentation-map" title="Permanent link">&para;</a></h2>
483517
<ul>
484-
<li><a href="quickstart/">Quickstart</a>: install, run, and extend the echo agent</li>
485-
<li><a href="mini-swe-agent/">Mini SWE Agent guide</a>: bridge mini-swe-agent over ACP, including duet launcher and Textual client</li>
518+
<li><a href="quickstart/">Quickstart</a>: install, run, and embed the echo agent, plus next steps for extending it</li>
519+
<li><a href="releasing/">Releasing</a>: schema upgrade workflow, version bumps, and publishing checklist</li>
486520
</ul>
487521
<p>Source code lives under <code>src/acp/</code>, while tests and additional examples are available in <code>tests/</code> and <code>examples/</code>. If you plan to contribute, see the repository README for the development workflow.</p>
488522

quickstart/index.html

Lines changed: 102 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<link rel="prev" href="..">
1919

2020

21-
<link rel="next" href="../mini-swe-agent/">
21+
<link rel="next" href="../releasing/">
2222

2323

2424
<link rel="icon" href="../assets/images/favicon.png">
@@ -352,22 +352,22 @@
352352
</li>
353353

354354
<li class="md-nav__item">
355-
<a href="#2-run-the-echo-agent" class="md-nav__link">
355+
<a href="#2-launch-the-echo-agent-terminal" class="md-nav__link">
356356
<span class="md-ellipsis">
357-
2. Run the echo agent
357+
2. Launch the Echo agent (terminal)
358358
</span>
359359
</a>
360360

361361
</li>
362362

363363
<li class="md-nav__item">
364-
<a href="#3-connect-from-your-client" class="md-nav__link">
364+
<a href="#3-connect-from-an-editor" class="md-nav__link">
365365
<span class="md-ellipsis">
366-
3. Connect from your client
366+
3. Connect from an editor
367367
</span>
368368
</a>
369369

370-
<nav class="md-nav" aria-label="3. Connect from your client">
370+
<nav class="md-nav" aria-label="3. Connect from an editor">
371371
<ul class="md-nav__list">
372372

373373
<li class="md-nav__item">
@@ -386,6 +386,15 @@
386386
</span>
387387
</a>
388388

389+
</li>
390+
391+
<li class="md-nav__item">
392+
<a href="#programmatic-launch" class="md-nav__link">
393+
<span class="md-ellipsis">
394+
Programmatic launch
395+
</span>
396+
</a>
397+
389398
</li>
390399

391400
</ul>
@@ -403,9 +412,9 @@
403412
</li>
404413

405414
<li class="md-nav__item">
406-
<a href="#optional-mini-swe-agent-bridge" class="md-nav__link">
415+
<a href="#5-optional-talk-to-the-gemini-cli" class="md-nav__link">
407416
<span class="md-ellipsis">
408-
Optional: Mini SWE Agent bridge
417+
5. Optional: Talk to the Gemini CLI
409418
</span>
410419
</a>
411420

@@ -426,12 +435,12 @@
426435

427436

428437
<li class="md-nav__item">
429-
<a href="../mini-swe-agent/" class="md-nav__link">
438+
<a href="../releasing/" class="md-nav__link">
430439

431440

432441

433442
<span class="md-ellipsis">
434-
Mini SWE Agent
443+
Releasing
435444

436445
</span>
437446

@@ -486,22 +495,22 @@
486495
</li>
487496

488497
<li class="md-nav__item">
489-
<a href="#2-run-the-echo-agent" class="md-nav__link">
498+
<a href="#2-launch-the-echo-agent-terminal" class="md-nav__link">
490499
<span class="md-ellipsis">
491-
2. Run the echo agent
500+
2. Launch the Echo agent (terminal)
492501
</span>
493502
</a>
494503

495504
</li>
496505

497506
<li class="md-nav__item">
498-
<a href="#3-connect-from-your-client" class="md-nav__link">
507+
<a href="#3-connect-from-an-editor" class="md-nav__link">
499508
<span class="md-ellipsis">
500-
3. Connect from your client
509+
3. Connect from an editor
501510
</span>
502511
</a>
503512

504-
<nav class="md-nav" aria-label="3. Connect from your client">
513+
<nav class="md-nav" aria-label="3. Connect from an editor">
505514
<ul class="md-nav__list">
506515

507516
<li class="md-nav__item">
@@ -520,6 +529,15 @@
520529
</span>
521530
</a>
522531

532+
</li>
533+
534+
<li class="md-nav__item">
535+
<a href="#programmatic-launch" class="md-nav__link">
536+
<span class="md-ellipsis">
537+
Programmatic launch
538+
</span>
539+
</a>
540+
523541
</li>
524542

525543
</ul>
@@ -537,9 +555,9 @@
537555
</li>
538556

539557
<li class="md-nav__item">
540-
<a href="#optional-mini-swe-agent-bridge" class="md-nav__link">
558+
<a href="#5-optional-talk-to-the-gemini-cli" class="md-nav__link">
541559
<span class="md-ellipsis">
542-
Optional: Mini SWE Agent bridge
560+
5. Optional: Talk to the Gemini CLI
543561
</span>
544562
</a>
545563

@@ -576,12 +594,12 @@ <h2 id="1-install-the-sdk">1. Install the SDK<a class="headerlink" href="#1-inst
576594
# or
577595
uv add agent-client-protocol
578596
</code></pre>
579-
<h2 id="2-run-the-echo-agent">2. Run the echo agent<a class="headerlink" href="#2-run-the-echo-agent" title="Permanent link">&para;</a></h2>
580-
<p>Launch the ready-made echo example, which streams text blocks back over ACP:</p>
597+
<h2 id="2-launch-the-echo-agent-terminal">2. Launch the Echo agent (terminal)<a class="headerlink" href="#2-launch-the-echo-agent-terminal" title="Permanent link">&para;</a></h2>
598+
<p>Start the ready-made echo example — it streams text blocks back to any ACP client:</p>
581599
<pre><code class="language-bash">python examples/echo_agent.py
582600
</code></pre>
583-
<p>Keep it running while you connect your client.</p>
584-
<h2 id="3-connect-from-your-client">3. Connect from your client<a class="headerlink" href="#3-connect-from-your-client" title="Permanent link">&para;</a></h2>
601+
<p>Leave this process running while you connect from an editor or another program.</p>
602+
<h2 id="3-connect-from-an-editor">3. Connect from an editor<a class="headerlink" href="#3-connect-from-an-editor" title="Permanent link">&para;</a></h2>
585603
<h3 id="zed">Zed<a class="headerlink" href="#zed" title="Permanent link">&para;</a></h3>
586604
<p>Add an Agent Server entry in <code>settings.json</code> (Zed → Settings → Agents panel):</p>
587605
<pre><code class="language-json">{
@@ -598,6 +616,39 @@ <h3 id="zed">Zed<a class="headerlink" href="#zed" title="Permanent link">&para;<
598616
<p>Open the Agents panel and start the session. Each message you send should be echoed back via streamed <code>session/update</code> notifications.</p>
599617
<h3 id="other-clients">Other clients<a class="headerlink" href="#other-clients" title="Permanent link">&para;</a></h3>
600618
<p>Any ACP client that communicates over stdio can spawn the same script; no additional transport configuration is required.</p>
619+
<h3 id="programmatic-launch">Programmatic launch<a class="headerlink" href="#programmatic-launch" title="Permanent link">&para;</a></h3>
620+
<pre><code class="language-python">import asyncio
621+
import sys
622+
from pathlib import Path
623+
624+
from acp import spawn_agent_process, text_block
625+
from acp.interfaces import Client
626+
from acp.schema import InitializeRequest, NewSessionRequest, PromptRequest, SessionNotification
627+
628+
629+
class SimpleClient(Client):
630+
async def requestPermission(self, params): # pragma: no cover - minimal stub
631+
return {&quot;outcome&quot;: {&quot;outcome&quot;: &quot;cancelled&quot;}}
632+
633+
async def sessionUpdate(self, params: SessionNotification) -&gt; None:
634+
print(&quot;update:&quot;, params.sessionId, params.update)
635+
636+
637+
async def main() -&gt; None:
638+
script = Path(&quot;examples/echo_agent.py&quot;)
639+
async with spawn_agent_process(lambda _agent: SimpleClient(), sys.executable, str(script)) as (conn, _proc):
640+
await conn.initialize(InitializeRequest(protocolVersion=1))
641+
session = await conn.newSession(NewSessionRequest(cwd=str(script.parent), mcpServers=[]))
642+
await conn.prompt(
643+
PromptRequest(
644+
sessionId=session.sessionId,
645+
prompt=[text_block(&quot;Hello from spawn!&quot;)],
646+
)
647+
)
648+
649+
asyncio.run(main())
650+
</code></pre>
651+
<p><code>spawn_agent_process</code> manages the child process, wires its stdio into ACP framing, and closes everything when the block exits. The mirror helper <code>spawn_client_process</code> lets you drive an ACP client from Python as well.</p>
601652
<h2 id="4-extend-the-agent">4. Extend the agent<a class="headerlink" href="#4-extend-the-agent" title="Permanent link">&para;</a></h2>
602653
<p>Create your own agent by subclassing <code>acp.Agent</code>. The pattern mirrors the echo example:</p>
603654
<pre><code class="language-python">from acp import Agent, PromptRequest, PromptResponse
@@ -608,16 +659,36 @@ <h2 id="4-extend-the-agent">4. Extend the agent<a class="headerlink" href="#4-ex
608659
# inspect params.prompt, stream updates, then finish the turn
609660
return PromptResponse(stopReason=&quot;end_turn&quot;)
610661
</code></pre>
611-
<p>Hook it up with <code>AgentSideConnection</code> inside an async entrypoint and wire it to your client. Refer to <a href="https://github.com/psiace/agent-client-protocol-python/blob/main/examples/echo_agent.py">examples/echo_agent.py</a> for the complete structure, including lifetime hooks (<code>initialize</code>, <code>newSession</code>) and streaming responses.</p>
612-
<h2 id="optional-mini-swe-agent-bridge">Optional: Mini SWE Agent bridge<a class="headerlink" href="#optional-mini-swe-agent-bridge" title="Permanent link">&para;</a></h2>
613-
<p>The repository also ships a bridge for <a href="https://github.com/groundx-ai/mini-swe-agent">mini-swe-agent</a>. To try it:</p>
614-
<ol>
615-
<li>Install the dependency:
616-
<code>bash
617-
pip install mini-swe-agent</code></li>
618-
<li>Configure Zed to run <code>examples/mini_swe_agent/agent.py</code> and supply environment variables such as <code>MINI_SWE_MODEL</code> and <code>OPENROUTER_API_KEY</code>.</li>
619-
<li>Review the <a href="../mini-swe-agent/">Mini SWE Agent guide</a> for environment options, tool-call mapping, and a duet launcher that starts both the bridge and a Textual client (<code>python examples/mini_swe_agent/duet.py</code>).</li>
620-
</ol>
662+
<p>Hook it up with <code>AgentSideConnection</code> inside an async entrypoint and wire it to your client. Refer to:</p>
663+
<ul>
664+
<li><a href="https://github.com/psiace/agent-client-protocol-python/blob/main/examples/echo_agent.py"><code>examples/echo_agent.py</code></a> for the smallest streaming agent</li>
665+
<li><a href="https://github.com/psiace/agent-client-protocol-python/blob/main/examples/agent.py"><code>examples/agent.py</code></a> for an implementation that negotiates capabilities and streams richer updates</li>
666+
<li><a href="https://github.com/psiace/agent-client-protocol-python/blob/main/examples/duet.py"><code>examples/duet.py</code></a> to see <code>spawn_agent_process</code> in action alongside the interactive client</li>
667+
<li><a href="https://github.com/psiace/agent-client-protocol-python/blob/main/examples/gemini.py"><code>examples/gemini.py</code></a> to drive the Gemini CLI (<code>--experimental-acp</code>) directly from Python</li>
668+
</ul>
669+
<p>Need builders for common payloads? <code>acp.helpers</code> mirrors the Go/TS helper APIs:</p>
670+
<pre><code class="language-python">from acp import start_tool_call, update_tool_call, text_block, tool_content
671+
672+
start_update = start_tool_call(&quot;call-42&quot;, &quot;Open file&quot;, kind=&quot;read&quot;, status=&quot;pending&quot;)
673+
finish_update = update_tool_call(
674+
&quot;call-42&quot;,
675+
status=&quot;completed&quot;,
676+
content=[tool_content(text_block(&quot;File opened.&quot;))],
677+
)
678+
</code></pre>
679+
<p>Each helper wraps the generated Pydantic models in <code>acp.schema</code>, so the right discriminator fields (<code>type</code>, <code>sessionUpdate</code>, and friends) are always populated. That keeps examples readable while maintaining the same validation guarantees as constructing the models directly. Golden fixtures in <code>tests/test_golden.py</code> ensure the helpers stay in sync with future schema revisions.</p>
680+
<h2 id="5-optional-talk-to-the-gemini-cli">5. Optional: Talk to the Gemini CLI<a class="headerlink" href="#5-optional-talk-to-the-gemini-cli" title="Permanent link">&para;</a></h2>
681+
<p>If you have the Gemini CLI installed and authenticated:</p>
682+
<pre><code class="language-bash">python examples/gemini.py --yolo # auto-approve permission prompts
683+
python examples/gemini.py --sandbox --model gemini-1.5-pro
684+
</code></pre>
685+
<p>Environment helpers:</p>
686+
<ul>
687+
<li><code>ACP_GEMINI_BIN</code> — override the CLI path (defaults to <code>PATH</code> lookup)</li>
688+
<li><code>ACP_GEMINI_TEST_ARGS</code> — extra flags forwarded during the smoke test</li>
689+
<li><code>ACP_ENABLE_GEMINI_TESTS=1</code> — opt-in toggle for <code>tests/test_gemini_example.py</code></li>
690+
</ul>
691+
<p>Authentication hiccups (e.g. missing <code>GOOGLE_CLOUD_PROJECT</code>) are surfaced but treated as skips during testing so the suite stays green on machines without credentials.</p>
621692

622693

623694

0 commit comments

Comments
 (0)