diff --git a/src/sentry/investigations/agent.py b/src/sentry/investigations/agent.py index e6aca6cba2d2..db9e315819c3 100644 --- a/src/sentry/investigations/agent.py +++ b/src/sentry/investigations/agent.py @@ -57,6 +57,7 @@ MAX_TOOL_CONTENT_CHARS = 100_000 MAX_QUERY_LINK_PARAM_CHARS = 2000 IMPORT_NOT_ALLOWED_ERROR = "This import is not allowed in an investigation query." +SEER_CATEGORY_KEY = "investigation" PRIVATE_TRANSCRIPT_KEYS = { "authorization", "credentials", @@ -176,6 +177,8 @@ def start_execution_run( if client is None: client = SeerAgentClient(organization, user) client.on_completion_hook = InvestigationAgentCompletionHook + client.category_key = SEER_CATEGORY_KEY + client.category_value = str(execution.block.investigation_id) client.is_interactive = is_query client.enable_code_mode_tools = "only" if is_query else "off" client.enable_coding = False @@ -980,6 +983,8 @@ def _maybe_start_title_generation(investigation: Investigation, user_id: int | N client = SeerAgentClient( investigation.organization, user, + category_key=SEER_CATEGORY_KEY, + category_value=str(investigation.id), on_completion_hook=InvestigationAgentCompletionHook, enable_code_mode_tools="only", enable_coding=False, diff --git a/tests/sentry/investigations/test_agent.py b/tests/sentry/investigations/test_agent.py index dad23cdbe51c..eb928176a6ed 100644 --- a/tests/sentry/investigations/test_agent.py +++ b/tests/sentry/investigations/test_agent.py @@ -305,6 +305,14 @@ def test_start_run_includes_resolved_source_context(self) -> None: "2026-08-14T23:56:02+00:00" ) + def test_start_run_categorizes_the_run_as_an_investigation(self) -> None: + client = MagicMock() + + start_execution_run(self.execution, self.organization, self.user, client) + + assert client.category_key == "investigation" + assert client.category_value == str(self.investigation.id) + @patch("sentry.investigations.agent.record_execution_started") def test_start_run_records_execution_started(self, record_started: MagicMock) -> None: pending_execution = self.create_investigation_block_execution( @@ -1177,6 +1185,18 @@ def test_title_prompt_uses_specific_incident_source_context( assert "1 or 2 short" in prompt assert "Avoid headings and jargon" in prompt + @patch("sentry.investigations.agent.SeerAgentClient") + def test_title_generation_categorizes_the_run_as_an_investigation( + self, mock_client: MagicMock + ) -> None: + self.investigation.update(title=DEFAULT_INVESTIGATION_TITLE) + + _maybe_start_title_generation(self.investigation, None) + + kwargs = mock_client.call_args.kwargs + assert kwargs["category_key"] == "investigation" + assert kwargs["category_value"] == str(self.investigation.id) + @patch("sentry.investigations.agent.record_investigation_completed") @patch("sentry.investigations.agent.SeerAgentClient") def test_title_generation_waits_for_every_auto_run_block(