Skip to content

06-workshops - [Bug] Code Interpreter advanced-data-analysis lab: unpinned langchain breaks on LangChain 1.0 (AgentExecutor ImportError + output TypeError) #1796

Description

@stechr

In which component is this bug present?

  • 01-AgentCore-runtime
  • 02-AgentCore-gateway
  • 03-AgentCore-identity
  • 04-AgentCore-memory
  • 05-AgentCore-tools
  • 06-AgentCore-observability
  • 07-AgentCore-E2E

Bug Description

Notebook: 06-workshops/05-AgentCore-tools/01-Agent-Core-code-interpreter/03-advanced-data-analysis-with-agent-using-code-interpreter/langchain-agent-advanced-data-analysis-code-interpreter.ipynb (and its requirements.txt).

Running the notebook top-to-bottom, the import cell fails:

ImportError: cannot import name 'AgentExecutor' from 'langchain.agents'

Root causerequirements.txt lists langchain and langchain-aws with no version bound, and the first cell runs !pip install --upgrade -r requirements.txt. That installs LangChain >= 1.0, which removed the legacy AgentExecutor, create_tool_calling_agent, and tool from langchain.agents. The notebook imports all three from langchain.agents and builds the agent with create_tool_calling_agent + AgentExecutor.

Second failure (surfaces after the import is fixed) — with langchain pinned to the 0.3 line, output cells 7.1 (EDA) and 7.2 then fail:

TypeError: string indices must be integers, not 'str'

at print(response["output"][0]["text"]). On the pinned stack AgentExecutor's response["output"] is a plain string, not a content-block list, so the hardcoded [0]["text"] is invalid. The output shape varies by langchain / langchain-aws version.

Workaround / suggested fix

  1. Pin the deps in requirements.txt:
langchain-aws<0.3
langchain>=0.3,<1.0
  1. Make the output print shape-robust in cells 7.1 and 7.2:
print(response["output"] if isinstance(response["output"], str) else response["output"][0]["text"])

(Alternatively, migrate the notebook to the LangChain 1.0 agent API — LangGraph create_agent — and update the output handling accordingly.)

Environment — Amazon SageMaker Studio JupyterLab, Python 3.12; reproduces on a fresh clone, running the notebook as-is.

Related

Screenshots — n/a.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions