Skip to content
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

fix dropped tokens in ReActAgentWorker._arun_step_stream #14308

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions llama-index-core/llama_index/core/agent/react/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ def _run_step_stream(

# iterate over stream, break out if is final answer after the "Answer: "
full_response = ChatResponse(
message=ChatMessage(content=None, role="assistant")
message=ChatMessage(content=None, role=MessageRole.ASSISTANT)
)
is_done = False
for latest_chunk in chat_stream:
Expand Down Expand Up @@ -689,13 +689,14 @@ async def _arun_step_stream(

# iterate over stream, break out if is final answer after the "Answer: "
full_response = ChatResponse(
message=ChatMessage(content=None, role="assistant")
message=ChatMessage(content=None, role=MessageRole.ASSISTANT)
)
is_done = False
async for latest_chunk in chat_stream:
full_response = latest_chunk
is_done = self._infer_stream_chunk_is_final(latest_chunk)
if is_done:
full_response.delta = full_response.message.content
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm kind of confused what's happening here

The delta should only have the newest tokens from the stream, not the entire response?

I haven't noticed issues with the react agent dropping tokens, can you give some example that shows the issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tl;dr there was a bit of nuance I missed in debugging the issue. Responded here with more detail/context
#14307 (comment)

break

if not is_done:
Expand All @@ -719,7 +720,7 @@ async def _arun_step_stream(
else:
# Get the response in a separate thread so we can yield the response
response_stream = self._async_add_back_chunk_to_stream(
chunk=latest_chunk, chat_stream=chat_stream
chunk=full_response, chat_stream=chat_stream
)

agent_response = StreamingAgentChatResponse(
Expand Down
Loading