agentcat 2.0.2__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.
- {agentcat-2.0.2 → agentcat-2.1.0}/PKG-INFO +2 -2
- {agentcat-2.0.2 → agentcat-2.1.0}/pyproject.toml +1 -1
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/modules/adapters/_inner_tap.py +21 -2
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/modules/callpath.py +15 -12
- agentcat-2.1.0/src/agentcat/modules/constants.py +72 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/modules/handles.py +38 -44
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/modules/injection.py +60 -40
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/types.py +2 -2
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/utils.py +3 -2
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/community/test_community_v3_handles.py +24 -21
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/community/test_community_v3_nested_calls.py +5 -5
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/community/test_community_v3_openapi.py +7 -4
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/e2e/community_v3/test_agent_handle_http.py +21 -12
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/e2e/community_v3/test_event_capture_http.py +5 -2
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/e2e/community_v3/test_stateless_http.py +1 -1
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/e2e/community_v4/test_agent_handle_http.py +22 -13
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/e2e/community_v4/test_session_http.py +13 -6
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/e2e/community_v4/test_stateless_http.py +1 -1
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/e2e/official/test_agent_handle_http.py +18 -9
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/e2e/official/test_session_http.py +18 -8
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/e2e/official/test_stateless_http.py +1 -1
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/e2e/official_modern/test_agent_handle_http.py +21 -12
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/e2e/official_modern/test_mcpserver_http.py +18 -10
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/e2e/official_modern/test_session_http.py +18 -8
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/e2e/official_modern/test_stateless_http.py +1 -1
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_callpath.py +21 -16
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_community_v4_handles.py +16 -9
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_community_v4_nested_calls.py +4 -4
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_concurrency_handles.py +7 -7
- agentcat-2.1.0/tests/test_constants_copy.py +208 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_customer_owned_parameters.py +5 -5
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_dynamic_tracking.py +15 -8
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_handles.py +75 -26
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_injection.py +112 -58
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_inner_tap.py +69 -15
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_lowlevel_v1_handles.py +31 -22
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_lowlevel_v2_handles.py +27 -24
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_rebuild_on_demand.py +5 -5
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_removed_events.py +3 -1
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_report_missing.py +17 -16
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_response_shape.py +3 -3
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_session_id_validation.py +62 -37
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_tool_context.py +23 -20
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_utils/__init__.py +19 -0
- agentcat-2.0.2/src/agentcat/modules/constants.py +0 -70
- agentcat-2.0.2/tests/test_constants_copy.py +0 -198
- {agentcat-2.0.2 → agentcat-2.1.0}/.gitignore +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/CONTRIBUTING.md +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/LICENSE +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/README.md +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/docs/cats/bibi.png +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/docs/cats/void.jpg +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/docs/cats/zelda.jpg +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/docs/static/architecture.png +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/docs/static/og-image.png +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/__init__.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/modules/__init__.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/modules/adapters/__init__.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/modules/adapters/_common.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/modules/adapters/community.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/modules/adapters/lowlevel_v1.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/modules/adapters/lowlevel_v2.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/modules/client_identity.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/modules/detection.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/modules/diagnostics.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/modules/event_queue.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/modules/exceptions.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/modules/exporters/__init__.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/modules/exporters/datadog.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/modules/exporters/otlp.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/modules/exporters/sentry.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/modules/exporters/trace_context.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/modules/hooks.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/modules/identify.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/modules/internal.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/modules/logging.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/modules/redaction.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/modules/request_extra.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/modules/sanitization.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/modules/telemetry.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/modules/tools.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/modules/truncation.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/modules/validation.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/thirdparty/__init__.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/thirdparty/ksuid/__init__.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/thirdparty/ksuid/baseconv.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/src/agentcat/thirdparty/ksuid/ksuid.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/__init__.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/community/__init__.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/community/test_community_v3_event_serialization.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/community/test_community_v3_inject_context.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/community/test_community_v3_runtime_state_tools.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/conftest.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/e2e/__init__.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/e2e/_helpers.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/e2e/community_v3/__init__.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/e2e/community_v3/conftest.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/e2e/community_v3/test_identify_http.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/e2e/community_v3/test_request_extra_http.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/e2e/community_v4/__init__.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/e2e/community_v4/conftest.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/e2e/community_v4/test_identify_http.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/e2e/conftest.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/e2e/official/__init__.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/e2e/official/conftest.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/e2e/official/test_event_capture_http.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/e2e/official/test_identify_http.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/e2e/official/test_redaction_http.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/e2e/official/test_request_extra_http.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/e2e/official_modern/__init__.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/e2e/official_modern/conftest.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/e2e/official_modern/test_identify_http.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_api_base_url.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_async_hooks.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_client_identity.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_detection.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_diagnostics_attributes.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_diagnostics_auth.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_diagnostics_export.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_diagnostics_integration.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_diagnostics_no_payload.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_diagnostics_optout.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_diagnostics_record.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_diagnostics_sink.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_diagnostics_test_env.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_event_capture_completeness.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_event_queue.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_event_tags_properties.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_exceptions.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_exporter_sdk_version.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_hook_offload.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_identify_shape.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_logging.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_multiple_servers.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_options_v2.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_process_safety.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_publish_custom_event.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_redaction.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_request_extra.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_sanitization.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_tag_validation.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_truncation.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_truncation_json_safe.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_utils/client.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_utils/community_catalog_server.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_utils/community_client.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_utils/community_openapi_server.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_utils/community_todo_server.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_utils/delivery.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_utils/flavors.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_utils/modern_server.py +0 -0
- {agentcat-2.0.2 → agentcat-2.1.0}/tests/test_utils/todo_server.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: agentcat
|
|
3
|
-
Version: 2.0
|
|
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
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "agentcat"
|
|
3
|
-
version = "2.0
|
|
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" },
|
|
@@ -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
|
-
|
|
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
|
|
161
|
-
handler. The fallback also clears the
|
|
162
|
-
structured mirror stops gating on
|
|
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
|
|
229
|
+
"""The leading mint-back block, or None to leave the result untouched.
|
|
228
230
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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 [
|
|
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}"
|
|
@@ -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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
225
|
+
MINT_BACK_HEADER_ISSUED,
|
|
233
226
|
mint_back_session_line(res.session_id),
|
|
234
|
-
|
|
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
|
-
#
|
|
242
|
-
# issued one:
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
278
|
+
if not isinstance(sc, dict) or MCP_SESSION_KEY in sc:
|
|
287
279
|
return None
|
|
288
|
-
|
|
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:
|
|
@@ -9,7 +9,7 @@ listWrap.buildInjectedList.
|
|
|
9
9
|
|
|
10
10
|
Two passes over the tools, in order:
|
|
11
11
|
|
|
12
|
-
1. Handle pass — session_id/agent_id input params plus the
|
|
12
|
+
1. Handle pass — session_id/agent_id input params plus the mcp_session
|
|
13
13
|
outputSchema extension. Runs only when at least one handle is injectable
|
|
14
14
|
(prompted-mode tracing -> session_id, agent tracking -> agent_id); when
|
|
15
15
|
neither is, the pass is skipped wholesale and schemas keep their original
|
|
@@ -20,10 +20,11 @@ Two passes over the tools, in order:
|
|
|
20
20
|
events.
|
|
21
21
|
|
|
22
22
|
Resulting property order: customer params, session_id, agent_id, context.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
Every injected param is appended to required, and session_id also declares
|
|
24
|
+
the start|ses_ value pattern; both are client-side compliance only, since
|
|
25
|
+
callWrap tolerates an absent or malformed value (treating it as the start
|
|
26
|
+
of a new task), and schema-aware clients are the only enforcement an
|
|
27
|
+
injected parameter has.
|
|
27
28
|
"""
|
|
28
29
|
|
|
29
30
|
from collections.abc import Iterable
|
|
@@ -33,15 +34,18 @@ from typing import Any
|
|
|
33
34
|
from agentcat.modules.constants import (
|
|
34
35
|
AGENT_ID_PARAM,
|
|
35
36
|
AGENT_ID_PARAM_DESCRIPTION,
|
|
36
|
-
AGENT_ID_PARAM_DESCRIPTION_HOOK_MODE,
|
|
37
37
|
CONTEXT_PARAM,
|
|
38
38
|
GET_MORE_TOOLS_NAME,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
MCP_SESSION_AGENT_ID_DESCRIPTION,
|
|
40
|
+
MCP_SESSION_FIELD_DESCRIPTION,
|
|
41
|
+
MCP_SESSION_FIELD_DESCRIPTION_HOOK_MODE,
|
|
42
|
+
MCP_SESSION_KEY,
|
|
43
|
+
MCP_SESSION_SESSION_ID_DESCRIPTION,
|
|
44
|
+
MCP_SESSION_STATUS_DESCRIPTION,
|
|
43
45
|
SESSION_ID_PARAM,
|
|
44
46
|
SESSION_ID_PARAM_DESCRIPTION,
|
|
47
|
+
SESSION_ID_PARAM_PATTERN,
|
|
48
|
+
SESSION_START_SENTINEL,
|
|
45
49
|
)
|
|
46
50
|
from agentcat.modules.logging import write_to_log
|
|
47
51
|
from agentcat.types import AgentCatOptions
|
|
@@ -69,7 +73,7 @@ class InjectionResult:
|
|
|
69
73
|
|
|
70
74
|
injected_params has an entry for EVERY tool seen (possibly empty), so
|
|
71
75
|
the strip fallback applies only to tools never seen in any listing.
|
|
72
|
-
output_injected lists tools whose outputSchema gained
|
|
76
|
+
output_injected lists tools whose outputSchema gained mcp_session.
|
|
73
77
|
declared_session_params lists tools whose OWN schema declared
|
|
74
78
|
`session_id`; see `build_injected_schemas` for why that is a separate
|
|
75
79
|
signal rather than "absent from injected_params".
|
|
@@ -80,30 +84,40 @@ class InjectionResult:
|
|
|
80
84
|
declared_session_params: set[str] = field(default_factory=set)
|
|
81
85
|
|
|
82
86
|
|
|
83
|
-
def
|
|
87
|
+
def mcp_session_schema_property(
|
|
84
88
|
include_session_id: bool, include_agent_id: bool
|
|
85
89
|
) -> dict[str, Any]:
|
|
86
|
-
"""Build a fresh
|
|
90
|
+
"""Build a fresh mcp_session outputSchema fragment.
|
|
87
91
|
|
|
88
|
-
Sub-properties mirror the modes — no session_id in hook mode,
|
|
89
|
-
when tracking is off — so the copy never references a
|
|
90
|
-
agent cannot see. `
|
|
92
|
+
Sub-properties mirror the modes — no session_id or status in hook mode,
|
|
93
|
+
no agent_id when tracking is off — so the copy never references a
|
|
94
|
+
parameter the agent cannot see. Hook mode is `include_session_id` False
|
|
95
|
+
with `include_agent_id` on, and carries its own field description.
|
|
91
96
|
"""
|
|
92
97
|
sub_properties: dict[str, Any] = {}
|
|
93
98
|
if include_session_id:
|
|
94
99
|
sub_properties[SESSION_ID_PARAM] = {
|
|
95
100
|
"type": "string",
|
|
96
|
-
"description":
|
|
101
|
+
"description": MCP_SESSION_SESSION_ID_DESCRIPTION,
|
|
97
102
|
}
|
|
98
103
|
if include_agent_id:
|
|
99
104
|
sub_properties[AGENT_ID_PARAM] = {
|
|
100
105
|
"type": "string",
|
|
101
|
-
"description":
|
|
106
|
+
"description": MCP_SESSION_AGENT_ID_DESCRIPTION,
|
|
107
|
+
}
|
|
108
|
+
if include_session_id:
|
|
109
|
+
sub_properties["status"] = {
|
|
110
|
+
"type": "string",
|
|
111
|
+
"enum": ["issued", "active", "unrecognized"],
|
|
112
|
+
"description": MCP_SESSION_STATUS_DESCRIPTION,
|
|
102
113
|
}
|
|
103
|
-
sub_properties["instructions"] = {"type": "string"}
|
|
104
114
|
return {
|
|
105
115
|
"type": "object",
|
|
106
|
-
"description":
|
|
116
|
+
"description": (
|
|
117
|
+
MCP_SESSION_FIELD_DESCRIPTION
|
|
118
|
+
if include_session_id
|
|
119
|
+
else MCP_SESSION_FIELD_DESCRIPTION_HOOK_MODE
|
|
120
|
+
),
|
|
107
121
|
"properties": sub_properties,
|
|
108
122
|
}
|
|
109
123
|
|
|
@@ -115,6 +129,7 @@ def _inject_param(
|
|
|
115
129
|
description: str,
|
|
116
130
|
required: bool,
|
|
117
131
|
entry: set[str],
|
|
132
|
+
pattern: str | None = None,
|
|
118
133
|
) -> None:
|
|
119
134
|
"""Add one string param, honoring collisions and the required array."""
|
|
120
135
|
properties = schema.setdefault("properties", {})
|
|
@@ -124,7 +139,10 @@ def _inject_param(
|
|
|
124
139
|
f"Skipping {name} injection."
|
|
125
140
|
)
|
|
126
141
|
return
|
|
127
|
-
|
|
142
|
+
prop: dict[str, Any] = {"type": "string", "description": description}
|
|
143
|
+
if pattern is not None:
|
|
144
|
+
prop["pattern"] = pattern
|
|
145
|
+
properties[name] = prop
|
|
128
146
|
if required:
|
|
129
147
|
existing = schema.get("required")
|
|
130
148
|
if isinstance(existing, list):
|
|
@@ -205,18 +223,14 @@ def _add_handle_parameters(
|
|
|
205
223
|
schema,
|
|
206
224
|
SESSION_ID_PARAM,
|
|
207
225
|
SESSION_ID_PARAM_DESCRIPTION,
|
|
208
|
-
|
|
226
|
+
True,
|
|
209
227
|
entry,
|
|
228
|
+
pattern=SESSION_ID_PARAM_PATTERN,
|
|
210
229
|
)
|
|
211
230
|
if inject_agent_id:
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
description = (
|
|
215
|
-
AGENT_ID_PARAM_DESCRIPTION
|
|
216
|
-
if inject_session_id
|
|
217
|
-
else AGENT_ID_PARAM_DESCRIPTION_HOOK_MODE
|
|
231
|
+
_inject_param(
|
|
232
|
+
tool.name, schema, AGENT_ID_PARAM, AGENT_ID_PARAM_DESCRIPTION, True, entry
|
|
218
233
|
)
|
|
219
|
-
_inject_param(tool.name, schema, AGENT_ID_PARAM, description, True, entry)
|
|
220
234
|
|
|
221
235
|
_extend_output_schema(tool, inject_session_id, inject_agent_id, result)
|
|
222
236
|
|
|
@@ -227,7 +241,7 @@ def _extend_output_schema(
|
|
|
227
241
|
inject_agent_id: bool,
|
|
228
242
|
result: InjectionResult,
|
|
229
243
|
) -> None:
|
|
230
|
-
"""Declare the optional
|
|
244
|
+
"""Declare the optional mcp_session property on a plain-object
|
|
231
245
|
outputSchema so schema-validating clients accept the mirrored field.
|
|
232
246
|
|
|
233
247
|
Never added to required. Composed schemas have no single properties bag
|
|
@@ -240,18 +254,18 @@ def _extend_output_schema(
|
|
|
240
254
|
if any(key in schema for key in _COMPOSED_KEYS):
|
|
241
255
|
write_to_log(
|
|
242
256
|
f'WARN: Tool "{tool.name}" has complex outputSchema '
|
|
243
|
-
f"(oneOf/allOf/anyOf). Skipping {
|
|
257
|
+
f"(oneOf/allOf/anyOf). Skipping {MCP_SESSION_KEY} injection; "
|
|
244
258
|
"mint-back stays content-only for this tool."
|
|
245
259
|
)
|
|
246
260
|
return
|
|
247
261
|
properties = schema.setdefault("properties", {})
|
|
248
|
-
if
|
|
262
|
+
if MCP_SESSION_KEY in properties:
|
|
249
263
|
write_to_log(
|
|
250
264
|
f'WARN: Tool "{tool.name}" already declares '
|
|
251
|
-
f"'{
|
|
265
|
+
f"'{MCP_SESSION_KEY}' in outputSchema. Skipping injection."
|
|
252
266
|
)
|
|
253
267
|
return
|
|
254
|
-
properties[
|
|
268
|
+
properties[MCP_SESSION_KEY] = mcp_session_schema_property(
|
|
255
269
|
inject_session_id, inject_agent_id
|
|
256
270
|
)
|
|
257
271
|
result.output_injected.add(tool.name)
|
|
@@ -270,8 +284,9 @@ def _add_context_parameter(tool: ToolSpec, description: str, entry: set[str]) ->
|
|
|
270
284
|
means agents quietly stop supplying it and `user_intent` coverage decays
|
|
271
285
|
with nothing to show for it.
|
|
272
286
|
|
|
273
|
-
`session_id` is the
|
|
274
|
-
an agent
|
|
287
|
+
`session_id` is required the same way, with `start` as its explicit
|
|
288
|
+
first-call value — an agent asks to be minted one by sending the sentinel,
|
|
289
|
+
and an absent value still mints so a stale schema never errors.
|
|
275
290
|
"""
|
|
276
291
|
schema = tool.input_schema
|
|
277
292
|
properties = schema.get("properties")
|
|
@@ -359,7 +374,8 @@ def injected_parameter_names(
|
|
|
359
374
|
|
|
360
375
|
- `session_id` counts as ours iff prompted-mode tracing would have
|
|
361
376
|
injected it (`enable_tracing` on, no `resolve_session_id` hook) AND the
|
|
362
|
-
value the agent sent is absent
|
|
377
|
+
value the agent sent is absent, the `start` sentinel our copy tells
|
|
378
|
+
agents to send first, or our minted `ses_` KSUID shape.
|
|
363
379
|
A non-minted value is presumed the customer's own parameter: it is not
|
|
364
380
|
stripped, and — because this same set feeds `resolve_handles` — it is
|
|
365
381
|
not branded invalid or corrected on the wire either.
|
|
@@ -388,10 +404,14 @@ def injected_parameter_names(
|
|
|
388
404
|
names: set[str] = set()
|
|
389
405
|
if opts.enable_tracing and opts.resolve_session_id is None:
|
|
390
406
|
value = args.get(SESSION_ID_PARAM)
|
|
391
|
-
|
|
392
|
-
isinstance(value, str)
|
|
407
|
+
looks_ours = value is None or (
|
|
408
|
+
isinstance(value, str)
|
|
409
|
+
and (
|
|
410
|
+
value.strip().lower() == SESSION_START_SENTINEL
|
|
411
|
+
or is_valid_session_id(value.strip())
|
|
412
|
+
)
|
|
393
413
|
)
|
|
394
|
-
if
|
|
414
|
+
if looks_ours:
|
|
395
415
|
names.add(SESSION_ID_PARAM)
|
|
396
416
|
if opts.enable_tracing and opts.enable_agent_tracking:
|
|
397
417
|
names.add(AGENT_ID_PARAM)
|
|
@@ -262,7 +262,7 @@ class AgentCatOptions:
|
|
|
262
262
|
event_properties: EventPropertiesFunction | None = None
|
|
263
263
|
# Default False. Set True to inject a required agent_id parameter into every
|
|
264
264
|
# tool. Agents self-generate the value (model|harness|nonce, e.g.
|
|
265
|
-
# "opus-4.80-1m|claude-code|k3n9x"); it is echoed back in
|
|
265
|
+
# "opus-4.80-1m|claude-code|k3n9x"); it is echoed back in mcp_session
|
|
266
266
|
# and stamped on events as tags. Omission never rejects a call server-side —
|
|
267
267
|
# the event is simply published without agent identity. The intended
|
|
268
268
|
# enforcement is client-side: a strict schema-validating MCP client will
|
|
@@ -294,7 +294,7 @@ class AgentCatData:
|
|
|
294
294
|
# Per-tool set of parameter names AgentCat injected into the schema
|
|
295
295
|
# (context/session_id/agent_id), so they can be stripped before the tool runs.
|
|
296
296
|
injected_params_registry: dict[str, set[str]] | None = None
|
|
297
|
-
# Tools whose results receive an
|
|
297
|
+
# Tools whose results receive an mcp_session injection.
|
|
298
298
|
output_injection_registry: set[str] | None = None
|
|
299
299
|
# Tools whose OWN input schema declares `session_id` — the customer's
|
|
300
300
|
# parameter, never ours to read at call time. Membership only ever grows;
|
|
@@ -59,7 +59,7 @@ def generate_prefixed_ksuid(
|
|
|
59
59
|
prefix: str, use_milliseconds: bool = False, dt: Optional[datetime] = None
|
|
60
60
|
) -> str:
|
|
61
61
|
"""
|
|
62
|
-
Generate a prefixed KSUID (e.g., "
|
|
62
|
+
Generate a prefixed KSUID (e.g., "ses_2cOHEO0LYGADMzRvWTXXVbbgxgm").
|
|
63
63
|
|
|
64
64
|
Args:
|
|
65
65
|
prefix: The prefix to add (e.g., "ses", "usr", "evt")
|
|
@@ -96,7 +96,8 @@ def parse_prefixed_ksuid(
|
|
|
96
96
|
Parse a prefixed KSUID string back into its prefix and Ksuid object.
|
|
97
97
|
|
|
98
98
|
Args:
|
|
99
|
-
prefixed_ksuid: The prefixed KSUID string
|
|
99
|
+
prefixed_ksuid: The prefixed KSUID string
|
|
100
|
+
(e.g., "ses_2cOHEO0LYGADMzRvWTXXVbbgxgm")
|
|
100
101
|
use_milliseconds: If True, parses as KsuidMs
|
|
101
102
|
|
|
102
103
|
Returns:
|