refactor: simplify web transports with Starlette - #142
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The HTTP and WebSocket servers currently route agent messages through an in-memory transport pair, pump tasks, a connection registry, and WebSocket multiplex queues, while maintaining a hand-written ASGI adapter. This change connects both transports directly to
AgentSideConnectionand delegates HTTP/ASGI handling to Starlette.ConnectionRegistry/ConnectionStatewith a connection dictionary and a direct HTTP transport. Keep session routing, bounded SSE buffers, backpressure, keepalives, and cancellation cleanup; use one Future for initialization.[http]extra; core/stdio imports remain independent of web dependencies.create_asgi_app(agent_factory, *, path="/acp"), sharing the configured route between HTTP and WebSocket, including when mounted under a parent application. Method dispatch follows Starlette routing without a separate check in_get.Experimental API changes:
create_asgi_app()returns a Starlette app;AcpServerhandlers return Starlette responses. RemoveAcpAsgiApp,PostResult, the registry/state helpers, andcreate_websocket_connection(). Direct WebSocket integrations usehandle_websocket(agent_factory, websocket). The default/acproute replaces the previous catch-all route.session/loadnow works over HTTP without requiring asessionIdin its response. Correlate the request ID, keep replay and completion on the connection SSE stream, and provision the session stream for continued prompts. Failed loads clean up provisional streams while preserving existing sessions and overlapping loads. Cover empty/null responses, 1100-message histories, repeated loads, retry after failure, and permission callbacks over HTTP and WebSocket. Agent load responses and capability advertisement are preserved.Related issues
No linked issue.
Testing
make test: 256 passed, 1 skipped (optional Gemini test).make check: lockfile consistency, pre-commit/Ruff, ty, and deptry passed.Docs & screenshots
Updated
docs/web-transport.mdwith the simplified architecture, ablation results, API changes, custom paths, and parent/child lifespan mounting example. Updated the HTTP server example. No schema regeneration or screenshots required.Checklist
feat:,fix:).make gen-all) are called out if applicable (none).