Superagent

Overview

respan-instrumentation-superagent is an instrumentation plugin that captures calls from the Superagent safety-agent SDK and sends them to Respan through the unified OpenTelemetry pipeline.

It monkey-patches safety_agent.client.SafetyClient methods and emits canonical Respan spans for guard, redact, scan, and future compatible Superagent methods.

$pip install respan-ai respan-instrumentation-superagent safety-agent

Version: 0.1.0 | Python: >=3.11, <3.14

Dependencies

PackageVersion
respan-tracing^2.16.1
respan-sdk>=2.5.0
safety-agent>=0.1.5

Quick start

1from respan import Respan
2from respan_instrumentation_superagent import SuperagentInstrumentor
3from safety_agent import create_client
4
5respan = Respan(
6 api_key="your-respan-api-key",
7 instrumentations=[SuperagentInstrumentor()],
8)
9
10client = create_client()
11result = await client.guard(input="Check this content for safety.")
12print(result.classification)
13respan.flush()

Public API

SuperagentInstrumentor

The main instrumentor class. Implements the Instrumentation protocol.

1from respan_instrumentation_superagent import SuperagentInstrumentor
Attribute/MethodTypeDescription
namestr"superagent" — unique plugin identifier.
activate()() -> NonePatches compatible SafetyClient methods.
deactivate()() -> NoneRestores the original SafetyClient methods when the last active instrumentor is deactivated.

Constructor

1SuperagentInstrumentor(methods=("guard", "redact", "scan", "test"))
ParameterTypeDefaultDescription
methodstuple[str, ...] | NoneNoneOptional method allowlist. Defaults to all supported Superagent methods. Missing methods are skipped for SDK-version compatibility.

Captured operations

Superagent MethodLog TypeDescription
guardguardrailPrompt-injection and safety classification.
redacttoolPII or sensitive-content redaction.
scantoolRepository safety analysis.
testtoolFuture-compatible Superagent test method when present in the installed SDK.

Span attributes

All emitted spans include:

AttributeDescription
respan.entity.log_typeguardrail for guard; tool for the other operations.
traceloop.entity.nameOperation name, for example superagent.guard.
traceloop.entity.pathOperation path used for parent-child trace nesting.
traceloop.entity.inputJSON-serialized method arguments.
traceloop.entity.outputJSON-serialized result or error.
respan.metadata.integrationAlways superagent.
respan.metadata.superagent_methodCaptured method name.
respan.metadata.superagent_modelModel argument when provided.

guard() spans additionally include:

AttributeDescription
respan.metadata.guardrail_namesuperagent.guard.
respan.metadata.triggeredWhether the guard classification was block.
respan.metadata.superagent_classificationpass or block.

With propagated attributes

Use propagate_attributes() to attach per-request metadata to all Superagent spans:

1from respan import Respan, propagate_attributes
2from respan_instrumentation_superagent import SuperagentInstrumentor
3from safety_agent import create_client
4
5respan = Respan(instrumentations=[SuperagentInstrumentor()])
6client = create_client()
7
8async def handle_user_request(user_id: str, message: str):
9 with propagate_attributes(
10 customer_identifier=user_id,
11 thread_identifier="thread-123",
12 metadata={"surface": "chat-input"},
13 ):
14 result = await client.guard(input=message)
15 return result.classification

With decorators

Combine Superagent instrumentation with decorators when you want application-level structure around safety checks:

1from respan import Respan, task, workflow
2from respan_instrumentation_superagent import SuperagentInstrumentor
3from safety_agent import create_client
4
5respan = Respan(instrumentations=[SuperagentInstrumentor()])
6client = create_client()
7
8@task(name="guard_user_input")
9async def guard_user_input(message: str) -> str:
10 result = await client.guard(input=message)
11 return result.classification
12
13@workflow(name="chat_safety_pipeline")
14async def chat_safety_pipeline(message: str) -> str:
15 return await guard_user_input(message)

Architecture

Superagent safety-agent SDK
├─ SafetyClient.guard() ──→ SuperagentInstrumentor wrapper ──→ build_readable_span() ──→ inject_span()
│ │
├─ SafetyClient.redact() ──→ SuperagentInstrumentor wrapper ──→ build_readable_span() ──→ inject_span()
│ │
├─ SafetyClient.scan() ──→ SuperagentInstrumentor wrapper ──→ build_readable_span() ──→ inject_span()
│ │
└─ ... ──→ ... ──→ ... ──→ ...
OTEL Processor Chain
RespanSpanExporter
POST /v2/traces

Internal modules

These are implementation details, not part of the public API:

ModuleDescription
_instrumentation.pySuperagentInstrumentor, method patching, and restore logic.
_span_emitter.pyCanonical Respan span attribute mapping and span injection.
_serialization.pyJSON-safe method input/output serialization helpers.
_constants.pySuperagent-specific method names and metadata keys.