[Python] Update the signatures of CopilotSession.send() and send_and_wait()#814
[Python] Update the signatures of CopilotSession.send() and send_and_wait()#814brettcannon wants to merge 1 commit intogithub:mainfrom
CopilotSession.send() and send_and_wait()#814Conversation
There was a problem hiding this comment.
Pull request overview
Updates the Python SDK message-sending API to use explicit parameters (prompt, attachments, mode, timeout) instead of a MessageOptions dict, and migrates in-repo callers to the new signatures.
Changes:
- Changed
CopilotSession.send()/send_and_wait()signatures to takepromptplus keyword-onlyattachments/mode(andtimeoutforsend_and_wait). - Removed the
MessageOptionsTypedDict and stopped exporting it from the Python package. - Updated Python E2E tests, samples, and scenario scripts to call the new APIs (including attachment usage).
Reviewed changes
Copilot reviewed 48 out of 48 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/scenarios/transport/tcp/python/main.py | Update scenario to call send_and_wait(prompt) with a string prompt. |
| test/scenarios/transport/stdio/python/main.py | Update scenario to call send_and_wait(prompt) with a string prompt. |
| test/scenarios/transport/reconnect/python/main.py | Update reconnect scenario to use new send_and_wait(prompt) signature in both sessions. |
| test/scenarios/tools/virtual-filesystem/python/main.py | Update tool scenario to pass prompt as a string (multi-line literal concatenation). |
| test/scenarios/tools/tool-overrides/python/main.py | Update to send_and_wait(prompt) string form. |
| test/scenarios/tools/tool-filtering/python/main.py | Update to send_and_wait(prompt) string form. |
| test/scenarios/tools/skills/python/main.py | Update to send_and_wait(prompt) string form. |
| test/scenarios/tools/no-tools/python/main.py | Update to send_and_wait(prompt) string form. |
| test/scenarios/tools/mcp-servers/python/main.py | Update to send_and_wait(prompt) string form. |
| test/scenarios/tools/custom-agents/python/main.py | Update to send_and_wait(prompt) string form. |
| test/scenarios/sessions/streaming/python/main.py | Update streaming session scenario to use new send_and_wait(prompt) call. |
| test/scenarios/sessions/session-resume/python/main.py | Update resume scenario to use new send_and_wait(prompt) calls. |
| test/scenarios/sessions/infinite-sessions/python/main.py | Update looped prompts to call send_and_wait(prompt) directly. |
| test/scenarios/sessions/concurrent-sessions/python/main.py | Update concurrent gather calls to use send_and_wait(prompt) string form. |
| test/scenarios/prompts/system-message/python/main.py | Update prompt scenario to use new send_and_wait(prompt) call. |
| test/scenarios/prompts/reasoning-effort/python/main.py | Update prompt scenario to use new send_and_wait(prompt) call. |
| test/scenarios/prompts/attachments/python/main.py | Update attachment scenario to use send_and_wait(prompt, attachments=...). |
| test/scenarios/modes/minimal/python/main.py | Update minimal mode scenario to use send_and_wait(prompt) string form. |
| test/scenarios/modes/default/python/main.py | Update default mode scenario to use send_and_wait(prompt) string form. |
| test/scenarios/callbacks/user-input/python/main.py | Update callback scenario prompt call to string form. |
| test/scenarios/callbacks/permissions/python/main.py | Update callback scenario prompt call to string form. |
| test/scenarios/callbacks/hooks/python/main.py | Update hook callback scenario prompt call to string form. |
| test/scenarios/bundling/fully-bundled/python/main.py | Update bundled scenario to use new send_and_wait(prompt) call. |
| test/scenarios/bundling/container-proxy/python/main.py | Update proxy bundling scenario to use new send_and_wait(prompt) call. |
| test/scenarios/bundling/app-direct-server/python/main.py | Update direct-server scenario to use new send_and_wait(prompt) call. |
| test/scenarios/bundling/app-backend-to-server/python/main.py | Update backend-to-server scenario helper to call send_and_wait(prompt) directly. |
| test/scenarios/auth/gh-app/python/main.py | Update GH App auth scenario to use new send_and_wait(prompt) call. |
| test/scenarios/auth/byok-openai/python/main.py | Update BYOK OpenAI scenario to use new send_and_wait(prompt) call. |
| test/scenarios/auth/byok-ollama/python/main.py | Update BYOK Ollama scenario to use new send_and_wait(prompt) call. |
| test/scenarios/auth/byok-azure/python/main.py | Update BYOK Azure scenario to use new send_and_wait(prompt) call. |
| test/scenarios/auth/byok-anthropic/python/main.py | Update BYOK Anthropic scenario to use new send_and_wait(prompt) call. |
| python/samples/chat.py | Update interactive sample to call send_and_wait(user_input) directly. |
| python/e2e/test_tools.py | Update E2E tool tests to call send(prompt) / send_and_wait(prompt) with strings. |
| python/e2e/test_streaming_fidelity.py | Update streaming fidelity tests to use send_and_wait(prompt) string form. |
| python/e2e/test_skills.py | Update skill tests to use send_and_wait(prompt) string form. |
| python/e2e/test_session.py | Update session tests to use new send(prompt) / send_and_wait(prompt) calls. |
| python/e2e/test_permissions.py | Update permission tests to use new send(prompt) / send_and_wait(prompt) calls. |
| python/e2e/test_multi_client.py | Update multi-client tests to use new send(prompt) signature (string prompts). |
| python/e2e/test_mcp_and_agents.py | Update MCP/agents tests to use new send(prompt) / send_and_wait(prompt) calls. |
| python/e2e/test_hooks.py | Update hooks tests to use send_and_wait(prompt) string form. |
| python/e2e/test_compaction.py | Update compaction tests to use send_and_wait(prompt) string form. |
| python/e2e/test_ask_user.py | Update ask_user tests to use send_and_wait(prompt) string form. |
| python/e2e/test_agent_and_compact_rpc.py | Update agent/compact RPC test to use send_and_wait(prompt) string form. |
| python/copilot/types.py | Remove MessageOptions TypedDict from types module. |
| python/copilot/session.py | Implement new send(prompt, *, attachments, mode) and send_and_wait(prompt, *, attachments, mode, timeout) signatures. |
| python/copilot/client.py | Update docstrings/examples to use session.send("...") string form. |
| python/copilot/init.py | Stop exporting MessageOptions from top-level package exports. |
| python/README.md | Update README examples to use the new string-based send API and keyword attachments. |
| """ | ||
| Send a message to this session and wait for the response. | ||
|
|
||
| The message is processed asynchronously. Subscribe to events via :meth:`on` | ||
| to receive streaming responses and other session events. |
There was a problem hiding this comment.
CopilotSession.send() returns immediately with a messageId and does not wait for the assistant to finish processing. The docstring currently says it "wait[s] for the response", which reads like it blocks until an assistant message is produced; consider rewording the first line to clarify it only sends/queues the message and returns the server message id (completion arrives via events or send_and_wait).
| async def send( | ||
| self, | ||
| prompt: str, | ||
| *, | ||
| attachments: list[Any] | None = None, | ||
| mode: str | None = None, | ||
| ) -> str: |
There was a problem hiding this comment.
The new attachments and mode parameters are typed as list[Any] and str, but this repo already defines a strongly-typed Attachment union in python/copilot/types.py. Using attachments: list[Attachment] | None and mode: Literal["enqueue", "immediate"] | None (or a named alias) would preserve type-safety for callers and make it harder to pass invalid values.
|
@brettcannon The updated signatures look better though the following Copilot comment also looks valid:
Can we strengthen the types for those params? |
Yep! I also plan to do a full "strengthen typing" pass at some point (waiting until all the API changes lant). |
No description provided.