sdk-python
sdk-python copied to clipboard
[BUG] ERROR | opentelemetry.context | Failed to detach context
Checks
- [x] I have updated to the lastest minor and patch version of Strands
- [x] I have checked the documentation and this is not expected behavior
- [x] I have searched ./issues and there are no duplicates of my issue
Strands Version
1.19.0
Python Version
3.11.9
Operating System
macOS 15.7.2
Installation Method
pip
Steps to Reproduce
I ran the swarm example:
import os
import logging
from strands import Agent
from strands.multiagent import Swarm
from strands.models import BedrockModel
# Enable debug logs and print them to stderr
logging.getLogger("strands.multiagent").setLevel(logging.DEBUG)
logging.basicConfig(
format="%(levelname)s | %(name)s | %(message)s",
handlers=[logging.StreamHandler()]
)
os.environ["AWS_PROFILE"] = "strands-profile"
bedrock_model = BedrockModel(
model_id="us.anthropic.claude-sonnet-4-20250514-v1:0"
)
# Create specialized agents
researcher = Agent(model=bedrock_model, name="researcher", system_prompt="You are a research specialist...")
coder = Agent(model=bedrock_model, name="coder", system_prompt="You are a coding specialist...")
reviewer = Agent(model=bedrock_model, name="reviewer", system_prompt="You are a code review specialist...")
architect = Agent(model=bedrock_model, name="architect", system_prompt="You are a system architecture specialist...")
# Create a swarm with these agents, starting with the researcher
swarm = Swarm(
[coder, researcher, reviewer, architect],
entry_point=researcher, # Start with the researcher
max_handoffs=20,
max_iterations=20,
execution_timeout=900.0, # 15 minutes
node_timeout=300.0, # 5 minutes per agent
repetitive_handoff_detection_window=8, # There must be >= 3 unique agents in the last 8 handoffs
repetitive_handoff_min_unique_agents=3
)
# Execute the swarm on a task
result = swarm("Design and implement a simple REST API for a todo app")
# Access the final result
print(f"Status: {result.status}")
print(f"Node history: {[node.node_id for node in result.node_history]}")
Expected Behavior
Example runs without errors.
Actual Behavior
The example runs but the logs have multiple errors like:
**ERROR | opentelemetry.context | Failed to detach context
Traceback (most recent call last):
File "/Users/mratul/.pyenv/versions/strands/lib/python3.11/site-packages/opentelemetry/context/__init__.py", line 155, in detach
_RUNTIME_CONTEXT.detach(token)
File "/Users/mratul/.pyenv/versions/strands/lib/python3.11/site-packages/opentelemetry/context/contextvars_context.py", line 53, in detach
self._current_context.reset(token)
ValueError: <Token var=<ContextVar name='current_context' default={} at 0x102b9f1f0> at 0x107827dc0> was created in a different Context
Additional Context
No response
Possible Solution
No response
Related Issues
No response