ms-tau-sdk 2.0.29.dev84__tar.gz → 2.0.30.dev86__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/CHANGELOG.md +25 -0
  2. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/PKG-INFO +2 -1
  3. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/pyproject.toml +2 -1
  4. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/agent_skills/tau_security_and_access/SKILL.md +30 -1
  5. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/api/a2a.py +11 -1
  6. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/api/request_identity.py +17 -3
  7. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/backend/client.py +9 -1
  8. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/backend/mcp.py +26 -3
  9. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/logging.py +16 -0
  10. ms_tau_sdk-2.0.30.dev86/src/ms_tau_sdk/protocols/caller_context.py +132 -0
  11. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/runtime/manager.py +31 -6
  12. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/runtime/requester.py +9 -2
  13. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/.gitignore +0 -0
  14. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/README.md +0 -0
  15. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/packages/tau-board/src/ms_tau_board/__init__.py +0 -0
  16. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/packages/tau-board/src/ms_tau_board/app.py +0 -0
  17. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/packages/tau-board/src/ms_tau_board/cli.py +0 -0
  18. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/packages/tau-board/src/ms_tau_board/config.py +0 -0
  19. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/packages/tau-board/src/ms_tau_board/env_file.py +0 -0
  20. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/packages/tau-board/src/ms_tau_board/logs.py +0 -0
  21. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/packages/tau-board/src/ms_tau_board/proxy.py +0 -0
  22. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/packages/tau-board/src/ms_tau_board/state.py +0 -0
  23. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/packages/tau-board/src/ms_tau_board/static/BULMA-LICENSE.txt +0 -0
  24. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/packages/tau-board/src/ms_tau_board/static/app.js +0 -0
  25. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/packages/tau-board/src/ms_tau_board/static/board.css +0 -0
  26. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/packages/tau-board/src/ms_tau_board/static/bulma.min.css +0 -0
  27. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/packages/tau-board/src/ms_tau_board/static/index.html +0 -0
  28. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/__init__.py +0 -0
  29. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/agent_skills/design-agent-icons-and-motion/SKILL.md +0 -0
  30. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/agent_skills/design-agent-icons-and-motion/agents/openai.yaml +0 -0
  31. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/agent_skills/design-agent-icons-and-motion/references/metatables-example.html +0 -0
  32. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/agent_skills/tau_a2a_runtime_adapter/SKILL.md +0 -0
  33. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/agent_skills/tau_local_development/SKILL.md +0 -0
  34. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/agent_skills/tau_project_customization/SKILL.md +0 -0
  35. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/agent_skills/tau_repository_integration/SKILL.md +0 -0
  36. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/api/__init__.py +0 -0
  37. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/api/chat.py +0 -0
  38. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/api/conversations.py +0 -0
  39. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/api/dependencies.py +0 -0
  40. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/api/health.py +0 -0
  41. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/api/inspection.py +0 -0
  42. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/api/local_chat.py +0 -0
  43. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/api/models.py +0 -0
  44. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/api/sessions.py +0 -0
  45. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/app.py +0 -0
  46. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/application.py +0 -0
  47. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/backend/__init__.py +0 -0
  48. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/backend/assertions.py +0 -0
  49. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/backend/auth.py +0 -0
  50. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/backend/local.py +0 -0
  51. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/backend/models.py +0 -0
  52. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/backend/routes.py +0 -0
  53. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/backend/team_memberships.py +0 -0
  54. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/cli.py +0 -0
  55. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/errors.py +0 -0
  56. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/protocols/__init__.py +0 -0
  57. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/protocols/a2a_failure.py +0 -0
  58. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/protocols/a2a_message.py +0 -0
  59. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/protocols/a2a_roles.py +0 -0
  60. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/protocols/assistant_ui.py +0 -0
  61. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/protocols/chat_history.py +0 -0
  62. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/protocols/strict_json.py +0 -0
  63. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/providers/__init__.py +0 -0
  64. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/providers/definitions.py +0 -0
  65. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/providers/factory.py +0 -0
  66. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/providers/tau_compat.py +0 -0
  67. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/resources/SYSTEM.md +0 -0
  68. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/resources/__init__.py +0 -0
  69. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/resources/context_compat.py +0 -0
  70. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/resources/loader.py +0 -0
  71. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/resources/prompts/review-code-repository.md +0 -0
  72. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/runtime/__init__.py +0 -0
  73. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/runtime/deployment_health.py +0 -0
  74. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/runtime/events.py +0 -0
  75. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/runtime/extensions.py +0 -0
  76. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/runtime/failures.py +0 -0
  77. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/runtime/live_turns.py +0 -0
  78. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/runtime/observability.py +0 -0
  79. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/runtime/provenance.py +0 -0
  80. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/runtime/session.py +0 -0
  81. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/runtime/snapshots.py +0 -0
  82. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/runtime/task_context.py +0 -0
  83. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/sessions/__init__.py +0 -0
  84. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/sessions/storage.py +0 -0
  85. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/settings.py +0 -0
  86. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/skills.py +0 -0
  87. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/tools/__init__.py +0 -0
  88. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/tools/mainsequence_mcp.py +0 -0
  89. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/tools/mcp_applications.py +0 -0
  90. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/tools/mcp_connection.py +0 -0
  91. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/tools/skill_read.py +0 -0
  92. {ms_tau_sdk-2.0.29.dev84 → ms_tau_sdk-2.0.30.dev86}/src/ms_tau_sdk/tools/task_control.py +0 -0
@@ -2,6 +2,31 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ - **The Security and access guide sets no rule on what caller context holds.** It no longer says
6
+ to refer to a person by an opaque id: what the keys and values mean, including whether one
7
+ refers to a person, is up to whoever designs the application. Caller context stays public, so
8
+ nothing secret or used as proof goes in it, and the
9
+ [trust rule](docs/reference/security-model.md#caller-context) is unchanged. SDK behavior is
10
+ unchanged.
11
+
12
+ ## 2.0.29 — 2026-11-07
13
+
14
+ - **Agents receive and pass on caller context (W3C `baggage` and `traceparent`).** A service user,
15
+ such as an application outside Main Sequence that serves its own users, can say in the W3C
16
+ `baggage` header which of its users a call is for. In hosted mode the runtime makes a verified
17
+ request's `traceparent` and `baggage` OpenTelemetry's current context, next to the verified
18
+ caller, and a Task's dispatch signal now carries the Task's context as the same two headers,
19
+ which become the context of that Task's execution. Agent code reads it with OpenTelemetry's
20
+ standard API (`opentelemetry.baggage`); the SDK adds no accessor and defines no keys. The
21
+ runtime's platform calls, Main Sequence MCP tools (A2A sends included), application tools and
22
+ `platform_client()` calls carry the current context on, and log lines record its
23
+ `mainsequence.` keys as a `baggage` field. The context is the caller's claim, never Main
24
+ Sequence identity: the [Security and access guide](docs/reference/security-model.md#caller-context)
25
+ says when to believe it, and missing context means no external user. `opentelemetry-api`, which
26
+ the runtime already installed through `mcp`, is now a direct dependency. An Agent on an earlier
27
+ release keeps working and carries no context. See the
28
+ [runtime contract](docs/reference/runtime-contract.md#caller-context).
29
+
5
30
  - **Troubleshooting covers code repository creation without a linked GitHub organization.** The
6
31
  platform creates a code repository's GitHub repository only in a GitHub organization the
7
32
  Organization linked. When an Agent creates one for its requester, the call answers `400` with
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: ms-tau-sdk
3
- Version: 2.0.29.dev84
3
+ Version: 2.0.30.dev86
4
4
  Summary: Workspace-bound Tau application primitives for Main Sequence projects
5
5
  Project-URL: Changelog, https://github.com/mainsequence-sdk/ms-tau-sdk/blob/development/CHANGELOG.md
6
6
  Project-URL: Documentation, https://github.com/mainsequence-sdk/ms-tau-sdk/tree/development/docs
@@ -20,6 +20,7 @@ Requires-Dist: fastapi>=0.116
20
20
  Requires-Dist: httpx>=0.28
21
21
  Requires-Dist: jsonschema<5,>=4.25
22
22
  Requires-Dist: mcp<3,>=2.3
23
+ Requires-Dist: opentelemetry-api<2,>=1.28
23
24
  Requires-Dist: pydantic-settings>=2.10
24
25
  Requires-Dist: pydantic>=2.11
25
26
  Requires-Dist: pyjwt[crypto]<3,>=2.10.1
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "ms-tau-sdk"
7
- version = "2.0.29.dev84"
7
+ version = "2.0.30.dev86"
8
8
  description = "Workspace-bound Tau application primitives for Main Sequence projects"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.13"
@@ -24,6 +24,7 @@ dependencies = [
24
24
  "httpx>=0.28",
25
25
  "jsonschema>=4.25,<5",
26
26
  "mcp>=2.3,<3",
27
+ "opentelemetry-api>=1.28,<2",
27
28
  "pydantic>=2.11",
28
29
  "pydantic-settings>=2.10",
29
30
  "pyjwt[crypto]>=2.10.1,<3",
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: tau-security-and-access
3
- description: Build and review project tools that call the platform or other applications for the person a turn serves, including tools that use a person's Secret without exposing it, and explain how delegation and policies decide what those tools can reach.
3
+ description: Build and review project tools that call the platform or other applications for the person a turn serves, including tools that use a person's Secret without exposing it or read the caller context another application sends, and explain how delegation and policies decide what those tools can reach.
4
4
  ---
5
5
 
6
6
  # TAU Security and Access
@@ -294,6 +294,33 @@ if person is None or REPORTS_TEAM_UID not in await person.in_teams([REPORTS_TEAM
294
294
  - A check the platform cannot answer raises `BackendError`; it never answers "not a member".
295
295
  - The requester carries no team list; `in_teams()` is the only membership check.
296
296
 
297
+ ## Caller context from another application
298
+
299
+ An application that serves its own users, such as a service outside Main Sequence, can say which
300
+ of its users the work it sends is for, in W3C `baggage` keys of the form
301
+ `mainsequence.<application>.<name>`. The runtime makes that context OpenTelemetry's current context
302
+ for the request or Task, and a tool reads it with OpenTelemetry's API:
303
+
304
+ ```python
305
+ from opentelemetry import baggage
306
+
307
+ person = baggage.get_baggage("mainsequence.advisor.person") # None when the work carries none
308
+ ```
309
+
310
+ - It is the sender's claim, never Main Sequence identity. It names no requester and carries no
311
+ delegation: `current_requester()` and `platform_client()` never read it, and it grants nothing.
312
+ Never let it choose whose Secret, credential or data a delegated call uses.
313
+ - Anyone who may give the Agent work can send any context, and a Task's context is whatever its
314
+ creator sent. Make rules from it only in an Agent whose policies admit only callers trusted to
315
+ vouch for it; in an HTTP handler, check `request.state.user` first.
316
+ - Use it to narrow what a tool returns, never to widen it. Missing context means no external user:
317
+ refuse what needs one, and never fall back to everyone's data.
318
+ - It is public. The runtime passes it on with every platform and application call, so never put a
319
+ secret in it, and know that an application that trusts this Agent's context trusts everyone who
320
+ may give the Agent work.
321
+
322
+ The SDK Security and access guide's **Caller context** section has the full rules.
323
+
297
324
  ## What never reaches the model
298
325
 
299
326
  Tool results, their `details`, and errors can reach the model provider and the session history.
@@ -334,5 +361,7 @@ Patch the extension module's `current_requester` and `platform_client` with fake
334
361
  - Secret values stay inside one call, in headers, never in results, logs, errors, URLs or caches.
335
362
  - The naming convention says whose Secrets the tool uses, and the owners of those Secrets know it.
336
363
  - A refused delegated call is reported, never retried as the Agent.
364
+ - Caller context only narrows results, comes from callers the Agent's policies trust, and its
365
+ absence is refused, never read as everyone.
337
366
  - The Agent's workload holds no grants it does not need, and none on people's Secrets; `user` is
338
367
  enough on an Agent it only sends work to.
@@ -51,6 +51,7 @@ from ms_tau_sdk.protocols.a2a_roles import (
51
51
  message_to_binding,
52
52
  message_to_protocol,
53
53
  )
54
+ from ms_tau_sdk.protocols.caller_context import request_context
54
55
  from ms_tau_sdk.protocols.strict_json import (
55
56
  StrictJsonContract,
56
57
  StrictJsonError,
@@ -1671,6 +1672,8 @@ async def _schedule_task_accelerator(
1671
1672
  requester_uid=_task_requester_uid(task.requester_user_uid, task.requester_identity_type),
1672
1673
  )
1673
1674
  try:
1675
+ # The attempt runs in the caller context of the request that created or continued the
1676
+ # Task.
1674
1677
  _background, scheduled = manager.create_a2a_task_execution(
1675
1678
  task.uid,
1676
1679
  execution,
@@ -2392,8 +2395,14 @@ async def task_dispatch_available(
2392
2395
  client: BackendDep,
2393
2396
  manager: RuntimeManagerDep,
2394
2397
  config: SettingsDep,
2398
+ request: Request,
2395
2399
  ) -> dict[str, Any]:
2396
- """Handle the bounded post-wake hint; the backend claim is the authority."""
2400
+ """Handle the bounded post-wake hint; the backend claim is the authority.
2401
+
2402
+ The signal carries the Task's caller context, the context of the request that created the
2403
+ Task, as W3C ``traceparent`` and ``baggage`` headers. It becomes the context of the Task's
2404
+ execution; a signal without them leaves the Task with none.
2405
+ """
2397
2406
 
2398
2407
  task_uid = str(body.get("task_uid") or "").strip()
2399
2408
  dispatch_uid = str(body.get("dispatch_uid") or "").strip()
@@ -2429,6 +2438,7 @@ async def task_dispatch_available(
2429
2438
  ),
2430
2439
  ),
2431
2440
  name=f"a2a-task-{task.task_id}",
2441
+ caller_context=request_context(request.scope.get("headers", ())),
2432
2442
  )
2433
2443
  return {"accepted": True, "scheduled": scheduled, "task_uid": task.uid}
2434
2444
 
@@ -6,7 +6,9 @@
6
6
  ``RequestIdentityMiddleware``, which admits a request only with the platform's signed assertion of
7
7
  the kind its route requires: a platform assertion on ``/internal/*``, a caller assertion on every
8
8
  other route. Handlers read the verified caller with ``current_caller()``, or from
9
- ``request.state.user`` and ``request.state.user_uid``.
9
+ ``request.state.user`` and ``request.state.user_uid``. Beside it, the request's W3C
10
+ ``traceparent`` and ``baggage`` become OpenTelemetry's current context for the request: the caller
11
+ context, which is the caller's claim and never identity.
10
12
 
11
13
  A request that addresses an existing session must also come from the session's owner, from an
12
14
  Organization admin, or, for a delegated child session, from the workload User of the Agent that
@@ -48,7 +50,12 @@ from ms_tau_sdk.backend.team_memberships import (
48
50
  unbind_team_membership_scope,
49
51
  )
50
52
  from ms_tau_sdk.errors import SessionNotFoundError, TauSDKError
51
- from ms_tau_sdk.logging import bind_request_identity_log_fields
53
+ from ms_tau_sdk.logging import bind_request_identity_log_fields, bind_request_log_fields
54
+ from ms_tau_sdk.protocols.caller_context import (
55
+ caller_context_scope,
56
+ recorded_baggage,
57
+ request_context,
58
+ )
52
59
  from ms_tau_sdk.runtime.provenance import CallerIdentityError
53
60
  from ms_tau_sdk.settings import TauSDKSettings
54
61
 
@@ -345,11 +352,18 @@ class RequestIdentityMiddleware:
345
352
  assertion=caller_assertion,
346
353
  client=_backend_of(scope),
347
354
  )
355
+ # The caller context arrives beside the assertion verified above, and only with one. It is
356
+ # the caller's claim: it never admits a request or names a caller.
357
+ caller_context = request_context(scope.get("headers", ()))
358
+ baggage = recorded_baggage(caller_context)
359
+ if baggage:
360
+ bind_request_log_fields(scope, baggage=baggage)
348
361
  caller_token = _current_caller.set(caller)
349
362
  lookups_token = _workload_lookups.set({})
350
363
  membership_token = bind_team_membership_scope(membership)
351
364
  try:
352
- await self.app(scope, receive, send)
365
+ with caller_context_scope(caller_context):
366
+ await self.app(scope, receive, send)
353
367
  finally:
354
368
  unbind_team_membership_scope(membership, membership_token)
355
369
  _workload_lookups.reset(lookups_token)
@@ -24,6 +24,7 @@ from ms_tau_sdk.errors import (
24
24
  SessionNotFoundError,
25
25
  )
26
26
  from ms_tau_sdk.protocols.a2a_roles import platform_message_to_binding
27
+ from ms_tau_sdk.protocols.caller_context import outbound_headers
27
28
  from ms_tau_sdk.settings import TauSDKSettings
28
29
 
29
30
  from .assertions import ASSERTION_HEADER
@@ -311,7 +312,13 @@ class MainSequenceClient:
311
312
  response = await self._client.request(
312
313
  method,
313
314
  path,
314
- headers={**(headers or {}), **await self.auth.headers(force=force_auth)},
315
+ # The caller context of the work goes on with the call; a header the call
316
+ # sets wins.
317
+ headers={
318
+ **outbound_headers(headers or ()),
319
+ **(headers or {}),
320
+ **await self.auth.headers(force=force_auth),
321
+ },
315
322
  json=json,
316
323
  )
317
324
  response_detail = self._safe_body(response) if not response.is_success else None
@@ -734,6 +741,7 @@ class MainSequenceClient:
734
741
  data=data,
735
742
  files=files,
736
743
  headers={
744
+ **outbound_headers(headers or ()),
737
745
  **dict(headers or {}),
738
746
  **delegation,
739
747
  **await self.auth.headers(force=force_auth),
@@ -22,9 +22,12 @@ from mcp.shared._context_streams import (
22
22
  create_context_streams,
23
23
  )
24
24
  from mcp.shared.message import SessionMessage
25
+ from opentelemetry import context as otel_context
26
+ from opentelemetry.context import Context
25
27
  from pydantic import BaseModel, Field, model_validator
26
28
  from structlog.contextvars import bound_contextvars, get_contextvars
27
29
 
30
+ from ms_tau_sdk.protocols.caller_context import caller_context_scope, outbound_headers
28
31
  from ms_tau_sdk.settings import TauSDKSettings
29
32
 
30
33
  from .auth import BackendAuth
@@ -294,6 +297,7 @@ class _CallToolCommand:
294
297
  meta: dict[str, object] | None
295
298
  timeout_seconds: float | None
296
299
  log_context: dict[str, object]
300
+ caller_context: Context
297
301
  result: asyncio.Future[types.CallToolResult]
298
302
 
299
303
 
@@ -301,12 +305,14 @@ class _CallToolCommand:
301
305
  class _ReadResourceCommand:
302
306
  uri: str
303
307
  log_context: dict[str, object]
308
+ caller_context: Context
304
309
  result: asyncio.Future[types.ReadResourceResult]
305
310
 
306
311
 
307
312
  @dataclass(frozen=True)
308
313
  class _ListSkillsCommand:
309
314
  log_context: dict[str, object]
315
+ caller_context: Context
310
316
  result: asyncio.Future[tuple[Skill, ...]]
311
317
 
312
318
 
@@ -410,7 +416,7 @@ class MCPConnectionClient:
410
416
  timeout=self._http_timeout,
411
417
  auth=self._http_auth,
412
418
  event_hooks={
413
- "request": [self._prepare_tool_request],
419
+ "request": [self._carry_caller_context, self._prepare_tool_request],
414
420
  "response": [self._raise_for_error_status],
415
421
  },
416
422
  ) as http_client:
@@ -453,6 +459,12 @@ class MCPConnectionClient:
453
459
  )
454
460
  self._http_calls.clear()
455
461
 
462
+ async def _carry_caller_context(self, request: httpx2.Request) -> None:
463
+ # MCP sends each message from its own task, in the context of the call that sent it, so
464
+ # a request carries the caller context of that call and the connection's own requests
465
+ # carry none. A header already on the request wins.
466
+ request.headers.update(outbound_headers(request.headers))
467
+
456
468
  async def _prepare_tool_request(self, request: httpx2.Request) -> None:
457
469
  if request.method != "POST":
458
470
  return
@@ -515,7 +527,10 @@ class MCPConnectionClient:
515
527
  return
516
528
  self._in_flight.add(command.result)
517
529
  try:
518
- with bound_contextvars(**command.log_context):
530
+ with (
531
+ bound_contextvars(**command.log_context),
532
+ caller_context_scope(command.caller_context),
533
+ ):
519
534
  if isinstance(command, _CallToolCommand):
520
535
  with anyio.CancelScope() as cancel_scope:
521
536
  call = _ToolCall(cancel_scope)
@@ -643,6 +658,7 @@ class MCPConnectionClient:
643
658
  meta=meta,
644
659
  timeout_seconds=timeout_seconds,
645
660
  log_context=dict(get_contextvars()),
661
+ caller_context=otel_context.get_current(),
646
662
  result=result,
647
663
  )
648
664
  )
@@ -657,6 +673,7 @@ class MCPConnectionClient:
657
673
  _ReadResourceCommand(
658
674
  uri=uri,
659
675
  log_context=dict(get_contextvars()),
676
+ caller_context=otel_context.get_current(),
660
677
  result=result,
661
678
  )
662
679
  )
@@ -672,7 +689,13 @@ class MCPConnectionClient:
672
689
  return ()
673
690
  commands = self._require_commands()
674
691
  result: asyncio.Future[tuple[Skill, ...]] = asyncio.get_running_loop().create_future()
675
- commands.put_nowait(_ListSkillsCommand(log_context=dict(get_contextvars()), result=result))
692
+ commands.put_nowait(
693
+ _ListSkillsCommand(
694
+ log_context=dict(get_contextvars()),
695
+ caller_context=otel_context.get_current(),
696
+ result=result,
697
+ )
698
+ )
676
699
  return await result
677
700
 
678
701
  async def aclose(self) -> None:
@@ -28,6 +28,7 @@ from structlog.contextvars import (
28
28
  from structlog.typing import EventDict, Processor, WrappedLogger
29
29
 
30
30
  from ms_tau_sdk import __version__
31
+ from ms_tau_sdk.protocols.caller_context import recorded_baggage
31
32
 
32
33
  SENSITIVE_EXACT_KEYS = {
33
34
  "api_key",
@@ -168,6 +169,20 @@ def _bind_context(
168
169
  return event_dict
169
170
 
170
171
 
172
+ def _add_caller_context(
173
+ _logger: WrappedLogger,
174
+ _method_name: str,
175
+ event_dict: EventDict,
176
+ ) -> EventDict:
177
+ """Record the current caller context's ``mainsequence.`` keys as ``baggage``, as a claim."""
178
+
179
+ if "baggage" not in event_dict:
180
+ members = recorded_baggage()
181
+ if members:
182
+ event_dict["baggage"] = members
183
+ return event_dict
184
+
185
+
171
186
  def _add_google_cloud_trace_fields(
172
187
  _logger: WrappedLogger,
173
188
  _method_name: str,
@@ -344,6 +359,7 @@ def _common_processors() -> list[Processor]:
344
359
  structlog.stdlib.add_log_level,
345
360
  structlog.processors.TimeStamper(fmt="iso", utc=True),
346
361
  _bind_context,
362
+ _add_caller_context,
347
363
  _add_google_cloud_trace_fields,
348
364
  structlog.dev.set_exc_info,
349
365
  _safe_exception,
@@ -0,0 +1,132 @@
1
+ """Caller context: the W3C ``traceparent`` and ``baggage`` that come with a request or a Task.
2
+
3
+ A service user that calls Main Sequence for one of its own users can say, in W3C Baggage, which
4
+ user the call is for and add its own information about the call. The platform carries that
5
+ context to the applications that run on it, an Agent among them, and records it; it never
6
+ authenticates, authorizes or decides anything with it, and it defines no keys. The runtime carries
7
+ every key the same way and gives none of them a meaning.
8
+
9
+ The context of the request or Task the runtime serves is OpenTelemetry's current context: Agent
10
+ code reads it with ``opentelemetry.baggage``, and the runtime's calls to the platform and to
11
+ applications carry it on. It is a claim, worth as much as the trust in the caller that delivered
12
+ it, and it is never Main Sequence identity.
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ import logging
18
+ from collections.abc import Iterable, Iterator
19
+ from contextlib import contextmanager
20
+ from contextvars import ContextVar
21
+
22
+ from opentelemetry import baggage, trace
23
+ from opentelemetry import context as otel_context
24
+ from opentelemetry.baggage.propagation import W3CBaggagePropagator
25
+ from opentelemetry.context import Context
26
+ from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator
27
+
28
+ _baggage_propagator = W3CBaggagePropagator()
29
+ _trace_propagator = TraceContextTextMapPropagator()
30
+ _CARRIED_HEADERS = frozenset({"traceparent", "tracestate", "baggage"})
31
+ _handling_baggage: ContextVar[bool] = ContextVar("ms_tau_sdk_handling_baggage", default=False)
32
+
33
+
34
+ class _QuietBaggagePropagator(logging.Filter):
35
+ """Drop the parser's warnings while the runtime reads or writes baggage: they quote it."""
36
+
37
+ def filter(self, record: logging.LogRecord) -> bool:
38
+ return not _handling_baggage.get()
39
+
40
+
41
+ logging.getLogger("opentelemetry.baggage.propagation").addFilter(_QuietBaggagePropagator())
42
+
43
+
44
+ def _carrier(headers: Iterable[tuple[bytes, bytes]]) -> dict[str, str]:
45
+ """The request's trace context and baggage headers; repeated fields are joined."""
46
+
47
+ carrier: dict[str, str] = {}
48
+ for raw_name, raw_value in headers:
49
+ name = raw_name.decode("latin-1").lower()
50
+ if name in _CARRIED_HEADERS:
51
+ value = raw_value.decode("latin-1")
52
+ carrier[name] = f"{carrier[name]},{value}" if name in carrier else value
53
+ return carrier
54
+
55
+
56
+ def _with_baggage_header(header: str | None, context: Context) -> Context:
57
+ """``context`` with the members of one W3C ``baggage`` header added.
58
+
59
+ The parser's limits apply: a header over 8192 bytes is ignored whole, a member over 4096 bytes
60
+ is skipped and at most 180 members are read. W3C properties, after a member's ``;``, are
61
+ dropped, as the platform drops them. Malformed input is skipped and never raises.
62
+ """
63
+
64
+ # The header is decoded as latin-1, so its length is its length in bytes.
65
+ if not header or len(header) > W3CBaggagePropagator._MAX_HEADER_LENGTH:
66
+ return context
67
+ # Properties follow an unencoded ';', so an encoded ';' inside a value survives.
68
+ members = ",".join(member.split(";", 1)[0] for member in header.split(","))
69
+ token = _handling_baggage.set(True)
70
+ try:
71
+ return _baggage_propagator.extract({"baggage": members}, context=context)
72
+ except Exception:
73
+ return context
74
+ finally:
75
+ _handling_baggage.reset(token)
76
+
77
+
78
+ def request_context(headers: Iterable[tuple[bytes, bytes]]) -> Context:
79
+ """The caller context one inbound request or Task dispatch carries, from its headers.
80
+
81
+ Its baggage is exactly the request's ``baggage`` header: never the process's or another
82
+ request's, and none without the header. Its trace parent is the request's ``traceparent``,
83
+ unless instrumentation already records a span for the request.
84
+ """
85
+
86
+ carrier = _carrier(headers)
87
+ context = baggage.clear(context=otel_context.get_current())
88
+ context = _with_baggage_header(carrier.get("baggage"), context)
89
+ if not trace.get_current_span(context).is_recording():
90
+ context = _trace_propagator.extract(carrier, context=context)
91
+ return context
92
+
93
+
94
+ def outbound_headers(present: Iterable[str] = ()) -> dict[str, str]:
95
+ """The W3C ``traceparent``, ``tracestate`` and ``baggage`` headers of the current context.
96
+
97
+ Empty when the current context has neither. A header named in ``present``, in any case, is
98
+ left out: the call sets it itself, and its own value wins. Building them never fails a call.
99
+ """
100
+
101
+ carrier: dict[str, str] = {}
102
+ token = _handling_baggage.set(True)
103
+ try:
104
+ _trace_propagator.inject(carrier)
105
+ _baggage_propagator.inject(carrier)
106
+ except Exception:
107
+ return {}
108
+ finally:
109
+ _handling_baggage.reset(token)
110
+ own = {str(name).lower() for name in present}
111
+ return {name: value for name, value in carrier.items() if name not in own}
112
+
113
+
114
+ def recorded_baggage(context: Context | None = None) -> dict[str, str]:
115
+ """The context's baggage keys under ``mainsequence.``: the keys log lines record."""
116
+
117
+ return {
118
+ key: str(value)
119
+ for key, value in baggage.get_all(context=context).items()
120
+ if key.startswith("mainsequence.")
121
+ }
122
+
123
+
124
+ @contextmanager
125
+ def caller_context_scope(context: Context) -> Iterator[None]:
126
+ """Make ``context`` the current caller context until the block ends."""
127
+
128
+ token = otel_context.attach(context)
129
+ try:
130
+ yield
131
+ finally:
132
+ otel_context.detach(token)
@@ -19,6 +19,7 @@ import httpx
19
19
  import structlog
20
20
  from jsonschema.exceptions import SchemaError, ValidationError
21
21
  from jsonschema.validators import validator_for
22
+ from opentelemetry.context import Context
22
23
  from structlog.contextvars import (
23
24
  bind_contextvars,
24
25
  bound_contextvars,
@@ -53,6 +54,7 @@ from ms_tau_sdk.errors import (
53
54
  ToolWorkbenchError,
54
55
  )
55
56
  from ms_tau_sdk.logging import conversation_log_fields
57
+ from ms_tau_sdk.protocols.caller_context import caller_context_scope
56
58
  from ms_tau_sdk.providers.factory import ProviderFactory
57
59
  from ms_tau_sdk.resources.loader import tau_resource_paths
58
60
  from ms_tau_sdk.runtime.events import TauRuntimeEvent
@@ -2026,7 +2028,14 @@ class SessionRuntimeManager:
2026
2028
  *,
2027
2029
  name: str,
2028
2030
  operation_uid: str | None = None,
2031
+ caller_context: Context | None = None,
2029
2032
  ) -> asyncio.Task[object]:
2033
+ """Run ``coroutine`` detached from the turn that starts it.
2034
+
2035
+ The work keeps the caller context of the work that starts it, or runs in
2036
+ ``caller_context`` when one is given.
2037
+ """
2038
+
2030
2039
  if self._draining or self._closed:
2031
2040
  coroutine.close()
2032
2041
  raise RuntimeError("Main Sequence TAU SDK runtime is shutting down")
@@ -2066,7 +2075,12 @@ class SessionRuntimeManager:
2066
2075
  **{key: value for key, value in detached_fields.items() if value is not None}
2067
2076
  )
2068
2077
  try:
2069
- return await coroutine
2078
+ with (
2079
+ caller_context_scope(caller_context)
2080
+ if caller_context is not None
2081
+ else contextlib.nullcontext()
2082
+ ):
2083
+ return await coroutine
2070
2084
  finally:
2071
2085
  clear_contextvars()
2072
2086
 
@@ -2081,8 +2095,13 @@ class SessionRuntimeManager:
2081
2095
  coroutine: Coroutine[Any, Any, object],
2082
2096
  *,
2083
2097
  name: str,
2098
+ caller_context: Context | None = None,
2084
2099
  ) -> tuple[asyncio.Task[object], bool]:
2085
- """Deduplicate local accelerators; the platform's dispatch remains recovery owner."""
2100
+ """Deduplicate local accelerators; the platform's dispatch remains recovery owner.
2101
+
2102
+ The execution runs in ``caller_context``, the Task's caller context, when one is given,
2103
+ and otherwise in the caller context of the work that starts it.
2104
+ """
2086
2105
 
2087
2106
  existing = self._a2a_task_executions.get(task_uid)
2088
2107
  if existing is not None and not existing.done():
@@ -2092,6 +2111,7 @@ class SessionRuntimeManager:
2092
2111
  coroutine,
2093
2112
  name=name,
2094
2113
  operation_uid=task_uid,
2114
+ caller_context=caller_context,
2095
2115
  )
2096
2116
  self._a2a_task_executions[task_uid] = task
2097
2117
 
@@ -2162,10 +2182,15 @@ class SessionRuntimeManager:
2162
2182
 
2163
2183
  async def _renew_lease(self, runtime: ActiveSessionRuntime) -> None:
2164
2184
  clear_contextvars()
2165
- with bound_contextvars(
2166
- session_uid=runtime.session_uid,
2167
- agent_session_uid=runtime.session_uid,
2168
- operation_uid=str(uuid.uuid4()),
2185
+ # The lease outlives the request that loaded the session, so its renewals carry no
2186
+ # caller's context.
2187
+ with (
2188
+ caller_context_scope(Context()),
2189
+ bound_contextvars(
2190
+ session_uid=runtime.session_uid,
2191
+ agent_session_uid=runtime.session_uid,
2192
+ operation_uid=str(uuid.uuid4()),
2193
+ ),
2169
2194
  ):
2170
2195
  await self._renew_lease_with_context(runtime)
2171
2196
 
@@ -39,6 +39,7 @@ from ms_tau_sdk.errors import (
39
39
  BackendTimeoutError,
40
40
  TauSDKError,
41
41
  )
42
+ from ms_tau_sdk.protocols.caller_context import outbound_headers
42
43
 
43
44
  logger = structlog.get_logger(__name__)
44
45
 
@@ -329,7 +330,9 @@ class TurnRequesterBinding:
329
330
  client = self._application_http()
330
331
  # Only the application's bearer token goes to the application: never the runtime
331
332
  # credential or the lease proof. The request is built here so that no cookie the shared
332
- # client kept from another answer is sent with it.
333
+ # client kept from another answer is sent with it. The caller context of the work goes
334
+ # on with it, unless the call sets those headers itself.
335
+ own_headers = dict(options.get("headers") or {})
333
336
  request = httpx.Request(
334
337
  method,
335
338
  url,
@@ -338,7 +341,11 @@ class TurnRequesterBinding:
338
341
  content=options.get("content"),
339
342
  data=options.get("data"),
340
343
  files=options.get("files"),
341
- headers={**dict(options.get("headers") or {}), "Authorization": f"Bearer {token}"},
344
+ headers={
345
+ **outbound_headers(own_headers),
346
+ **own_headers,
347
+ "Authorization": f"Bearer {token}",
348
+ },
342
349
  extensions={"timeout": client.timeout.as_dict()},
343
350
  )
344
351
  started_at = time.monotonic()