Skip to main content

Respan instrumentation plugin for Strands Agents

Project description

respan-instrumentation-strands-agents

Respan instrumentation plugin for Strands Agents.

This package consumes Strands Agents' native OpenTelemetry spans and maps them directly into the Respan span contract used by the OTLP pipeline. It does not require OpenInference at runtime.

Install

pip install respan-instrumentation-strands-agents

Quickstart

import os

from respan import Respan
from respan_instrumentation_strands_agents import StrandsAgentsInstrumentor
from strands import Agent, tool
from strands.models.openai import OpenAIModel

respan_api_key = os.environ["RESPAN_API_KEY"]
respan_base_url = os.getenv("RESPAN_BASE_URL", "https://api.respan.ai/api")

respan = Respan(
    api_key=respan_api_key,
    base_url=respan_base_url,
    instrumentations=[StrandsAgentsInstrumentor()],
)

model = OpenAIModel(
    model_id="gpt-4o-mini",
    client_args={"api_key": respan_api_key, "base_url": respan_base_url},
)


@tool
def get_weather(city: str) -> str:
    """Get the current weather for a city."""
    return f"The weather in {city} is sunny and 72F."


agent = Agent(
    name="WeatherAgent",
    model=model,
    tools=[get_weather],
    system_prompt="You are a concise weather assistant.",
)

result = agent("What is the weather in Seattle?")
print(result)

respan.flush()

Notes

  • Initialize Respan(...) before running the agent so Strands uses the active Respan OpenTelemetry provider.
  • The instrumentor can refresh an already-created Strands tracer singleton when possible, which helps when an agent was constructed before activation.
  • Tool definitions are enabled by default via Strands' gen_ai_tool_definitions semantic-convention opt-in and are exported as canonical llm.request.functions attributes.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file respan_instrumentation_strands_agents-0.1.0.tar.gz.

File metadata

File hashes

Hashes for respan_instrumentation_strands_agents-0.1.0.tar.gz
Algorithm Hash digest
SHA256 63ec426714846d13b4b12adf276e30687d3520c8d17d0252dea5b2ea096562aa
MD5 b2b0d73b3262ab6205711575849ee62f
BLAKE2b-256 890986edd1e335eeb31dcfc7b9792e4e30964a3ba0cb7f6bc213a29fc2482347

See more details on using hashes here.

File details

Details for the file respan_instrumentation_strands_agents-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for respan_instrumentation_strands_agents-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3ca36a9e81a9e059c79cef6b75fc5ea2de8b926f26a052518ee186a4e1e596e2
MD5 22c571a6194cebdd8adea93df830d71b
BLAKE2b-256 e311dfa9f682dd5bc9fc63ffaaa6a309d7d11709be1f745918c4239c74e26b78

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page