@@ -155,5 +155,93 @@ flowchart LR
155155- [ SDK Architecture] ( /sdk/arch/overview ) – Packages and modes
156156
157157---
158+
159+ ## Client SDK
160+
161+ Python examples for interacting with Agent Server:
162+
163+ ``` python
164+ # Minimal REST client using httpx (no SDK wrapper required)
165+ # Endpoints from conversation/event routers:
166+ # - POST /api/conversations/{conversation_id}/events (send message)
167+ # - GET /api/conversations/{conversation_id}/events/search (read events)
168+ # (source: event_router.py)
169+ # https://github.com/OpenHands/software-agent-sdk/blob/HEAD/openhands-agent-server/openhands/agent_server/event_router.py
170+
171+ import httpx
172+
173+ BASE_URL = " https://agent-server.example.com"
174+ API_KEY = " your-api-key"
175+ CONVERSATION_ID = " your-conversation-uuid"
176+
177+ headers = {" X-Session-API-Key" : API_KEY }
178+
179+ # Send a user message and start the agent loop
180+ send = {
181+ " role" : " user" ,
182+ " content" : [{" type" : " text" , " text" : " Hello, agent!" }],
183+ " run" : True ,
184+ }
185+ r = httpx.post(
186+ f " { BASE_URL } /api/conversations/ { CONVERSATION_ID } /events " ,
187+ json = send,
188+ headers = headers,
189+ )
190+ r.raise_for_status()
191+
192+ # Poll recent events (use WebSockets for streaming if preferred)
193+ resp = httpx.get(
194+ f " { BASE_URL } /api/conversations/ { CONVERSATION_ID } /events/search " ,
195+ headers = headers,
196+ params = {" limit" : 50 },
197+ )
198+ resp.raise_for_status()
199+ for ev in resp.json().get(" items" , []):
200+ print (ev.get(" kind" ), ev.get(" source" ))
201+ ```
202+
203+ <Note >
204+ To create a new conversation via REST, post a StartConversationRequest to ` /api/conversations ` .
205+ See the JSON example in
206+ [ conversation_router.py] ( https://github.com/OpenHands/software-agent-sdk/blob/HEAD/openhands-agent-server/openhands/agent_server/conversation_router.py )
207+ (START_CONVERSATION_EXAMPLES).
208+ </Note >
209+
210+ ### WebSocket streaming example (events)
211+
212+ ``` python
213+ # Stream conversation events over WebSocket
214+ # Endpoint: /sockets/events/{conversation_id}?session_api_key=...
215+ # (source: sockets.py)
216+ # https://github.com/OpenHands/software-agent-sdk/blob/HEAD/openhands-agent-server/openhands/agent_server/sockets.py
217+
218+ import asyncio
219+ import json
220+ import websockets
221+
222+ BASE_WS = " wss://agent-server.example.com"
223+ API_KEY = " your-api-key"
224+ CONVERSATION_ID = " your-conversation-uuid"
225+
226+ async def stream_events ():
227+ ws_url = (
228+ f " { BASE_WS } /sockets/events/ { CONVERSATION_ID } "
229+ f " ?session_api_key= { API_KEY } &resend_all=false "
230+ )
231+ async with websockets.connect(ws_url) as ws:
232+ while True :
233+ raw = await ws.recv()
234+ event = json.loads(raw)
235+ print (event.get(" kind" ), event.get(" source" ))
236+
237+ asyncio.run(stream_events())
238+ ```
239+
240+ <Note >
241+ WebSockets require passing the session key as a query parameter
242+ (` session_api_key ` ). See
243+ [ sockets.py] ( https://github.com/OpenHands/software-agent-sdk/blob/HEAD/openhands-agent-server/openhands/agent_server/sockets.py ) .
244+ </Note >
245+
158246Last updated: 2025-12-09 06:57 UTC
159247Source commit (software-agent-sdk): ` 93d405c9 `
0 commit comments