langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
94.77k stars 15.34k forks source link

create_react_agent stream stopped on the very first AIMessage and doesn't provide the full answer #25885

Open ahammi opened 2 months ago

ahammi commented 2 months ago

Checked other resources

Example Code

I have followed the instructions to create a react agent that can query sqlite database:

agent_executor = create_react_agent(chat_model, tools, messages_modifier=system_message)

for s in agent_executor.stream(
    {"messages": [HumanMessage(content="Which country's customers spent the most?")]}
):
    print(s)
    print("----")

Error Message and Stack Trace (if applicable)

No response

Description

the stream stopped on the very first AIMessage. This is what I got after running this code: {'agent': {'messages': [AIMessage(content="To determine which country's customers spent the most, we need to look at the relevant tables in the database. First, let's list all the tables to understand the structure of the database.", additional_kwargs={'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 36, 'prompt_tokens': 549, 'total_tokens': 585}, 'model_name': 'gpt-4o', 'system_fingerprint': 'fp_f5a70d8dc9', 'finish_reason': 'stop', 'logprobs': None}, id='run-fa55841d-026a-4bd9-9060-24740c0ec6ad-0', usage_metadata={'input_tokens': 549, 'output_tokens': 36, 'total_tokens': 585})]}}

System Info

System Information

OS: Windows OS Version: 10.0.19045 Python Version: 3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022, 16:36:42) [MSC v.1929 64 bit (AMD64)]

Package Information

langchain_core: 0.2.35 langchain: 0.2.15 langchain_community: 0.2.13 langsmith: 0.1.85 langchain_chroma: 0.1.3 langchain_experimental: 0.0.62 langchain_openai: 0.1.23 langchain_text_splitters: 0.2.2 langgraph: 0.2.14

Optional packages not installed

Mustafa0503 commented 1 month ago

Hello! We're a group of students from the University of Toronto Scarborough, and we're looking to contribute to LangChain. We'd love the opportunity to investigate this bug further.