Facet
All docs

AWS Strands Agents — Integration Guide

Step-by-step developer guide for instrumenting an AWS Strands Agents application.

AWS Strands Agents Integration Guide (Developer)

This is the complete, step-by-step guide for a developer instrumenting a real AWS Strands Agents application with ADG. It reflects the adapter as actually validated against real, officially-maintained AWS tool implementations (strands-agents-tools) — not just this project's own hand-built demos — see "Real-world validation" below for what that means in practice and why it matters to you.

For the conceptual question "which of my own objects/calls should become a Trace vs. an Activity vs. an Artifact vs. a Resource?" — see the Ontology Mapping Decision Guide first. This guide assumes you already know the answer and shows the Strands-Agents-specific mechanics of acting on it.


1. The one-line integration

Strands Agents' own observability is unconditionally OpenTelemetry — every strands.Agent call emits OTel GenAI semantic-convention spans with no opt-in flag required to turn tracing on at all (unlike Pydantic AI, where Agent.instrument_all() must be called first). This adapter attaches an OTel SpanProcessor to observe exactly that — no wrapping of your Agent calls, no subclassing, no changes to your agent's own tools:

from adg.adapters.strands_agents import instrument_tracing

instrument_tracing()

agent = Agent(model=my_model, tools=[my_tool])
result = agent("What is 17 times 24?")

Call instrument_tracing() before constructing your first Agent(...). Strands lazily creates one process-wide tracer singleton on first use (strands.telemetry.get_tracer()); calling this function afterward still attaches the processor correctly, but the message-content-as-span-attributes opt-in described below (the one genuinely Strands-specific piece of this adapter) will not retroactively apply to a tracer already constructed.

instrument_tracing():

  1. Merges two required tokens into the OTEL_SEMCONV_STABILITY_OPT_IN environment variable (see "The one genuinely Strands-specific piece" below) — non-destructively, preserving any tokens you've already set.
  2. Installs (or reuses, see "Composable path" below) a real opentelemetry.sdk.trace.TracerProvider.
  3. Attaches an ADGSpanProcessor to it, wired with ADG's default transport (console by default; your Facet platform contact can help configure REST/production transport).

Unlike Pydantic AI, there is no separate "turn on instrumentation" call — Strands' own tracing is unconditional, keyed only on whatever TracerProvider is globally active when its tracer singleton is first constructed.

Composable path (you already run OpenTelemetry)

from adg.adapters.strands_agents import instrument_tracing

instrument_tracing(tracer_provider=my_existing_provider)

This only adds ADGSpanProcessor to your existing provider — composing with, never replacing, whatever other processors/exporters you already have attached. ADGSpanProcessor observes whatever spans Strands emits regardless of who else is attached to the same provider.

Lower-level path (full manual control)

from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.trace import set_tracer_provider
from strands import Agent
from adg.adapters.strands_agents import ADGSpanProcessor, _ensure_semconv_opt_in

_ensure_semconv_opt_in()  # before the first Agent() is created
provider = TracerProvider()
provider.add_span_processor(ADGSpanProcessor())
set_tracer_provider(provider)

agent = Agent(model=my_model, tools=[my_tool])

Customizing what gets captured

All the same optional parameters every other ADG adapter supports are available on instrument_tracing(...):

from pathlib import Path
from adg.adapters.strands_agents import instrument_tracing
from adg.artifact_types import load_artifact_type_mapping

artifact_type_mapping = load_artifact_type_mapping(
    Path(__file__).parent / "artifact_types.toml"
)

instrument_tracing(artifact_type_mapper=artifact_type_mapping)

See the Artifact Type Mapping guide for the full artifact_types.toml format — this classifies your agent's own outcome Artifacts (e.g. "this tool's return value is a DECISION") without ADG ever guessing at your business semantics itself.

Zero-code mode: also available

Unlike Pydantic AI, this adapter does have a zero-code path: adg.zero_code.strands_agents_patch (registered in adg.zero_code._PATCHERS as "strands_agents") self-instruments the first strands.Agent constructed in the process — no instrument_tracing() call anywhere in customer code at all, driven entirely by environment variables (ADG_ZERO_CODE/ADG_ZERO_CODE_FRAMEWORKS/ADG_APPLICATION/ ADG_API_BASE_URL/ADG_ZERO_CODE_ARTIFACT_TYPE_MAPPING_FILE, ...). See our own internal test applications for a worked example and run strands-agents-support-triage-zero-code to see it in action.

One Strands-specific ordering requirement, confirmed directly against the real SDK (strands-agents==1.62.0), that the patch itself already handles for you but is worth understanding: Strands' own Agent.__init__ resolves its tracer eagerly, synchronously (self.tracer = get_tracer()), reading OTEL_SEMCONV_STABILITY_OPT_IN at that exact moment — unlike Pydantic AI, where Agent.instrument_all() only needs to run before the first run call, not before construction. The zero-code patch's own _adg_patched_init calls _ensure_instrumented() strictly before the original Agent.__init__ for exactly this reason; this only matters to you if you're writing manual instrumentation and calling instrument_tracing() yourself — always call it before constructing your first Agent, per §1 above.

Same caveats as every other zero-code patch (indiscriminate, process-global scope; no way to pass an existing TracerProvider from zero-code mode, since there's no call site) — see the adapter's own zero-code module docstring for the full discussion.


2. How Strands Agents' OTel spans map onto the ontology

This adapter is the second specialization (after Pydantic AI) of the framework-agnostic ingestion engine — adg.adapters.otel_genai — which dispatches on the published gen_ai.operation.name OTel attribute (an industry-standard fact, not a framework-specific guess). Unlike Pydantic AI, this adapter required no attribute-shape compatibility normalizer at all: every attribute name Strands emits already matches what adg.adapters.otel_genai expects, confirmed empirically against a real install (strands-agents==1.62.0) — the cleanest Tier 2 reuse case so far.

OTel span (gen_ai.operation.name / span name) Ontology entity Notes
The outermost invoke_agent <name> span Trace One per agent(...)/agent.invoke_async(...) call.
Every span Strands emits, nested or not Activity invoke_agent, chat (one per model request, including retries), execute_tool <name> (one per tool call) — nesting via OTel parent-child span relationships becomes Lineage CONTAINS.
chat (a model request) Artifact (the completion, if populated) + Resource ("llm"-typed, with usage metadata) One chat span per model round-trip — a Guide-triggered retry (§4) produces a second nested chat span in the same Trace, not a second Trace.
execute_tool <name> Artifact (the tool's return value, named after the tool) + Resource ("tool"-typed) Proven against two real, officially-maintained AWS tools during real-world validation (strands_tools.calculator, strands_tools.current_time — see §5).
An error recorded on any span during the run TraceFailed (instead of TraceCompleted) Via the adapter's existing, generic error handling (inherited unchanged from adg.adapters.otel_genai).

One confirmed timing quirk: Trace.customer_context is always None

Strands' own _start_span() creates the span, then calls span.set_attributes(...) (including gen_ai.agent.name) only afterward — too late for this platform's on_start hook, which fires synchronously during span creation. This means TraceStarted. customer_context is always None for this adapter (confirmed, not a bug). The shared adg.adapters.otel_genai.processor module's own TraceFinalStateCaptured fallback (reading the root span's gen_ai.output.messages when the Pydantic-AI-specific final_result attribute is absent, as it always is here) still surfaces the Trace's own final output by the time the Trace ends. If you need the agent's name available at Trace-start time specifically, use TraceFinalStateCaptured (fired at Trace end) rather than TraceStarted.


3. The one genuinely Strands-specific piece: a message-content opt-in

By default, Strands records model/agent input and output message content (not operation metadata) as OTel span events, not span attributes — a legitimate, spec-permitted alternative emission shape the GenAI semantic conventions explicitly allow, that this platform's shared extractor does not read (span events are deprecated in OTel's own tracing API recommendations, and no other confirmed emitter so far needs them).

Strands itself ships a documented env-var opt-in, OTEL_SEMCONV_STABILITY_OPT_IN, that moves this same content onto span attributes instead:

  • gen_ai_latest_experimental selects the modern span-naming/ attribute scheme.
  • gen_ai_span_attributes_only additionally promotes message content (gen_ai.input.messages/gen_ai.output.messages) from events onto the span itself.

instrument_tracing() sets both tokens automatically, merged non-destructively with any tokens you've already set (e.g. gen_ai_tool_definitions, your own gen_ai_unredacted_attributes=... redaction override) — see _ensure_semconv_opt_in() in the adapter if you need to call it yourself in the lower-level manual-control path.

Tool-call inputs/outputs (gen_ai.tool.call.arguments/ gen_ai.tool.call.result) are unaffected by either opt-in — under gen_ai_latest_experimental alone, Strands already records those directly as span attributes per the OTel GenAI execute_tool span convention, confirmed empirically.


4. Guardrails: Strands' own InterventionHandler mechanism

Strands Agents' first-class guardrail primitive is strands.interventions.InterventionHandler, with hooks at before_tool_call, before_invocation, before_model_call, after_tool_call, and after_model_call:

from strands.interventions import InterventionHandler, Deny, Guide, Proceed

class NoSpeculation(InterventionHandler):
    def after_model_call(self, event):
        text = _extract_text(event.stop_response.message)
        if "i think" in text.lower():
            return Guide("Speculative language is not allowed; cite a source.")
        return Proceed()

agent = Agent(model=my_model, tools=[search_docs], intervention_handler=NoSpeculation())

Two confirmed structural facts, directly via OTel span inspection (based on investigation against our own internal test applications):

  • Deny returned from before_tool_call means the execute_tool span is never created at all — confirmed via empirical smoke test (0 execute_tool spans when denied). Only a "DENIED: ..." message appears inside the next execute_event_loop_cycle span's gen_ai.input.messages — a span type this adapter's extractor does not recognize, so no Artifact is produced for a denial. If you want a visible Artifact per guardrail verdict, do your own check inside a plain tool instead (see §5 of this guide's "no visible Artifact" pattern, mirrored from the Pydantic AI developer guide).
  • Deny is a documented no-op on after_model_call — Strands itself logs "has no effect" for any action type other than Proceed/Guide/Transform at that hook (confirmed via strands/interventions/registry.py's _apply_after_model_call). Only Guide triggers a genuine retry there (discards the response, re-invokes the model) — confirmed via smoke test showing two nested chat spans for one invoke_agent turn, exactly mirroring Pydantic AI's ModelRetry behavior (see the Pydantic AI developer guide §4). Strands imposes no built-in retry cap at this hook — if you need one, track your own retry count inside your InterventionHandler (our own internal test applications include a worked example, _NoSpeculation, that accepts the still-speculative answer once its own budget is exhausted, since Deny can't be used to fail the trace from this hook).

If you want a visible Artifact per guardrail verdict instead, do your own check inside a plain @tool-decorated function (see our own internal test applications' check_no_pii for a worked, real-Presidio-backed example) — a tool call's return value is always captured as its own Artifact (§2's table).


5. Real-world validation: what this adapter was actually proven against

Beyond this project's own two hand-built internal test applications, the adapter was validated against real, officially-maintained AWS tool implementations:

strands-agents-tools (PyPI, the official companion tool library published by the strands-agents GitHub org itself, v0.8.10) — installs cleanly alongside strands-agents==1.62.0 with zero version conflicts. This was validated via a pip-install-based demo (not vendored, same posture as Pydantic AI's oterm validation).

Two real, non-trivial tools were driven through a real strands.Agent tool-calling turn:

  • strands_tools.calculator — a genuine sympy-backed symbolic math tool (arbitrary expression evaluation, equation solving, calculus, matrix operations).
  • strands_tools.current_time — a genuine timezone-aware clock tool.

Both ran through ADGSpanProcessor with a real, scripted model — confirming full, correct event emission (execute_tool calculator span, gen_ai.tool.call.result populated with the genuine computed result, e.g. "Result: 408" for 17 * 24) with zero adapter changes.

Result: zero changes to the adapter were needed — this is a different kind of validation than Pydantic AI's oterm validation (which validated a real application's agent-construction plumbing); this instead validates real, non-trivial, officially- maintained tool implementations flowing through the same unmodified extraction logic.


6. Where to go next

  • The Ontology Mapping Decision Guide — how to decide ontology boundaries for anything Strands Agents' own instrumentation doesn't already structure for you.
  • The Artifact Type Mapping guide — classifying your agent's own outcome Artifacts.
  • The Field Mapping guide — vocabulary normalization (mapping your own field names onto canonical projection fields).
  • Your Facet platform contact — production transport, monitoring, and scaling for Strands-Agents-sourced traces.
  • The Pydantic AI Integration Guide — the sibling adapter sharing the same adg.adapters.otel_genai core; useful for comparing the two confirmed OTel GenAI semconv emission shapes side by side.
  • The framework-agnostic OTel GenAI semantic-convention core this adapter specializes — the same core any future OTel-GenAI-semconv-emitting framework adapter (LiteLLM, CrewAI's own OTel path — this is on our roadmap) will reuse unmodified.