Skip to content

[BUG] Tools operating in different context and breaking AgentCore 3LO #946

@patrickbradshawdallas

Description

@patrickbradshawdallas

Checks

  • I have updated to the lastest minor and patch version of Strands
  • I have checked the documentation and this is not expected behavior
  • I have searched ./issues and there are no duplicates of my issue

Strands Version

1.10.0

Python Version

3.12

Operating System

ghcr.io/astral-sh/uv:python3.12-bookworm-slim

Installation Method

pip

Steps to Reproduce

  1. Code attached for execution in Amazon Bedrock AgentCore Runtime
  2. Create a Cognito User Pool and client (note the client ID and user pool ID)
  3. Create a Google credential provider in Amazon Bedrock AgentCore
  4. Unzip and replace information in the troubleshooting jupyter notebook (Cognito client ID, User pool ID, user name, and user password)
  5. Run through all cells to create, deploy, and execute agent.
  6. Observe that the agent responds that it was unable to retrieve credentials for Google and that CloudWatch logs show an error retrieving the workload access token and that the access token from BedrockAgentCoreContext.get_workload_access_token() returns a valid access token outside of the Strands agent but None within the tool execution. (This is retrieving a request-scoped ContextVar where the context has shifted when invoking the Strands agent and thus breaking 3LO flows.)

There may be a simpler way to showcase this - I have not yet tried creating a ContextVar directly outside of the agent and then referencing this within a tool execution, instead using the Bedrock AgentCore constructs per my use case. (Note also that there is a global variable workaround that is commented out in this file.)

strands-troubleshooting.zip

Expected Behavior

I expect that the workload access token is the same within AgentTask and GetCalendarEventsToday. Essentially that the agent executes in the same context (ContextVar) as the overall request rather than creating a net new context.

Actual Behavior

Actual behavior is that the AgentTask has a correct workload access token (from ContextVar) and the GetCalendarEventsToday returns None.

Additional Context

No response

Possible Solution

No response

Related Issues

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions