:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(aeo): call claude web search directly so answers carry citations (#122246)
Lucas Ricoy0dece895c102
diff --git a/products/aeo/backend/engines.py b/products/aeo/backend/engines.pyindex daabcfd5a8c6..e8706d4eeadb 100644--- a/products/aeo/backend/engines.py+++ b/products/aeo/backend/engines.py@@ -355,6 +355,11 @@ class ClaudeWebSearchEngine:"type": ANTHROPIC_WEB_SEARCH_TOOL_TYPE,"name": "web_search","max_uses": MAX_WEB_SEARCHES_PER_PROMPT,+ # This tool version runs searches from code execution by default. Claude then reads+ # the results through encrypted stdout, and the answer text carries no citations.+ # Direct calls attach web_search_result_location citations, and they keep the tool+ # eligible for zero data retention.+ "allowed_callers": ["direct"],}],}diff --git a/products/aeo/backend/test/test_engines.py b/products/aeo/backend/test/test_engines.pyindex 531f60d28624..8db3f963aa25 100644--- a/products/aeo/backend/test/test_engines.py+++ b/products/aeo/backend/test/test_engines.py@@ -7,6 +7,7 @@ from parameterized import parameterizedfrom products.aeo.backend.engines import (OPENAI_MAX_OUTPUT_TOKENS,CitationCheck,+ ClaudeWebSearchEngine,OpenAIWebSearchEngine,anthropic_truncated_error,build_check_fields,@@ -219,6 +220,29 @@ def test_openai_engine_run_wires_response_error(_name: str, body: dict, expectedassert check.cited_urls # completed body carries citations+def test_claude_engine_calls_web_search_directly() -> None:+ captured: dict = {}++ def fake_post(_session, _url, _headers, payload, **_kwargs):+ captured["payload"] = payload+ return ANTHROPIC_BODY++ with (+ patch(+ "products.aeo.backend.engines.resolve_ai_gateway_config",+ return_value=SimpleNamespace(url="https://gw.test/v1", api_key="k"),+ ),+ patch("products.aeo.backend.engines.ai_gateway_headers", return_value={}),+ patch("products.aeo.backend.engines.gateway_post_json", side_effect=fake_post),+ ):+ check = ClaudeWebSearchEngine().run("best session replay tool", trace_id="t1", custom_properties={})++ [tool] = captured["payload"]["tools"]+ assert tool["allowed_callers"] == ["direct"]+ assert check.error is None+ assert check.cited_urls == ["https://posthog.com/session-replay", "https://example.com/reviews"]++def test_parse_exa_citations() -> None:parsed = parse_exa_citations(EXA_BODY)assert parsed.answer_text == "PostHog is one option."