Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
1b3072b
feat(python): share one attachment manager across the auto module
nik13 Nov 11, 2026
dc69e51
test(python): expect the F01 PII denial reason for a tightened borrow…
nik13 Nov 11, 2026
7c6ef0d
feat(python): capture MCP, agent SDK, smolagents and Firecrawl tool m…
nik13 Nov 11, 2026
3ed3321
test(python): MCP/agent attachment suites, CI workflow and README sec…
nik13 Nov 11, 2026
ecfac0c
test(python): fix fixtures for real SDK floors and the root requests …
nik13 Nov 11, 2026
be331c3
test(python): cover Firecrawl crawl-status documents
nik13 Nov 11, 2026
0b2eb4b
fix(python): name the per-call capture-policy context key like the TS…
nik13 Nov 11, 2026
abdfcca
Merge feat/attachments-python-mcp-agents (be331c39) into feat/attachm…
nik13 Nov 11, 2026
42724ea
feat(python): register the MCP and agent media adapters in the auto m…
nik13 Nov 11, 2026
a598b9a
ci(python): pin mcp below 2 in the all-six auto row (mcp-use 1.7.1 ne…
nik13 Nov 11, 2026
d8ee8cd
fix(python): project Claude Agent SDK tool media on a live tool span;…
nik13 Nov 12, 2026
92939ee
test(python): MCP error results follow hide_error_details
nik13 Nov 12, 2026
2e6778d
Merge commit '92939ee9922c1d455a31756ae8ddf70a0214a3f9' into c5-py-au…
nik13 Nov 12, 2026
c53acf3
feat(python): auto registry and report rows for provider and framewor…
nik13 Nov 12, 2026
dd79fcf
fix(python): pass attachments to Agno only when its media adapter is …
nik13 Nov 12, 2026
4901f03
fix(python): per-client Claude tool-span deferral, live-conversation …
nik13 Nov 12, 2026
50370aa
Merge commit '4901f03d' into c8-auto-integrate2
nik13 Nov 12, 2026
2010273
fix(python): auto skips Agno media when trace_config sets a flag Agno…
nik13 Nov 12, 2026
67e5cbc
test(python): auto framework+OpenAI one-upload rows and Agno config_u…
nik13 Nov 12, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions .github/workflows/attachments-python-mcp-agents-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: Python MCP and agent attachments

# Real MCP, mcp-use, OpenAI Agents SDK, Claude Agent SDK, smolagents and
# firecrawl-py releases (declared floor and latest) through the Python
# instrumentors to a TLS loopback F01 attachment server. Outbound network is
# disabled while the tests run.

on:
pull_request:
paths:
- 'python/fi_instrumentation/attachments/**'
- 'python/frameworks/mcp/**'
- 'python/frameworks/mcp-use/**'
- 'python/frameworks/openai-agents/**'
- 'python/frameworks/claude-agent-sdk/**'
- 'python/frameworks/smolagents/**'
- 'python/frameworks/firecrawl/**'
- 'python/tests/attachments_mcp_agents/**'
- 'python/tests/attachments_providers/conftest.py'
- 'python/traceai/**'
- '.github/workflows/attachments-python-mcp-agents-tests.yml'
push:
branches: [dev]
paths:
- 'python/fi_instrumentation/attachments/**'
- 'python/frameworks/mcp/**'
- 'python/frameworks/mcp-use/**'
- 'python/frameworks/openai-agents/**'
- 'python/frameworks/claude-agent-sdk/**'
- 'python/frameworks/smolagents/**'
- 'python/frameworks/firecrawl/**'
- 'python/tests/attachments_mcp_agents/**'
- 'python/tests/attachments_providers/conftest.py'
- 'python/traceai/**'
- '.github/workflows/attachments-python-mcp-agents-tests.yml'
workflow_dispatch:

permissions:
contents: read

env:
MCP_USE_ANONYMIZED_TELEMETRY: 'false'
MCP_USE_LANGFUSE: 'false'
MCP_USE_LAMINAR: 'false'

jobs:
attachments:
name: ${{ matrix.package }} attachments (${{ matrix.tier }})
runs-on: ubuntu-24.04
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
include:
- {package: core, tier: latest, python: '3.12', path: '', suite: test_tool_media.py, sdks: 'pillow'}
- {package: mcp, tier: floor, python: '3.11', path: mcp, suite: test_mcp_attachments.py, sdks: 'mcp==1.30.0'}
- {package: mcp, tier: latest, python: '3.12', path: mcp, suite: test_mcp_attachments.py, sdks: 'mcp==2.3.0'}
- {package: mcp-use, tier: floor, python: '3.11', path: mcp-use, suite: test_mcp_use_attachments.py,
sdks: 'mcp-use==1.7.1 langchain-core==1.6.12'}
- {package: mcp-use, tier: latest, python: '3.12', path: mcp-use, suite: test_mcp_use_attachments.py,
sdks: 'mcp-use==1.7.1'}
# 0.2.6 is the declared floor; computer calls get a function span from 0.10.0.
- {package: openai-agents, tier: floor, python: '3.11', path: openai-agents,
suite: test_openai_agents_attachments.py, sdks: 'openai-agents==0.2.6'}
- {package: openai-agents, tier: computer-span, python: '3.12', path: openai-agents,
suite: test_openai_agents_attachments.py, sdks: 'openai-agents==0.10.0 openai==2.19.0'}
- {package: openai-agents, tier: latest, python: '3.12', path: openai-agents,
suite: test_openai_agents_attachments.py, sdks: 'openai-agents==0.24.0'}
- {package: claude-agent-sdk, tier: floor, python: '3.11', path: claude-agent-sdk,
suite: test_claude_agent_sdk_attachments.py, sdks: 'claude-agent-sdk==0.1.0'}
- {package: claude-agent-sdk, tier: latest, python: '3.12', path: claude-agent-sdk,
suite: test_claude_agent_sdk_attachments.py, sdks: 'claude-agent-sdk==0.2.180'}
- {package: smolagents, tier: floor, python: '3.11', path: smolagents, suite: test_smolagents_attachments.py,
sdks: 'smolagents==1.12.0 openai'}
- {package: smolagents, tier: latest, python: '3.12', path: smolagents, suite: test_smolagents_attachments.py,
sdks: 'smolagents==1.26.0 openai'}
- {package: firecrawl, tier: floor, python: '3.11', path: firecrawl, suite: test_firecrawl_attachments.py,
sdks: 'firecrawl-py==4.46.2'}
- {package: firecrawl, tier: latest, python: '3.12', path: firecrawl, suite: test_firecrawl_attachments.py,
sdks: 'firecrawl-py==4.55.0'}
# traceai.init enabling all six by name (registry, report rows, capture through auto).
- {package: auto, tier: latest, python: '3.12', expect: '1', suite: test_auto_registry.py,
path: 'mcp mcp-use openai-agents claude-agent-sdk smolagents firecrawl',
sdks: 'mcp>=1.30.0,<2 mcp-use==1.7.1 openai-agents==0.24.0 claude-agent-sdk==0.2.180 smolagents==1.26.0 openai pillow firecrawl-py==4.55.0'}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: ${{ matrix.python }}
- name: Install the source integration and the selected SDK
env:
SDKS: ${{ matrix.sdks }}
PKG_PATH: ${{ matrix.path }}
run: |
python -m venv .venv
extra=""
for pkg in $PKG_PATH; do extra="$extra -e python/frameworks/$pkg"; done
# shellcheck disable=SC2086
.venv/bin/pip install -e python $extra opentelemetry-sdk 'pytest>=8,<9' 'pytest-asyncio<0.25' packaging $SDKS
.venv/bin/pip freeze | grep -iE '^(mcp|mcp-use|openai-agents|openai|claude-agent-sdk|smolagents|firecrawl-py|pillow|langchain-core)==' || true
- name: Run with outbound network disabled
env:
SUITE: ${{ matrix.suite }}
TRACEAI_EXPECT_MCP_AGENT_ADAPTERS: ${{ matrix.expect || '0' }}
run: |
sudo --preserve-env=MCP_USE_ANONYMIZED_TELEMETRY,MCP_USE_LANGFUSE,MCP_USE_LAMINAR,TRACEAI_EXPECT_MCP_AGENT_ADAPTERS unshare --net -- bash -e -c '
ip link set lo up
cd "$2/python"
PYTHONPATH=. "$1" -m pytest "tests/attachments_mcp_agents/$3" -q -p no:cacheprovider -o addopts="" \
-o faulthandler_timeout=120
' _ "$PWD/.venv/bin/python" "$PWD" "$SUITE"
53 changes: 52 additions & 1 deletion python/fi_instrumentation/attachments/media_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
- One registry per manager remembers admitted (span, position) pairs, so a
second observer of the same span and position gets the FIRST occurrence back
and uploads nothing.
- A per-call ``CapturePolicy`` set in the OpenTelemetry context under
``CAPTURE_POLICY_KEY`` (``traceai.with_attachment_capture_policy``) can only
add restrictions. A context marked under ``OWNER_KEY``
(``traceai.with_attachment_ownership``) belongs to an adapter that captures
the media itself, so nothing is captured here for that call.

Every public function is non-throwing and returns ``None``/empty on denial.
"""
Expand All @@ -26,6 +31,8 @@
from collections import OrderedDict
from typing import Any, Callable, Iterable, Mapping, NamedTuple, Optional, Tuple

from opentelemetry import context as otel_context

from .policy import CapturePolicy
from .stream import StreamOptions
from .types import Bytes, CorrelationHandle
Expand All @@ -50,6 +57,13 @@
# mulaw have no F01 MIME, so they are never captured.
SPEECH_FORMATS = {"mp3": "audio/mpeg", "opus": "audio/ogg", "ogg": "audio/ogg", "flac": "audio/flac",
"wav": "audio/wav"}
# Context keys shared BY NAME with the auto module (``traceai``) and any adapter, like the
# TypeScript ``Symbol.for`` keys: plain strings, so no package has to import another.
CAPTURE_POLICY_KEY = "traceai.auto.attachment_policy.v1"
OWNER_KEY = "traceai.auto.attachment_owner.v1"
# CapturePolicy facts that grant capture; every other fact only restricts.
_PERMISSIONS = frozenset(("capture_content", "record_inputs", "record_outputs", "requested"))
_DENY_ALL = CapturePolicy(capture_content=False, requested=False)


class Occurrence(NamedTuple):
Expand Down Expand Up @@ -93,6 +107,40 @@ def _restricted(config, name: str) -> bool:
return True


def merge_capture_policies(*policies: Any) -> CapturePolicy:
"""Deny-wins intersection: a grant needs every policy, a restriction needs any one.

``None`` adds nothing. Any other value that is not a ``CapturePolicy`` denies.
"""
present = [policy for policy in policies if policy is not None]
if any(not isinstance(policy, CapturePolicy) for policy in present):
return _DENY_ALL
if not present:
return CapturePolicy()
values = {}
for item in dataclasses.fields(CapturePolicy):
facts = [getattr(policy, item.name) for policy in present]
values[item.name] = all(facts) if item.name in _PERMISSIONS else any(facts)
return CapturePolicy(**values)


def context_capture_policy(context=None) -> Any:
"""The per-call policy in the (current) OpenTelemetry context; None when unset."""
try:
return otel_context.get_value(CAPTURE_POLICY_KEY, context)
except Exception:
# An unreadable restriction is a restriction, never permission.
return _DENY_ALL


def owned_elsewhere(context=None) -> bool:
"""True when another adapter marked this call's media as its own."""
try:
return otel_context.get_value(OWNER_KEY, context) is not None
except Exception:
return True


def local_capture_policy(trace_config=None, *, direction: str, image: bool = False, error_detail: bool = False,
base: Optional[CapturePolicy] = None) -> CapturePolicy:
"""Fold the instrumentor's local TraceConfig into a deny-only CapturePolicy.
Expand All @@ -103,6 +151,7 @@ def local_capture_policy(trace_config=None, *, direction: str, image: bool = Fal
ancestry, so a tool screenshot is still treated as model input.
"""
base = base if isinstance(base, CapturePolicy) else CapturePolicy()
base = merge_capture_policies(base, context_capture_policy())
names = _INPUT_HIDE if direction == "input" else _OUTPUT_HIDE
hidden = any(_restricted(trace_config, name) for name in names) or _restricted(trace_config, "pii_redaction")
if image and direction == "input" and _restricted(trace_config, "hide_input_images"):
Expand All @@ -116,6 +165,8 @@ def local_capture_policy(trace_config=None, *, direction: str, image: bool = Fal
changes["model_input"] = True
if error_detail:
changes["error_detail"] = True
if owned_elsewhere():
changes["requested"] = False
return dataclasses.replace(base, **changes)


Expand Down Expand Up @@ -262,7 +313,7 @@ class Observation:

def __init__(self, manager, span, namespace: str):
self.manager, self.span, self.namespace = manager, span, namespace
self.key = span_key(span) if active(manager) else None
self.key = span_key(span) if active(manager) and not owned_elsewhere() else None
self.captured: "OrderedDict[str, Occurrence]" = OrderedDict()
self._visited = 0

Expand Down
Loading
Loading