-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: ReActAgent.astream_chat() throws AssertionError after updating to the lastest version #15883
Comments
Hey @dzmitrysyrtsou! 👋 I'm here to help you with any bugs, questions, or contributions you have. Let's squash those bugs together! The To resolve this issue, ensure that the @pytest.mark.asyncio()
async def test_astream_chat_basic(
add_tool: FunctionTool,
) -> None:
mock_llm = MockStreamChatLLM(
responses=[
ChatMessage(
content=MOCK_ACTION_RESPONSE,
role=MessageRole.ASSISTANT,
),
ChatMessage(
content=MOCK_STREAM_FINAL_RESPONSE,
role=MessageRole.ASSISTANT,
),
]
)
agent = ReActAgent.from_tools(
tools=[add_tool],
llm=mock_llm,
)
response = await agent.astream_chat("What is 1 + 1?")
assert isinstance(response, StreamingAgentChatResponse)
# exhaust stream
async for delta in response.async_response_gen():
continue
expected_answer = MOCK_STREAM_FINAL_RESPONSE.split("Answer: ")[-1].strip()
assert response.response == expected_answer
assert agent.chat_history == [
ChatMessage(
content="What is 1 + 1?",
role=MessageRole.USER,
),
ChatMessage(
content="2 is the final answer.",
role=MessageRole.ASSISTANT,
),
] Ensure that your implementation aligns with this test case to avoid the |
Hey, I'm pretty sure we're using the Agent correctly. Here is a chunk of our code:
We are deeply convinced that the problem is not with the way the agent is used, but rather with the implementation of astream_chat() method. |
The issue you're encountering is likely due to the recent changes in the Here is the exact implementation of the @trace_method("chat")
async def astream_chat(
self,
message: str,
chat_history: Optional[List[ChatMessage]] = None,
tool_choice: Union[str, dict] = "auto",
) -> StreamingAgentChatResponse:
with self.callback_manager.event(
CBEventType.AGENT_STEP,
payload={EventPayload.MESSAGES: [message]},
) as e:
chat_response = await self._achat(
message, chat_history, tool_choice, mode=ChatResponseMode.STREAM
)
assert isinstance(chat_response, StreamingAgentChatResponse)
e.on_end(payload={EventPayload.RESPONSE: chat_response})
return chat_response The Ensure that the If you need further assistance, please provide more details about the |
We're not using a custom implementation of _achat() method. We're using a built-in implementation from Llama. |
Its definitely a bug lol |
Bug Description
After updating to the latest version, ReActAgent.astream_chat() throws AssertionError: assert isinstance(chat_response, StreamingAgentChatResponse).
This seems to be related to a new assertion added to llama-index-core/llama_index/core/agent/runner/base.py, namely:
Isn't the logic now conflicting?
Looks like a bug....
Version
latest
Steps to Reproduce
Create a ReActAgent and call astream_chat() method.
Relevant Logs/Tracbacks
No response
The text was updated successfully, but these errors were encountered: