awslabs / awslabs/agentcore-samples

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

Open
#1,796 0 comments 0 reactions 1 assignee Claimed by @akshseh View on GitHub
06-workshops bug
Dominant language
Python
Stars
3.4k
Forks
1.3k
Avg merge
1d 22h
Merged PRs (30d)
30

Description

**In which component is this bug present?**

- [ ] 01-AgentCore-runtime
- [ ] 02-AgentCore-gateway
- [ ] 03-AgentCore-identity
- [ ] 04-AgentCore-memory
- [x] 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 cause** — `requirements.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
```
2. Make the output print shape-robust in cells 7.1 and 7.2:
```python
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**
- Prerequisites still list "Claude 3.7 Sonnet", but the notebook uses `global.anthropic.claude-haiku-4-5` (and Sonnet 3.7 is no longer available in Bedrock — see #1733).
- #804 (LangGraph tutorial uses deprecated `create_react_agent`) is the same class of LangChain API-drift issue in a different notebook.

**Screenshots** — n/a.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.