agentcat 2.0.1__tar.gz → 2.1.0__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 (152) hide show
  1. {agentcat-2.0.1 → agentcat-2.1.0}/PKG-INFO +21 -2
  2. {agentcat-2.0.1 → agentcat-2.1.0}/README.md +19 -0
  3. {agentcat-2.0.1 → agentcat-2.1.0}/pyproject.toml +1 -1
  4. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/__init__.py +3 -1
  5. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/modules/adapters/_inner_tap.py +21 -2
  6. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/modules/callpath.py +15 -12
  7. agentcat-2.1.0/src/agentcat/modules/constants.py +72 -0
  8. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/modules/event_queue.py +30 -4
  9. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/modules/handles.py +38 -44
  10. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/modules/injection.py +60 -40
  11. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/modules/redaction.py +114 -2
  12. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/types.py +31 -2
  13. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/utils.py +3 -2
  14. {agentcat-2.0.1 → agentcat-2.1.0}/tests/community/test_community_v3_handles.py +24 -21
  15. {agentcat-2.0.1 → agentcat-2.1.0}/tests/community/test_community_v3_nested_calls.py +5 -5
  16. {agentcat-2.0.1 → agentcat-2.1.0}/tests/community/test_community_v3_openapi.py +7 -4
  17. {agentcat-2.0.1 → agentcat-2.1.0}/tests/e2e/community_v3/test_agent_handle_http.py +21 -12
  18. {agentcat-2.0.1 → agentcat-2.1.0}/tests/e2e/community_v3/test_event_capture_http.py +5 -2
  19. {agentcat-2.0.1 → agentcat-2.1.0}/tests/e2e/community_v3/test_stateless_http.py +1 -1
  20. {agentcat-2.0.1 → agentcat-2.1.0}/tests/e2e/community_v4/test_agent_handle_http.py +22 -13
  21. {agentcat-2.0.1 → agentcat-2.1.0}/tests/e2e/community_v4/test_session_http.py +13 -6
  22. {agentcat-2.0.1 → agentcat-2.1.0}/tests/e2e/community_v4/test_stateless_http.py +1 -1
  23. {agentcat-2.0.1 → agentcat-2.1.0}/tests/e2e/official/test_agent_handle_http.py +18 -9
  24. {agentcat-2.0.1 → agentcat-2.1.0}/tests/e2e/official/test_session_http.py +18 -8
  25. {agentcat-2.0.1 → agentcat-2.1.0}/tests/e2e/official/test_stateless_http.py +1 -1
  26. {agentcat-2.0.1 → agentcat-2.1.0}/tests/e2e/official_modern/test_agent_handle_http.py +21 -12
  27. {agentcat-2.0.1 → agentcat-2.1.0}/tests/e2e/official_modern/test_mcpserver_http.py +18 -10
  28. {agentcat-2.0.1 → agentcat-2.1.0}/tests/e2e/official_modern/test_session_http.py +18 -8
  29. {agentcat-2.0.1 → agentcat-2.1.0}/tests/e2e/official_modern/test_stateless_http.py +1 -1
  30. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_callpath.py +21 -16
  31. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_community_v4_handles.py +16 -9
  32. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_community_v4_nested_calls.py +4 -4
  33. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_concurrency_handles.py +7 -7
  34. agentcat-2.1.0/tests/test_constants_copy.py +208 -0
  35. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_customer_owned_parameters.py +5 -5
  36. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_dynamic_tracking.py +15 -8
  37. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_event_queue.py +165 -0
  38. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_handles.py +75 -26
  39. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_injection.py +112 -58
  40. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_inner_tap.py +69 -15
  41. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_lowlevel_v1_handles.py +31 -22
  42. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_lowlevel_v2_handles.py +27 -24
  43. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_rebuild_on_demand.py +5 -5
  44. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_redaction.py +307 -2
  45. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_removed_events.py +3 -1
  46. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_report_missing.py +17 -16
  47. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_response_shape.py +3 -3
  48. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_session_id_validation.py +62 -37
  49. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_tool_context.py +23 -20
  50. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_utils/__init__.py +19 -0
  51. agentcat-2.0.1/src/agentcat/modules/constants.py +0 -70
  52. agentcat-2.0.1/tests/test_constants_copy.py +0 -198
  53. {agentcat-2.0.1 → agentcat-2.1.0}/.gitignore +0 -0
  54. {agentcat-2.0.1 → agentcat-2.1.0}/CONTRIBUTING.md +0 -0
  55. {agentcat-2.0.1 → agentcat-2.1.0}/LICENSE +0 -0
  56. {agentcat-2.0.1 → agentcat-2.1.0}/docs/cats/bibi.png +0 -0
  57. {agentcat-2.0.1 → agentcat-2.1.0}/docs/cats/void.jpg +0 -0
  58. {agentcat-2.0.1 → agentcat-2.1.0}/docs/cats/zelda.jpg +0 -0
  59. {agentcat-2.0.1 → agentcat-2.1.0}/docs/static/architecture.png +0 -0
  60. {agentcat-2.0.1 → agentcat-2.1.0}/docs/static/og-image.png +0 -0
  61. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/modules/__init__.py +0 -0
  62. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/modules/adapters/__init__.py +0 -0
  63. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/modules/adapters/_common.py +0 -0
  64. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/modules/adapters/community.py +0 -0
  65. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/modules/adapters/lowlevel_v1.py +0 -0
  66. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/modules/adapters/lowlevel_v2.py +0 -0
  67. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/modules/client_identity.py +0 -0
  68. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/modules/detection.py +0 -0
  69. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/modules/diagnostics.py +0 -0
  70. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/modules/exceptions.py +0 -0
  71. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/modules/exporters/__init__.py +0 -0
  72. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/modules/exporters/datadog.py +0 -0
  73. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/modules/exporters/otlp.py +0 -0
  74. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/modules/exporters/sentry.py +0 -0
  75. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/modules/exporters/trace_context.py +0 -0
  76. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/modules/hooks.py +0 -0
  77. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/modules/identify.py +0 -0
  78. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/modules/internal.py +0 -0
  79. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/modules/logging.py +0 -0
  80. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/modules/request_extra.py +0 -0
  81. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/modules/sanitization.py +0 -0
  82. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/modules/telemetry.py +0 -0
  83. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/modules/tools.py +0 -0
  84. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/modules/truncation.py +0 -0
  85. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/modules/validation.py +0 -0
  86. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/thirdparty/__init__.py +0 -0
  87. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/thirdparty/ksuid/__init__.py +0 -0
  88. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/thirdparty/ksuid/baseconv.py +0 -0
  89. {agentcat-2.0.1 → agentcat-2.1.0}/src/agentcat/thirdparty/ksuid/ksuid.py +0 -0
  90. {agentcat-2.0.1 → agentcat-2.1.0}/tests/__init__.py +0 -0
  91. {agentcat-2.0.1 → agentcat-2.1.0}/tests/community/__init__.py +0 -0
  92. {agentcat-2.0.1 → agentcat-2.1.0}/tests/community/test_community_v3_event_serialization.py +0 -0
  93. {agentcat-2.0.1 → agentcat-2.1.0}/tests/community/test_community_v3_inject_context.py +0 -0
  94. {agentcat-2.0.1 → agentcat-2.1.0}/tests/community/test_community_v3_runtime_state_tools.py +0 -0
  95. {agentcat-2.0.1 → agentcat-2.1.0}/tests/conftest.py +0 -0
  96. {agentcat-2.0.1 → agentcat-2.1.0}/tests/e2e/__init__.py +0 -0
  97. {agentcat-2.0.1 → agentcat-2.1.0}/tests/e2e/_helpers.py +0 -0
  98. {agentcat-2.0.1 → agentcat-2.1.0}/tests/e2e/community_v3/__init__.py +0 -0
  99. {agentcat-2.0.1 → agentcat-2.1.0}/tests/e2e/community_v3/conftest.py +0 -0
  100. {agentcat-2.0.1 → agentcat-2.1.0}/tests/e2e/community_v3/test_identify_http.py +0 -0
  101. {agentcat-2.0.1 → agentcat-2.1.0}/tests/e2e/community_v3/test_request_extra_http.py +0 -0
  102. {agentcat-2.0.1 → agentcat-2.1.0}/tests/e2e/community_v4/__init__.py +0 -0
  103. {agentcat-2.0.1 → agentcat-2.1.0}/tests/e2e/community_v4/conftest.py +0 -0
  104. {agentcat-2.0.1 → agentcat-2.1.0}/tests/e2e/community_v4/test_identify_http.py +0 -0
  105. {agentcat-2.0.1 → agentcat-2.1.0}/tests/e2e/conftest.py +0 -0
  106. {agentcat-2.0.1 → agentcat-2.1.0}/tests/e2e/official/__init__.py +0 -0
  107. {agentcat-2.0.1 → agentcat-2.1.0}/tests/e2e/official/conftest.py +0 -0
  108. {agentcat-2.0.1 → agentcat-2.1.0}/tests/e2e/official/test_event_capture_http.py +0 -0
  109. {agentcat-2.0.1 → agentcat-2.1.0}/tests/e2e/official/test_identify_http.py +0 -0
  110. {agentcat-2.0.1 → agentcat-2.1.0}/tests/e2e/official/test_redaction_http.py +0 -0
  111. {agentcat-2.0.1 → agentcat-2.1.0}/tests/e2e/official/test_request_extra_http.py +0 -0
  112. {agentcat-2.0.1 → agentcat-2.1.0}/tests/e2e/official_modern/__init__.py +0 -0
  113. {agentcat-2.0.1 → agentcat-2.1.0}/tests/e2e/official_modern/conftest.py +0 -0
  114. {agentcat-2.0.1 → agentcat-2.1.0}/tests/e2e/official_modern/test_identify_http.py +0 -0
  115. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_api_base_url.py +0 -0
  116. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_async_hooks.py +0 -0
  117. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_client_identity.py +0 -0
  118. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_detection.py +0 -0
  119. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_diagnostics_attributes.py +0 -0
  120. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_diagnostics_auth.py +0 -0
  121. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_diagnostics_export.py +0 -0
  122. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_diagnostics_integration.py +0 -0
  123. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_diagnostics_no_payload.py +0 -0
  124. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_diagnostics_optout.py +0 -0
  125. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_diagnostics_record.py +0 -0
  126. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_diagnostics_sink.py +0 -0
  127. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_diagnostics_test_env.py +0 -0
  128. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_event_capture_completeness.py +0 -0
  129. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_event_tags_properties.py +0 -0
  130. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_exceptions.py +0 -0
  131. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_exporter_sdk_version.py +0 -0
  132. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_hook_offload.py +0 -0
  133. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_identify_shape.py +0 -0
  134. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_logging.py +0 -0
  135. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_multiple_servers.py +0 -0
  136. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_options_v2.py +0 -0
  137. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_process_safety.py +0 -0
  138. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_publish_custom_event.py +0 -0
  139. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_request_extra.py +0 -0
  140. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_sanitization.py +0 -0
  141. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_tag_validation.py +0 -0
  142. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_truncation.py +0 -0
  143. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_truncation_json_safe.py +0 -0
  144. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_utils/client.py +0 -0
  145. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_utils/community_catalog_server.py +0 -0
  146. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_utils/community_client.py +0 -0
  147. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_utils/community_openapi_server.py +0 -0
  148. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_utils/community_todo_server.py +0 -0
  149. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_utils/delivery.py +0 -0
  150. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_utils/flavors.py +0 -0
  151. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_utils/modern_server.py +0 -0
  152. {agentcat-2.0.1 → agentcat-2.1.0}/tests/test_utils/todo_server.py +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: agentcat
3
- Version: 2.0.1
3
+ Version: 2.1.0
4
4
  Summary: Analytics tool for MCP (Model Context Protocol) servers, Claude Connectors, and ChatGPT Plugins - tracks tool usage patterns and provides insights
5
5
  Project-URL: Homepage, https://github.com/agentcathq/agentcat-python-sdk
6
6
  Project-URL: Bug Tracker, https://github.com/agentcathq/agentcat-python-sdk/issues
@@ -175,6 +175,25 @@ async def redact(text: str) -> str:
175
175
  agentcat.track(server, "proj_0000000", AgentCatOptions(redact_sensitive_information=redact))
176
176
  ```
177
177
 
178
+ For redaction decisions that need more context than a single string — such as which tool was called or what type of event is being published — use the event-level `redact_event` hook. It receives the full event and returns a modified event, or `None` to drop the event entirely. It may be sync or async, runs before `redact_sensitive_information` (so it sees raw values), and can be combined with it.
179
+
180
+ Mutate the event you're given and return it, as in the example below — don't construct or return a different `Event`. The return value replaces the event's fields wholesale, not as a diff against the original, so returning a partial or freshly-built event will silently drop every field you didn't set.
181
+
182
+ ```python
183
+ from agentcat import AgentCatOptions
184
+
185
+ def redact_event(event):
186
+ # Drop events from tools that handle secrets entirely
187
+ if event.resource_name == "get_credentials":
188
+ return None
189
+ # Strip response payloads from a specific tool
190
+ if event.resource_name == "export_report":
191
+ event.response = None
192
+ return event
193
+
194
+ agentcat.track(server, "proj_0000000", AgentCatOptions(redact_event=redact_event))
195
+ ```
196
+
178
197
  ### Vendor Support
179
198
 
180
199
  AgentCat seamlessly integrates with your existing observability stack, providing automatic logging and tracing without the tedious setup typically required. Export telemetry data to multiple platforms simultaneously:
@@ -143,6 +143,25 @@ async def redact(text: str) -> str:
143
143
  agentcat.track(server, "proj_0000000", AgentCatOptions(redact_sensitive_information=redact))
144
144
  ```
145
145
 
146
+ For redaction decisions that need more context than a single string — such as which tool was called or what type of event is being published — use the event-level `redact_event` hook. It receives the full event and returns a modified event, or `None` to drop the event entirely. It may be sync or async, runs before `redact_sensitive_information` (so it sees raw values), and can be combined with it.
147
+
148
+ Mutate the event you're given and return it, as in the example below — don't construct or return a different `Event`. The return value replaces the event's fields wholesale, not as a diff against the original, so returning a partial or freshly-built event will silently drop every field you didn't set.
149
+
150
+ ```python
151
+ from agentcat import AgentCatOptions
152
+
153
+ def redact_event(event):
154
+ # Drop events from tools that handle secrets entirely
155
+ if event.resource_name == "get_credentials":
156
+ return None
157
+ # Strip response payloads from a specific tool
158
+ if event.resource_name == "export_report":
159
+ event.response = None
160
+ return event
161
+
162
+ agentcat.track(server, "proj_0000000", AgentCatOptions(redact_event=redact_event))
163
+ ```
164
+
146
165
  ### Vendor Support
147
166
 
148
167
  AgentCat seamlessly integrates with your existing observability stack, providing automatic logging and tracing without the tedious setup typically required. Export telemetry data to multiple platforms simultaneously:
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "agentcat"
3
- version = "2.0.1"
3
+ version = "2.1.0"
4
4
  description = "Analytics tool for MCP (Model Context Protocol) servers, Claude Connectors, and ChatGPT Plugins - tracks tool usage patterns and provides insights"
5
5
  authors = [
6
6
  { name = "AgentCat, Inc.", email = "support@agentcat.com" },
@@ -25,6 +25,7 @@ from .types import (
25
25
  EventPropertiesFunction,
26
26
  EventTagsFunction,
27
27
  IdentifyFunction,
28
+ RedactEventFunction,
28
29
  RedactionFunction,
29
30
  ResolveSessionIdFunction,
30
31
  UnredactedEvent,
@@ -449,8 +450,9 @@ __all__ = [
449
450
  # Types for identify functionality
450
451
  "UserIdentity",
451
452
  "IdentifyFunction",
452
- # Type for redaction functionality
453
+ # Types for redaction functionality
453
454
  "RedactionFunction",
455
+ "RedactEventFunction",
454
456
  # Types for event metadata callbacks
455
457
  "EventTagsFunction",
456
458
  "EventPropertiesFunction",
@@ -98,7 +98,7 @@ from collections.abc import Awaitable, Callable
98
98
  from types import TracebackType
99
99
  from typing import Any
100
100
 
101
- from agentcat.modules.exceptions import capture_exception
101
+ from agentcat.modules.exceptions import _safe_str, capture_exception
102
102
  from agentcat.modules.logging import write_to_log
103
103
  from agentcat.types import ErrorData
104
104
 
@@ -202,12 +202,31 @@ class InnerTap:
202
202
  an upstream error a proxy passed through, or a tool that returned
203
203
  ``is_error`` without anything having been raised at all, both of which
204
204
  have no local exception and never will.
205
+
206
+ One generation's wrapper is patched up: mcp 2.1 keeps a crash's own
207
+ text off the wire by raising ``UnexpectedToolError("Error executing
208
+ tool <name>")`` from it, where every earlier generation put
209
+ ``: <text>`` after the prefix. The cause still carries the text, so
210
+ it goes back on the event's message — the wire is not ours to touch —
211
+ and the message reads the same on every generation. Matched by class
212
+ name (the class exists only where the policy does) and skipped when
213
+ the text is already there (a nested crash's wrapper embeds the inner
214
+ wrapper's, and a future upstream may embed it again).
205
215
  """
206
216
  # `is not None`, not truthiness: an exception class that defines
207
217
  # `__len__` or `__bool__` can be falsy, and losing its traceback to
208
218
  # that would be a very quiet bug.
209
219
  exc = self._cell.exc
210
- return capture_exception(exc if exc is not None else flattened)
220
+ error = capture_exception(exc if exc is not None else flattened)
221
+ try:
222
+ cause = getattr(exc, "__cause__", None)
223
+ if type(exc).__name__ == "UnexpectedToolError" and cause is not None:
224
+ text = _safe_str(cause)
225
+ if text not in error["message"]:
226
+ error["message"] = f"{error['message']}: {text}"
227
+ except Exception: # a hostile __cause__ costs the suffix, never the event
228
+ pass
229
+ return error
211
230
 
212
231
 
213
232
  def inner_tap() -> InnerTap:
@@ -111,7 +111,8 @@ async def resolve_call(
111
111
  A tool absent from `declared_session_params` is ours — including one this
112
112
  instance never listed. That is the common case on stateless HTTP and it
113
113
  degrades safely: a customer's foreign value in that window is classified
114
- `invalid` rather than `foreign`, and both publish sessionless.
114
+ `invalid` rather than `foreign`, and both publish sessionless (a value
115
+ spelling `start` instead mints, exactly as on a parameter we injected).
115
116
  """
116
117
  resolution = await resolve_handles(
117
118
  raw_arguments,
@@ -157,9 +158,10 @@ async def get_stripped_arguments(
157
158
  rebuild falls back to the shape+config-aware strip (see
158
159
  `injected_parameter_names`): a name is removed only when the enabled
159
160
  options would have injected it AND, for `session_id`, the value matches
160
- our minted shape — a customer-declared parameter rides through to their
161
- handler. The fallback also clears the output-injection registry, so the
162
- structured mirror stops gating on knowledge we no longer have (§3.4b).
161
+ our minted shape or the `start` sentinel — a customer-declared parameter
162
+ rides through to their handler. The fallback also clears the
163
+ output-injection registry, so the structured mirror stops gating on
164
+ knowledge we no longer have (§3.4b).
163
165
  """
164
166
  registry = data.injected_params_registry
165
167
  if registry is None and rebuild is not None:
@@ -224,19 +226,20 @@ def decorate_content(
224
226
  res: HandleResolution,
225
227
  make_text_block: Callable[[str], Any],
226
228
  ) -> list[Any] | None:
227
- """The trailing mint-back block, or None to leave the result untouched.
229
+ """The leading mint-back block, or None to leave the result untouched.
228
230
 
229
- Error state is deliberately not an input: the retry after a failure has to
230
- carry the same session, so `isError` results decorate on identical terms
231
- (§3.4a). Whether there is anything to say at all stays the single ruling of
232
- `build_mint_back_text` — a session minted on this call, or a supplied one
233
- this server never issued; never in hook mode, and never for a parameter
234
- AgentCat did not inject.
231
+ Prepended, not appended: an ID at the tail of a long result is what
232
+ clients truncate away. Error state is deliberately not an input: the retry
233
+ after a failure has to carry the same session, so `isError` results
234
+ decorate on identical terms (§3.4a). Whether there is anything to say at
235
+ all stays the single ruling of `build_mint_back_text` — a session minted
236
+ on this call, or a supplied one this server never issued; never in hook
237
+ mode, and never for a parameter AgentCat did not inject.
235
238
  """
236
239
  text = build_mint_back_text(res)
237
240
  if text is None or not isinstance(content, list):
238
241
  return None
239
- return [*content, make_text_block(text)]
242
+ return [make_text_block(text), *content]
240
243
 
241
244
 
242
245
  def structured_mirror(
@@ -0,0 +1,72 @@
1
+ LOG_PATH = "agentcat.log" # Default log file path
2
+ SESSION_ID_PREFIX = "ses"
3
+ EVENT_ID_PREFIX = "evt"
4
+ AGENTCAT_API_URL = "https://api.agentcat.com" # Default API URL for AgentCat events
5
+ AGENTCAT_SOURCE = "agentcat" # Source attribution for telemetry exporters
6
+ DEFAULT_CONTEXT_DESCRIPTION = "Explain why you are calling this tool and how it fits into the user's overall goal. This parameter is used for analytics and user intent tracking. YOU MUST provide 15-25 words (count carefully). NEVER use first person ('I', 'we', 'you') - maintain third-person perspective. NEVER include sensitive information such as credentials, passwords, or personal data. Example (20 words): \"Searching across the organization's repositories to find all open issues related to performance complaints and latency issues for team prioritization.\""
7
+
8
+ # Maximum number of exceptions to capture in a cause chain
9
+ MAX_EXCEPTION_CHAIN_DEPTH = 10
10
+
11
+ # Maximum number of stack frames to capture per exception
12
+ MAX_STACK_FRAMES = 50
13
+
14
+ # Internal SDK diagnostics (privacy-first, metadata-only OTLP logs)
15
+ DIAGNOSTICS_SCOPE_NAME = "agentcat-diagnostics"
16
+ DEFAULT_DIAGNOSTICS_ENDPOINT = "https://otel.agentcat.com"
17
+ # Public shared ingestion key — NOT a secret; ships in the package to deter
18
+ # drive-by traffic, paired with a server-side rate limit. Override with the
19
+ # DIAGNOSTICS_TOKEN env var. Must match the collector's bearer token (same
20
+ # literal as the TypeScript SDK).
21
+ DEFAULT_DIAGNOSTICS_TOKEN = "dgk_sdk_diag_3f9a2c7e1b8d4065af2e9c1d7b6a4f80"
22
+
23
+ # ── Explicit handles: injected parameter names & wire keys ───────────────────
24
+ SESSION_ID_PARAM = "session_id"
25
+ AGENT_ID_PARAM = "agent_id"
26
+ CONTEXT_PARAM = "context"
27
+ GET_MORE_TOOLS_NAME = "get_more_tools"
28
+ AGENT_ID_PREFIX = "agt" # reserved; server-side agent minting was removed
29
+ MCP_SESSION_KEY = "mcp_session"
30
+ META_CLIENT_INFO_KEY = "io.modelcontextprotocol/clientInfo"
31
+ META_PROTOCOL_VERSION_KEY = "io.modelcontextprotocol/protocolVersion"
32
+ AGENTCAT_TAG_SESSION_SOURCE = "agentcat_session_id_source"
33
+ AGENTCAT_TAG_AGENT_ID = "agentcat_agent_id"
34
+ AGENTCAT_TAG_AGENT_SOURCE = "agentcat_agent_id_source"
35
+ AGENTCAT_TAG_PROTOCOL_VERSION = "agentcat_protocol_version"
36
+ AGENTCAT_TAG_MRTR = "agentcat_mrtr"
37
+ # Presence-gated: rides only on tools/call events the customer's own server
38
+ # made from inside another tracked call (a code-mode sandbox, a tool calling
39
+ # a sibling tool). Value is always "true"; absent on agent-facing calls.
40
+ AGENTCAT_TAG_NESTED = "agentcat_nested"
41
+ AGENTCAT_CUSTOM_EVENT_TYPE = "agentcat:custom"
42
+
43
+ # ── Explicit handles: agent-facing copy (byte-identical to TS constants.ts) ──
44
+ # Source of truth: agentcat-typescript-sdk/src/modules/constants.ts (and the
45
+ # copy spec it cites). Do not reword here without changing the TS SDK first;
46
+ # tests/test_constants_copy.py enforces byte parity.
47
+ SESSION_ID_PARAM_DESCRIPTION = "Session continuity handle, one of two values: the ses_ ID issued for the task underway, or start. This server cannot link your calls between requests on its own, so session continuity travels in this parameter instead. If you were handed a session_id for this task — for example by the agent that spawned you — send that exact value from your first call. Otherwise send start on your first call; the server will issue an opaque correlation ID in the mcp_session field of the result, or in a text block at the start of the result beginning [session_id issued. Then send that exact ses_ value on every later call and hand it to any subagents working the same task. start always begins a new, unrelated task — never send it mid-task. If you send a value this server does not recognize, the result reports it: mcp_session.status of unrecognized, or a text block beginning [session_id unrecognized; re-send the ID issued for this task, or start if none was issued yet. Never invent a ses_ value."
48
+ # Wire literals of the session_id value contract: the pattern the injected
49
+ # parameter's schema declares, and the sentinel value that begins a new task.
50
+ # The pattern is is_valid_session_id's shape with the start alternative added;
51
+ # resolution accepts the sentinel case-insensitively and still treats an
52
+ # absent value as a start (stale schemas and scripted callers never error).
53
+ SESSION_ID_PARAM_PATTERN = "^(start|ses_[0-9A-Za-z]{27})$"
54
+ SESSION_START_SENTINEL = "start"
55
+ AGENT_ID_PARAM_DESCRIPTION = "Agent identity handle, required on every call including your first. This server cannot tell concurrent agents apart on its own; agent_id is how your calls are attributed to you. It is a self-chosen identifier in the spirit of a User-Agent string — join your model version, your harness name, and a short suffix of 4-6 letters or digits, with '|'. Example: opus-4.80-1m|claude-code|k3n9x. Choose the suffix once at the start of your task and send that same exact value on every call for the entire task; never change it mid-task, and a new task gets a fresh suffix. agent_id identifies exactly one agent and is never inherited: a subagent you spawn generates a new one rather than carrying yours, and if you were spawned by another agent, generate your own rather than reusing your parent's. A call without agent_id cannot be attributed to you."
56
+ MINT_BACK_HEADER_ISSUED = (
57
+ "[session_id issued — see this tool's session_id parameter description]"
58
+ )
59
+ MINT_BACK_ISSUED_BODY = "This is the first-call issuance described in this tool's session_id parameter description."
60
+ MINT_BACK_HEADER_UNRECOGNIZED = (
61
+ "[session_id unrecognized — see this tool's session_id parameter description]"
62
+ )
63
+ MINT_BACK_UNRECOGNIZED_BODY = "The value sent was not issued by this server. Re-send the session_id issued earlier for this task; if none was issued yet, send start and one will be issued."
64
+ MCP_SESSION_FIELD_DESCRIPTION = "Session continuity and agent attribution state for this task, returned on completed responses that carry structured output. This server cannot link your calls between requests on its own, so session continuity travels here instead."
65
+ MCP_SESSION_FIELD_DESCRIPTION_HOOK_MODE = "Agent attribution state for this task, returned on completed responses that carry structured output."
66
+ MCP_SESSION_SESSION_ID_DESCRIPTION = "Opaque correlation ID for this task, issued by this server. Use this as the session_id argument of every later call, and hand it to any subagents working the same task. Absent when status is unrecognized; no replacement is issued in that response — recovery is described under status."
67
+ MCP_SESSION_AGENT_ID_DESCRIPTION = "Present only when you sent agent_id on this call. Your agent_id, echoed as received. Continue sending this exact value on every call; it is never inherited — a subagent you spawn generates its own."
68
+ MCP_SESSION_STATUS_DESCRIPTION = "issued: first call of a task; the session_id above was just created. active: the session_id you sent was accepted; keep sending it. unrecognized: the value sent was not issued by this server — re-send the one issued earlier for this task; if none was issued yet, send start to be issued a new one."
69
+
70
+
71
+ def mint_back_session_line(session_id: str) -> str:
72
+ return f"session_id: {session_id}"
@@ -26,7 +26,7 @@ from ..types import Event, UnredactedEvent
26
26
  from ..utils import generate_prefixed_ksuid, get_agentcat_version
27
27
  from .internal import get_server_tracking_data
28
28
  from .logging import write_to_log
29
- from .redaction import redact_event
29
+ from .redaction import apply_event_redaction, redact_event
30
30
  from .sanitization import sanitize_event
31
31
  from .truncation import truncate_event
32
32
 
@@ -47,6 +47,12 @@ class _Stop:
47
47
  _STOP = _Stop()
48
48
 
49
49
 
50
+ def _ensure_event_id(event: UnredactedEvent) -> None:
51
+ """Assign a ksuid if the event doesn't already have one."""
52
+ if not event.id:
53
+ event.id = generate_prefixed_ksuid(EVENT_ID_PREFIX)
54
+
55
+
50
56
  class EventQueue:
51
57
  """Manages event queue and sending to AgentCat API."""
52
58
 
@@ -155,11 +161,30 @@ class EventQueue:
155
161
 
156
162
  def _process_event(self, event: UnredactedEvent) -> None:
157
163
  """Process a single event."""
164
+ if event and event.event_redaction_fn:
165
+ # Event-level redaction hook runs first, on raw values, and may
166
+ # drop the event entirely.
167
+ try:
168
+ _ensure_event_id(event)
169
+ redacted_event = apply_event_redaction(event, event.event_redaction_fn)
170
+ if redacted_event is None:
171
+ write_to_log(f"Event {event.id} dropped by redact_event hook")
172
+ return
173
+ event = redacted_event
174
+ event.event_redaction_fn = None # Clear to avoid reprocessing
175
+ except (Exception, SystemExit) as error:
176
+ # SystemExit included: a customer hook calling sys.exit() must
177
+ # not kill the worker thread.
178
+ write_to_log(
179
+ f"WARNING: Dropping event {event.id or 'unknown'} due to "
180
+ f"event redaction failure: {error}"
181
+ )
182
+ return # Skip this event if event redaction fails
183
+
158
184
  if event and event.redaction_fn:
159
185
  # Redact sensitive information if a redaction function is provided
160
186
  try:
161
- if not event.id:
162
- event.id = generate_prefixed_ksuid(EVENT_ID_PREFIX)
187
+ _ensure_event_id(event)
163
188
  redacted_event = redact_event(event, event.redaction_fn)
164
189
  # The redacted event is already the full event object, not a dict
165
190
  event = redacted_event
@@ -186,7 +211,7 @@ class EventQueue:
186
211
  )
187
212
 
188
213
  if event:
189
- event.id = event.id or generate_prefixed_ksuid("evt")
214
+ _ensure_event_id(event)
190
215
 
191
216
  # Send to AgentCat API only if project_id exists
192
217
  if event.project_id:
@@ -394,6 +419,7 @@ def publish_event(server: Any, event: UnredactedEvent) -> None:
394
419
  full_event = UnredactedEvent(
395
420
  **stamped,
396
421
  redaction_fn=data.options.redact_sensitive_information,
422
+ event_redaction_fn=data.options.redact_event,
397
423
  )
398
424
 
399
425
  event_queue.add(full_event)
@@ -18,14 +18,14 @@ from agentcat.modules.constants import (
18
18
  AGENTCAT_TAG_NESTED,
19
19
  AGENTCAT_TAG_PROTOCOL_VERSION,
20
20
  AGENTCAT_TAG_SESSION_SOURCE,
21
- MCP_INSTRUCTIONS_KEY,
22
- MINT_BACK_CLOSER,
23
- MINT_BACK_HEADER_INVALID,
24
- MINT_BACK_HEADER_SESSION,
25
- MINT_BACK_INVALID_LINE,
21
+ MCP_SESSION_KEY,
22
+ MINT_BACK_HEADER_ISSUED,
23
+ MINT_BACK_HEADER_UNRECOGNIZED,
24
+ MINT_BACK_ISSUED_BODY,
25
+ MINT_BACK_UNRECOGNIZED_BODY,
26
26
  SESSION_ID_PARAM,
27
27
  SESSION_ID_PREFIX,
28
- mint_back_confirmed,
28
+ SESSION_START_SENTINEL,
29
29
  mint_back_session_line,
30
30
  )
31
31
  from agentcat.modules.hooks import run_hook
@@ -184,7 +184,13 @@ async def resolve_handles(
184
184
  )
185
185
 
186
186
  supplied = extract_handle(arguments, SESSION_ID_PARAM)
187
- if supplied:
187
+ # The `start` sentinel is checked BEFORE shape validation and resolves
188
+ # exactly like an absent value: it is the explicit spelling of "begin a
189
+ # new task" the required parameter's copy asks for. Case-insensitive
190
+ # (extract_handle already trimmed), and only ever read here — a foreign
191
+ # customer-owned value took the branch above, so `start` in a parameter
192
+ # the customer declared is never interpreted as a sentinel.
193
+ if supplied and supplied.lower() != SESSION_START_SENTINEL:
188
194
  if is_valid_session_id(supplied):
189
195
  return HandleResolution(
190
196
  supplied,
@@ -210,39 +216,24 @@ async def resolve_handles(
210
216
  )
211
217
 
212
218
 
213
- def _echoes_session_id(res: HandleResolution) -> bool:
214
- """Whether the agent has an AgentCat `session_id` value to echo back.
215
-
216
- Three ways to have none: hook mode and the no-parameter cases collapsed
217
- into `prompts_session_id`, plus `invalid` — where the parameter is ours
218
- but there is no value to confirm. That branch corrects the agent rather
219
- than issuing a replacement, so naming a `session_id` would be a lie.
220
- """
221
- return (
222
- res.prompts_session_id and not res.hook_mode and res.session_source != "invalid"
223
- )
224
-
225
-
226
219
  def build_mint_back_text(res: HandleResolution) -> str | None:
227
220
  if res.hook_mode or not res.prompts_session_id:
228
221
  return None
229
222
  if res.session_source == "minted":
230
223
  return "\n".join(
231
224
  [
232
- MINT_BACK_HEADER_SESSION,
225
+ MINT_BACK_HEADER_ISSUED,
233
226
  mint_back_session_line(res.session_id),
234
- MINT_BACK_CLOSER,
227
+ MINT_BACK_ISSUED_BODY,
235
228
  ]
236
229
  )
237
230
  if res.session_source == "invalid":
238
231
  # No replacement is handed out. An agent that sent something was
239
232
  # usually already issued a good ID, and giving it a second one splits a
240
233
  # session that was never split. The closing sentence of
241
- # MINT_BACK_INVALID_LINE is the way out for the agent that was never
242
- # issued one: omit the parameter and take the `minted` branch.
243
- return "\n".join(
244
- [MINT_BACK_HEADER_INVALID, MINT_BACK_INVALID_LINE, MINT_BACK_CLOSER]
245
- )
234
+ # MINT_BACK_UNRECOGNIZED_BODY is the way out for the agent that was
235
+ # never issued one: send `start` and take the `minted` branch.
236
+ return "\n".join([MINT_BACK_HEADER_UNRECOGNIZED, MINT_BACK_UNRECOGNIZED_BODY])
246
237
  return None
247
238
 
248
239
 
@@ -251,7 +242,9 @@ def build_structured_mint_back(res: HandleResolution) -> dict[str, Any] | None:
251
242
 
252
243
  Unlike `build_mint_back_text` (mint announcements only), this is present
253
244
  on EVERY response, so an agent can re-read its own handles mid-session.
254
- Handles the agent cannot echo are never named.
245
+ Handles the agent cannot echo are never named: `status` and `session_id`
246
+ appear only in prompted mode — hook mode and a customer-owned session
247
+ parameter mirror `agent_id` alone.
255
248
 
256
249
  Suppression is per-HANDLE, not per-response: a `session_id` collision skips
257
250
  only `session_id`. `agent_id` is a separate injection and still landed in
@@ -259,33 +252,34 @@ def build_structured_mint_back(res: HandleResolution) -> dict[str, Any] | None:
259
252
  mirror would withhold a handle AgentCat issued purely because a
260
253
  neighbouring one belongs to the customer.
261
254
  """
262
- echoes = _echoes_session_id(res)
263
- names: list[str] = []
264
- if echoes:
265
- names.append(SESSION_ID_PARAM)
266
- if res.agent_id:
267
- names.append(AGENT_ID_PARAM)
268
- text = build_mint_back_text(res)
269
- # `not names` alone would drop the `invalid` correction whenever no
270
- # agent_id is in play — the one branch that has something to say and
271
- # nothing to echo.
272
- if not names and not text:
273
- return None
255
+ prompted = res.prompts_session_id and not res.hook_mode
274
256
  mint: dict[str, Any] = {}
275
- if echoes:
257
+ if prompted and res.session_source in ("minted", "supplied"):
258
+ # `invalid` names no session_id: no replacement is issued, and the
259
+ # recovery path is described under `status`.
276
260
  mint[SESSION_ID_PARAM] = res.session_id
277
261
  if res.agent_id:
278
262
  mint[AGENT_ID_PARAM] = res.agent_id
279
- mint["instructions"] = text or mint_back_confirmed(names)
263
+ if prompted:
264
+ if res.session_source == "minted":
265
+ mint["status"] = "issued"
266
+ elif res.session_source == "supplied":
267
+ mint["status"] = "active"
268
+ elif res.session_source == "invalid":
269
+ mint["status"] = "unrecognized"
270
+ if not mint:
271
+ return None
280
272
  return mint
281
273
 
282
274
 
283
275
  def mirror_into_structured_content(
284
276
  sc: Any, mint: dict[str, Any]
285
277
  ) -> dict[str, Any] | None:
286
- if not isinstance(sc, dict) or MCP_INSTRUCTIONS_KEY in sc:
278
+ if not isinstance(sc, dict) or MCP_SESSION_KEY in sc:
287
279
  return None
288
- return {**sc, MCP_INSTRUCTIONS_KEY: mint}
280
+ # Mirror first: an ID at the tail of a long payload is what clients
281
+ # truncate away.
282
+ return {MCP_SESSION_KEY: mint, **sc}
289
283
 
290
284
 
291
285
  def _clamp_tag_value(value: str) -> str: