Skip to content

Add invocations_ws WebSocket protocol#46779

Open
007DXR wants to merge 13 commits intoAzure:feature/azure-ai-agentserver-invocations_wsfrom
007DXR:xinran/invocations_ws
Open

Add invocations_ws WebSocket protocol#46779
007DXR wants to merge 13 commits intoAzure:feature/azure-ai-agentserver-invocations_wsfrom
007DXR:xinran/invocations_ws

Conversation

@007DXR
Copy link
Copy Markdown

@007DXR 007DXR commented May 7, 2026

Summary

Add invocations_ws WebSocket protocol into azure-ai-agentserver-invocations so a single host can serve both the HTTP invocations and the WebSocket invocations_ws protocols.

What's new

New public API (exported from azure.ai.agentserver.invocations)

  • InvocationWSAgentServerHostAgentServerHost subclass exposing a single persistent WebSocket endpoint at /invocations_ws/ws that handles invoke, get_invocation, and cancel_invocation actions on one connection. Streaming is supported natively via async generator handlers.
  • InvocationWSContext — passed to handlers; carries invocation_id and resolved session_id.
  • InvocationWSError(code, message) — raise from a handler to return a domain‑specific error frame to the client without leaking internals.

Decorator‑based handler registration

  • @app.ws_invoke_handler (required) — supports both async def (non‑streaming) and async def generators (streaming).
  • @app.ws_get_invocation_handler (optional)
  • @app.ws_cancel_invocation_handler (optional)

Operational features

  • Built‑in WebSocket keep‑alive via ws_ping_interval (default 30 s, set to 0 to disable) so connections survive Azure APIM / Load Balancer ~4‑minute idle timeouts. Symmetric ping/pong actions in both directions.
  • Session ID resolution order: message field → FOUNDRY_AGENT_SESSION_ID env var → generated UUID.
  • OpenAPI spec discovery at GET /invocations_ws/docs/openapi.json.
  • Distributed tracing with GenAI semantic‑convention spans (invoke_agent, get_invocation, cancel_invocation) and attributes/error tags under the azure.ai.agentserver.invocations_ws.* namespace.

Multi‑protocol composition

  • InvocationWSAgentServerHost and InvocationAgentServerHost use cooperative multiple inheritance, so a single host class can register both @app.invoke_handler (HTTP) and @app.ws_invoke_handler (WebSocket) — see the "Combined HTTP + WebSocket host" section in README.md.

Changes in this PR

  • New InvocationWSAgentServerHost, InvocationWSContext, and InvocationWSError types under azure-ai-agentserver-invocations/azure.
  • Added streaming_ws_invoke_agent sample under samples/streaming_ws_invoke_agent demonstrating token‑by‑token streaming over both WebSocket and HTTP SSE.
  • New WebSocket test suites in tests: test_ws_invoke.py, test_ws_get_cancel.py, test_ws_decorator_pattern.py, test_ws_session_id.py, test_ws_keepalive.py, test_ws_tracing.py, test_ws_span_parenting.py, test_ws_server_routes.py, test_ws_edge_cases.py, test_ws_request_limits.py, test_ws_graceful_shutdown.py, test_ws_multimodal_protocol.py, plus a shared conftest_ws.py.
  • Updated README.md with a full "WebSocket Protocol (invocations_ws)" section, including client examples, session/streaming/long‑running patterns, and a combined HTTP+WS host example.

007DXR and others added 10 commits April 9, 2026 09:03
…text

- Updated all test files to replace InvocationAgentServerHost with ConversationAgentServerHost.
- Changed references from InvocationContext to ConversationContext.
- Adjusted WebSocket endpoint paths from /invocations/ws to /conversations/ws.
- Modified test assertions to check for conversation_id instead of invocation_id.
- Ensured that all relevant tests for graceful shutdown, invoke actions, request limits, and tracing are consistent with the new conversation model.
…-6256859 (Azure#46749)

* Configurations:  'specification/fileshares/resource-manager/Microsoft.FileShares/FileShares/tspconfig.yaml', and CommitSHA: '61f4dfae58f52c2c814ea7c6653ce77ac0cacd4a' in SpecRepo: 'https://github.com/Azure/azure-rest-api-specs' Pipeline run: https://dev.azure.com/azure-sdk/internal/_build/results?buildId=6256859 Refer to https://eng.ms/docs/products/azure-developer-experience/develop/sdk-release/sdk-release-prerequisites to prepare for SDK release.

* update test files

* Update pyproject.toml

* Configurations:  'specification/fileshares/resource-manager/Microsoft.FileShares/FileShares/tspconfig.yaml', and CommitSHA: '75ca22c5387184fb1f0c3b115ed22a006813800d' in SpecRepo: 'https://github.com/Azure/azure-rest-api-specs' Pipeline run: https://dev.azure.com/azure-sdk/internal/_build/results?buildId=6257089 Refer to https://eng.ms/docs/products/azure-developer-experience/develop/sdk-release/sdk-release-prerequisites to prepare for SDK release.

* update

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* update

---------

Co-authored-by: Yuchao Yan <yuchaoyan@microsoft.com>
Co-authored-by: Chenxi Jiang (WICRESOFT NORTH AMERICA LTD) <v-chenjiang@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…rtions

- Disable OpenTelemetry metrics exporter during tests to prevent noisy tracebacks.
- Ensure clean shutdown of OpenTelemetry providers in pytest.
- Update APPLICATIONINSIGHTS_CONNECTION_STRING in tests to a placeholder value.
- Modify logging levels in tests to capture warnings instead of errors.
- Adjust assertions in tracing tests to reflect expected behavior when tracing is not configured.
@github-actions github-actions Bot added Community Contribution Community members are working on the issue customer-reported Issues that are reported by GitHub users external to the Azure organization. Hosted Agents sdk/agentserver/* labels May 7, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

Thank you for your contribution @007DXR! We will review the pull request and get back to you soon.

@007DXR 007DXR requested review from benbp, mccoyp and weshaggard as code owners May 7, 2026 07:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Community Contribution Community members are working on the issue customer-reported Issues that are reported by GitHub users external to the Azure organization. Hosted Agents sdk/agentserver/*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants