@@ -36,47 +36,57 @@ Embed the agent inside another Python process without spawning your own pipes:
3636
3737``` python
3838import asyncio
39- import sys
40- from pathlib import Path
41-
42- from acp import spawn_agent_process
43- from acp.schema import InitializeRequest, NewSessionRequest, PromptRequest, TextContentBlock
44-
45-
46- async def main () -> None :
47- agent_script = Path(" examples/echo_agent.py" )
48- async with spawn_agent_process(lambda _agent : YourClient(), sys.executable, str (agent_script)) as (conn, _proc):
49- await conn.initialize(InitializeRequest(protocolVersion = 1 ))
50- session = await conn.newSession(NewSessionRequest(cwd = str (agent_script.parent), mcpServers = []))
51- await conn.prompt(
52- PromptRequest(
53- sessionId = session.sessionId,
54- prompt = [TextContentBlock(type = " text" , text = " Hello!" )],
55- )
56- )
57-
58-
59- asyncio.run(main())
60- ```
61-
62- ` spawn_client_process ` mirrors this pattern for the inverse direction.
63-
64- ### Minimal agent sketch
65-
66- ``` python
67- import asyncio
68-
69- from acp import Agent, AgentSideConnection, PromptRequest, PromptResponse, SessionNotification, stdio_streams
70- from acp.schema import AgentMessageChunk, TextContentBlock
7139
40+ from acp import (
41+ Agent,
42+ AgentSideConnection,
43+ AuthenticateRequest,
44+ AuthenticateResponse,
45+ CancelNotification,
46+ InitializeRequest,
47+ InitializeResponse,
48+ LoadSessionRequest,
49+ LoadSessionResponse,
50+ NewSessionRequest,
51+ NewSessionResponse,
52+ PromptRequest,
53+ PromptResponse,
54+ SetSessionModeRequest,
55+ SetSessionModeResponse,
56+ stdio_streams,
57+ PROTOCOL_VERSION ,
58+ )
59+ from acp.schema import (
60+ AgentCapabilities,
61+ AgentMessageChunk,
62+ McpCapabilities,
63+ PromptCapabilities,
64+ SessionNotification,
65+ TextContentBlock,
66+ )
7267
7368class EchoAgent (Agent ):
7469 def __init__ (self , conn ):
7570 self ._conn = conn
7671
72+ async def initialize (self , params : InitializeRequest) -> InitializeResponse:
73+ mcp_caps: McpCapabilities = McpCapabilities(http = False , sse = False )
74+ prompt_caps: PromptCapabilities = PromptCapabilities(audio = False , embeddedContext = False , image = False )
75+ agent_caps: AgentCapabilities = AgentCapabilities(
76+ loadSession = False ,
77+ mcpCapabilities = mcp_caps,
78+ promptCapabilities = prompt_caps,
79+ )
80+ return InitializeResponse(
81+ protocolVersion = PROTOCOL_VERSION ,
82+ agentCapabilities = agent_caps,
83+ )
84+ async def newSession (self , params : NewSessionRequest) -> NewSessionResponse:
85+ return NewSessionResponse(sessionId = " sess-1" )
86+
7787 async def prompt (self , params : PromptRequest) -> PromptResponse:
7888 for block in params.prompt:
79- text = getattr (block, " text" , " " )
89+ text = block.get( " text " , " " ) if isinstance (block, dict ) else getattr (block, " text" , " " )
8090 await self ._conn.sessionUpdate(
8191 SessionNotification(
8292 sessionId = params.sessionId,
0 commit comments