Skip to content

[Python] Update the signatures of CopilotSession.send() and send_and_wait()#814

Open
brettcannon wants to merge 1 commit intogithub:mainfrom
brettcannon:client.session.send
Open

[Python] Update the signatures of CopilotSession.send() and send_and_wait()#814
brettcannon wants to merge 1 commit intogithub:mainfrom
brettcannon:client.session.send

Conversation

@brettcannon
Copy link
Contributor

No description provided.

@brettcannon brettcannon requested a review from a team as a code owner March 12, 2026 22:47
Copilot AI review requested due to automatic review settings March 12, 2026 22:47
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 take prompt plus keyword-only attachments/mode (and timeout for send_and_wait).
  • Removed the MessageOptions TypedDict 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.

Comment on lines 124 to 128
"""
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.
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Comment on lines +117 to +123
async def send(
self,
prompt: str,
*,
attachments: list[Any] | None = None,
mode: str | None = None,
) -> str:
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@SteveSandersonMS
Copy link
Contributor

@brettcannon The updated signatures look better though the following Copilot comment also looks valid:

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.

Can we strengthen the types for those params?

@brettcannon
Copy link
Contributor Author

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants