Typo in the read_document tool/function in the Hierarchical Agent Teams notebook? #450

Closed
opened 2026-02-20 17:40:12 -05:00 by yindo · 3 comments
Owner

Originally created by @milenakapralova on GitHub (Feb 11, 2025).

Checked other resources

  • This is a bug, not a usage question. For questions, please use GitHub Discussions.
  • I added a clear and detailed title that summarizes the issue.
  • I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example).
  • I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue.

Example Code

def provide_a_start_line(
    start: Annotated[Optional[int], "The start line. Default is 0"] = None
) -> str:
    """Return the start line."""
    if start is not None:
        start = 0
    return start

print(provide_a_start_line), provide_a_start_line(1), provide_a_start_line(2)

Error Message and Stack Trace (if applicable)


Description

I am using the read_document() function in the Hierarchical Agent Teams notebook and the function:

  • keeps the input None start line as None, and
  • overwrites the non-None input start line with 0.
    Therefore, lines[start:end] is lines[0:end] irrespective of the start provided as argument to the function.

The function in question:

def read_document(
    file_name: Annotated[str, "File path to read the document from."],
    start: Annotated[Optional[int], "The start line. Default is 0"] = None,
    end: Annotated[Optional[int], "The end line. Default is None"] = None,
) -> str:
    """Read the specified document."""
    with (WORKING_DIRECTORY / file_name).open("r") as file:
        lines = file.readlines()
    if start is not None:
        start = 0
    return "\n".join(lines[start:end])

So, the function can keep the if-statement s.t. it is of the form if start is None: or can remove the if-statement altogether since lines[None:end] is equivalent to lines[0:end] in Python slicing.

System Info

Replication requires only python's typing module: from typing import Optional

python -m langchain_core.sys_info gives:

System Information

OS: Darwin
OS Version: Darwin Kernel Version 24.3.0: Thu Jan 2 20:24:06 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T8103
Python Version: 3.11.4 (main, Jul 5 2023, 09:00:44) [Clang 14.0.6 ]

Package Information

langchain_core: 0.3.34
langchain: 0.3.18
langchain_community: 0.3.17
langsmith: 0.1.147
langchain_anthropic: 0.3.7
langchain_experimental: 0.3.4
langchain_openai: 0.2.11
langchain_text_splitters: 0.3.6
langgraph_cli: 0.1.61
langgraph_sdk: 0.1.43

Optional packages not installed

langserve

Other Dependencies

aiohttp<4.0.0,>=3.8.3: Installed. No version info available.
anthropic<1,>=0.45.0: Installed. No version info available.
async-timeout<5.0.0,>=4.0.0;: Installed. No version info available.
click: 8.1.7
dataclasses-json<0.7,>=0.5.7: Installed. No version info available.
httpx: 0.28.0
httpx-sse<1.0.0,>=0.4.0: Installed. No version info available.
jsonpatch<2.0,>=1.33: Installed. No version info available.
langchain-anthropic;: Installed. No version info available.
langchain-aws;: Installed. No version info available.
langchain-cohere;: Installed. No version info available.
langchain-community;: Installed. No version info available.
langchain-core<1.0.0,>=0.3.34: Installed. No version info available.
langchain-deepseek;: Installed. No version info available.
langchain-fireworks;: Installed. No version info available.
langchain-google-genai;: Installed. No version info available.
langchain-google-vertexai;: Installed. No version info available.
langchain-groq;: Installed. No version info available.
langchain-huggingface;: Installed. No version info available.
langchain-mistralai;: Installed. No version info available.
langchain-ollama;: Installed. No version info available.
langchain-openai;: Installed. No version info available.
langchain-text-splitters<1.0.0,>=0.3.6: Installed. No version info available.
langchain-together;: Installed. No version info available.
langchain<1.0.0,>=0.3.18: Installed. No version info available.
langgraph-api: Installed. No version info available.
langsmith-pyo3: Installed. No version info available.
langsmith<0.4,>=0.1.125: Installed. No version info available.
langsmith<0.4,>=0.1.17: Installed. No version info available.
numpy<2,>=1.26.4;: Installed. No version info available.
numpy<3,>=1.26.2;: Installed. No version info available.
openai: 1.56.2
orjson: 3.10.12
packaging<25,>=23.2: Installed. No version info available.
pydantic: 2.10.3
pydantic-settings<3.0.0,>=2.4.0: Installed. No version info available.
pydantic<3.0.0,>=2.5.2;: Installed. No version info available.
pydantic<3.0.0,>=2.7.4: Installed. No version info available.
pydantic<3.0.0,>=2.7.4;: Installed. No version info available.
python-dotenv: 1.0.1
PyYAML>=5.3: Installed. No version info available.
requests: 2.32.3
requests-toolbelt: 1.0.0
requests<3,>=2: Installed. No version info available.
SQLAlchemy<3,>=1.4: Installed. No version info available.
tenacity!=8.4.0,<10,>=8.1.0: Installed. No version info available.
tenacity!=8.4.0,<10.0.0,>=8.1.0: Installed. No version info available.
tiktoken: 0.8.0
typing-extensions>=4.7: Installed. No version info available.

Originally created by @milenakapralova on GitHub (Feb 11, 2025). ### Checked other resources - [x] This is a bug, not a usage question. For questions, please use GitHub Discussions. - [x] I added a clear and detailed title that summarizes the issue. - [x] I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example). - [x] I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue. ### Example Code ```python def provide_a_start_line( start: Annotated[Optional[int], "The start line. Default is 0"] = None ) -> str: """Return the start line.""" if start is not None: start = 0 return start print(provide_a_start_line), provide_a_start_line(1), provide_a_start_line(2) ``` ### Error Message and Stack Trace (if applicable) ```shell ``` ### Description I am using the `read_document()` function in the [Hierarchical Agent Teams](https://github.com/langchain-ai/langgraph/blob/main/docs/docs/tutorials/multi_agent/hierarchical_agent_teams.ipynb) notebook and the function: * keeps the input None start line as None, and * overwrites the non-None input start line with 0. Therefore, lines[start:end] is lines[0:end] irrespective of the start provided as argument to the function. The function in question: ``` def read_document( file_name: Annotated[str, "File path to read the document from."], start: Annotated[Optional[int], "The start line. Default is 0"] = None, end: Annotated[Optional[int], "The end line. Default is None"] = None, ) -> str: """Read the specified document.""" with (WORKING_DIRECTORY / file_name).open("r") as file: lines = file.readlines() if start is not None: start = 0 return "\n".join(lines[start:end]) ``` So, the function can keep the if-statement s.t. it is of the form `if start is None:` or can remove the if-statement altogether since lines[None:end] is equivalent to lines[0:end] in Python slicing. ### System Info Replication requires only python's typing module: `from typing import Optional` `python -m langchain_core.sys_info` gives: System Information ------------------ > OS: Darwin > OS Version: Darwin Kernel Version 24.3.0: Thu Jan 2 20:24:06 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T8103 > Python Version: 3.11.4 (main, Jul 5 2023, 09:00:44) [Clang 14.0.6 ] Package Information ------------------- > langchain_core: 0.3.34 > langchain: 0.3.18 > langchain_community: 0.3.17 > langsmith: 0.1.147 > langchain_anthropic: 0.3.7 > langchain_experimental: 0.3.4 > langchain_openai: 0.2.11 > langchain_text_splitters: 0.3.6 > langgraph_cli: 0.1.61 > langgraph_sdk: 0.1.43 Optional packages not installed ------------------------------- > langserve Other Dependencies ------------------ > aiohttp<4.0.0,>=3.8.3: Installed. No version info available. > anthropic<1,>=0.45.0: Installed. No version info available. > async-timeout<5.0.0,>=4.0.0;: Installed. No version info available. > click: 8.1.7 > dataclasses-json<0.7,>=0.5.7: Installed. No version info available. > httpx: 0.28.0 > httpx-sse<1.0.0,>=0.4.0: Installed. No version info available. > jsonpatch<2.0,>=1.33: Installed. No version info available. > langchain-anthropic;: Installed. No version info available. > langchain-aws;: Installed. No version info available. > langchain-cohere;: Installed. No version info available. > langchain-community;: Installed. No version info available. > langchain-core<1.0.0,>=0.3.34: Installed. No version info available. > langchain-deepseek;: Installed. No version info available. > langchain-fireworks;: Installed. No version info available. > langchain-google-genai;: Installed. No version info available. > langchain-google-vertexai;: Installed. No version info available. > langchain-groq;: Installed. No version info available. > langchain-huggingface;: Installed. No version info available. > langchain-mistralai;: Installed. No version info available. > langchain-ollama;: Installed. No version info available. > langchain-openai;: Installed. No version info available. > langchain-text-splitters<1.0.0,>=0.3.6: Installed. No version info available. > langchain-together;: Installed. No version info available. > langchain<1.0.0,>=0.3.18: Installed. No version info available. > langgraph-api: Installed. No version info available. > langsmith-pyo3: Installed. No version info available. > langsmith<0.4,>=0.1.125: Installed. No version info available. > langsmith<0.4,>=0.1.17: Installed. No version info available. > numpy<2,>=1.26.4;: Installed. No version info available. > numpy<3,>=1.26.2;: Installed. No version info available. > openai: 1.56.2 > orjson: 3.10.12 > packaging<25,>=23.2: Installed. No version info available. > pydantic: 2.10.3 > pydantic-settings<3.0.0,>=2.4.0: Installed. No version info available. > pydantic<3.0.0,>=2.5.2;: Installed. No version info available. > pydantic<3.0.0,>=2.7.4: Installed. No version info available. > pydantic<3.0.0,>=2.7.4;: Installed. No version info available. > python-dotenv: 1.0.1 > PyYAML>=5.3: Installed. No version info available. > requests: 2.32.3 > requests-toolbelt: 1.0.0 > requests<3,>=2: Installed. No version info available. > SQLAlchemy<3,>=1.4: Installed. No version info available. > tenacity!=8.4.0,<10,>=8.1.0: Installed. No version info available. > tenacity!=8.4.0,<10.0.0,>=8.1.0: Installed. No version info available. > tiktoken: 0.8.0 > typing-extensions>=4.7: Installed. No version info available.
yindo closed this issue 2026-02-20 17:40:12 -05:00
Author
Owner

@gbaian10 commented on GitHub (Feb 11, 2025):

It seems like start has no effect in this tool because whether it's None or any int, its effect is equivalent to 0. Right?

@gbaian10 commented on GitHub (Feb 11, 2025): It seems like `start` has no effect in this tool because whether it's `None` or any `int`, its effect is equivalent to 0. Right?
Author
Owner

@vbarda commented on GitHub (Feb 11, 2025):

it should be if start is None, thanks for reporting. will keep the if statement for readability

@vbarda commented on GitHub (Feb 11, 2025): it should be `if start is None`, thanks for reporting. will keep the if statement for readability
Author
Owner

@milenakapralova commented on GitHub (Feb 11, 2025):

Cool. Then for readability maybe also add if end is None: end = len(lines) although that possibly adds overhead.

@milenakapralova commented on GitHub (Feb 11, 2025): Cool. Then for readability maybe also add `if end is None: end = len(lines)` although that possibly adds overhead.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#450