create_agent In "astream" with stream_mode="messages" does not output tokens incrementally. #1060

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

Originally created by @nswsnb on GitHub (Nov 14, 2025).

Checked other resources

  • This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/).
  • 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

import asyncio

from langchain.agents import create_agent
from langchain_openai import ChatOpenAI


modelOpenAI = ChatOpenAI(
        model="***",
        base_url="***",
        api_key="***", 
    )

agent = create_agent(
    model=modelOpenAI,
    system_prompt="You are a helpful assistant",

)

async def main():
    async for token, metadata in agent.astream(
            {"messages": [{"role": "user", "content": "hello who are you?"}]},
            stream_mode="messages",
            stream_subgraphs=True
    ):
        print(token.content)


if __name__ == '__main__':
    asyncio.run(main())

Error Message and Stack Trace (if applicable)

Output:
Hello! I’m your AI assistant, here to help answer your questions, provide information, or assist with tasks. You can think of me as a friendly digital helper. How can I assist you today? 😊

Description

I'm trying to use create_agent in astream with stream_mode="messages", but the output is not generated token by token.

System Info

version:

Image
Originally created by @nswsnb on GitHub (Nov 14, 2025). ### Checked other resources - [x] This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/). - [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 import asyncio from langchain.agents import create_agent from langchain_openai import ChatOpenAI modelOpenAI = ChatOpenAI( model="***", base_url="***", api_key="***", ) agent = create_agent( model=modelOpenAI, system_prompt="You are a helpful assistant", ) async def main(): async for token, metadata in agent.astream( {"messages": [{"role": "user", "content": "hello who are you?"}]}, stream_mode="messages", stream_subgraphs=True ): print(token.content) if __name__ == '__main__': asyncio.run(main()) ``` ### Error Message and Stack Trace (if applicable) ```shell Output: Hello! I’m your AI assistant, here to help answer your questions, provide information, or assist with tasks. You can think of me as a friendly digital helper. How can I assist you today? 😊 ``` ### Description I'm trying to use create_agent in astream with stream_mode="messages", but the output is not generated token by token. ### System Info version: <img width="642" height="680" alt="Image" src="https://github.com/user-attachments/assets/a9fe9581-8ffa-4249-aa3d-5992de559add" />
yindo added the bugpending labels 2026-02-20 17:42:55 -05:00
yindo closed this issue 2026-02-20 17:42:55 -05:00
Author
Owner

@yashsonawane15 commented on GitHub (Nov 15, 2025):

I think this should be in the langchain repository instead of langgraph.

@yashsonawane15 commented on GitHub (Nov 15, 2025): I think this should be in the langchain repository instead of langgraph.
Author
Owner

@le-codeur-rapide commented on GitHub (Nov 16, 2025):

Hello @nswsnb I ran your code and it worked as expected:
I just replaced print(token.content) by print(token.content + "|", end="") and got output:

|Hello|!| I'm| an| AI| language| model| here| to| assist| you|.| How| can| I| help| today|?||||

I am using same version of langgraph and langchain as you 1.0.3 and 1.0.7

What model are you using ?

@le-codeur-rapide commented on GitHub (Nov 16, 2025): Hello @nswsnb I ran your code and it worked as expected: I just replaced `print(token.content)` by `print(token.content + "|", end="")` and got output: ``` |Hello|!| I'm| an| AI| language| model| here| to| assist| you|.| How| can| I| help| today|?|||| ``` I am using same version of langgraph and langchain as you 1.0.3 and 1.0.7 What model are you using ?
Author
Owner

@casparb commented on GitHub (Nov 24, 2025):

Hi @nswsnb, I am closing as I cannot reproduce. Your code is functioning as expected. If you're still having issues please be more descriptive about what's going wrong.

@casparb commented on GitHub (Nov 24, 2025): Hi @nswsnb, I am closing as I cannot reproduce. Your code is functioning as expected. If you're still having issues please be more descriptive about what's going wrong.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#1060