@@ -25,31 +25,53 @@ make test # run tests
2525## Minimal agent example
2626
2727``` python
28- # agent_main.py
2928import asyncio
30- from acp import Agent, AgentSideConnection, Client, InitializeRequest, InitializeResponse, PromptRequest, PromptResponse, SessionNotification, stdio_streams, PROTOCOL_VERSION
31- from acp.schema import ContentBlock1, SessionUpdate2
29+
30+ from acp import (
31+ Agent,
32+ AgentSideConnection,
33+ AuthenticateRequest,
34+ CancelNotification,
35+ InitializeRequest,
36+ InitializeResponse,
37+ LoadSessionRequest,
38+ NewSessionRequest,
39+ NewSessionResponse,
40+ PromptRequest,
41+ PromptResponse,
42+ stdio_streams,
43+ )
44+
3245
3346class EchoAgent (Agent ):
34- def __init__ (self , client : Client) -> None :
35- self .client = client
36-
37- async def initialize (self , _p : InitializeRequest) -> InitializeResponse:
38- return InitializeResponse(protocolVersion = PROTOCOL_VERSION )
39-
40- async def prompt (self , p : PromptRequest) -> PromptResponse:
41- text = " " .join([getattr (b, " text" , " " ) for b in p.prompt if getattr (b, " type" , None ) == " text" ]) or " (empty)"
42- await self .client.sessionUpdate(SessionNotification(
43- sessionId = p.sessionId,
44- update = SessionUpdate2(sessionUpdate = " agent_message_chunk" , content = ContentBlock1(type = " text" , text = f " Echo: { text} " )),
45- ))
47+ async def initialize (self , params : InitializeRequest) -> InitializeResponse:
48+ return InitializeResponse(protocolVersion = params.protocolVersion)
49+
50+ async def newSession (self , params : NewSessionRequest) -> NewSessionResponse:
51+ return NewSessionResponse(sessionId = " sess-1" )
52+
53+ async def loadSession (self , params : LoadSessionRequest) -> None :
54+ return None
55+
56+ async def authenticate (self , params : AuthenticateRequest) -> None :
57+ return None
58+
59+ async def prompt (self , params : PromptRequest) -> PromptResponse:
60+ # Normally you'd stream updates via sessionUpdate
4661 return PromptResponse(stopReason = " end_turn" )
4762
63+ async def cancel (self , params : CancelNotification) -> None :
64+ return None
65+
66+
4867async def main () -> None :
4968 reader, writer = await stdio_streams()
50- AgentSideConnection(lambda c : EchoAgent(c), writer, reader)
69+ # For an agent process, local writes go to client stdin (writer=stdout)
70+ AgentSideConnection(lambda _conn : EchoAgent(), writer, reader)
71+ # Keep running; in a real agent you would await tasks or add your own loop
5172 await asyncio.Event().wait()
5273
74+
5375if __name__ == " __main__" :
5476 asyncio.run(main())
5577```
0 commit comments