feat: Redesign the APIs to be more intuitive, and make them backward-compatible #37
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
Note
This PR is stacked on #36 and should not be merged before that one.
As title
Related issues
Previously, the agent-side and client-side APIs are rather symmetric, making it confusing when choosing which connection should be used. For me it takes me a while to understand
AgentSideConnectionis created by agent but exposes the same API set as the client. Moreover, the fact it taking a callable as first parameter is not very Pythonic to me, because in Python you have to pass it via a lambda.So I added two new APIs to replace the two connection classes, while the latter should be considered an implementation detail.
run_agent(agent), called by agent developers, to start listening to client requests. It will block until cancelled or error, similar toserver.listen(), which users are more familiar with.connect_to_agent(client), called by client, to create a connection(ClientSideConnection) to the agent and it can be used like an agentThe first argument takes an agent or client instance respectively, rather than a callable. If the agent or client depends on the connection for interoperability, it should define a method
def on_connect, which will be called by the connection's__init__method if possible. See the change inexample/echo_agent.pyfor how it looks like.In the meantime,
ClientSideConnectionandAgentSideConnectionare deprecated as public APIs. Users importing it from the top level module will see a warning.A migration guide is good to add, this is on the To-do list. A migration guide is added.It's 100% backward-compatible, I wrote a new test file
test_compatibility.pyto ensure it.Testing
Docs & screenshots
Checklist
feat:,fix:).make gen-all) are called out if applicable.