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

Fixed and chain stream #39029

Open
wants to merge 9 commits into
base: feature/azure-ai-projects-beta5
Choose a base branch
from

Conversation

howieleung
Copy link
Member

@howieleung howieleung commented Jan 3, 2025

  1. Fixed event streaming so that it can encounter multiple event from a buffer or multiple of buffer to form a complete event.
  2. Fixed Issue with event handler making function tool calls. #39028. When we call create_stream, an event handler is associated to the response iterator. Usually people write code like this:
    with project_client.agents.create_stream(
        thread_id=thread.id, assistant_id=agent.id, event_handler=MyEventHandler(functions)
    ) as stream:
        for event_type, event_data, func_return in stream:
            print(f"Event Data: {str(event_data)")

Then when function tool calls are executed by the event handler, the response iterator of tool call stream is associated to the same event handler followed by calling until_done(). The call of until_done() pulls all events until no more response from the stream. As a result, the for loop above don't receive the events.

To fix the issue, I don't do until_done() after making tool call, so the for loop above will receive events from tool calls.

  1. Make submit_tool_outputs_to_stream function to return None instead of AgentRunStream because developers are not expected to iterate events from submit_tool_outputs_to_stream by context manager.

  2. Before the fix, when you make create_stream calls, the event handler received response_iterator and create_buffers from response_iterator. When the event handler makes tool calls, it will overwrite the response_iterator from the toolcall stream and reset the buffer. This might cause buffer and event lost. With the fix, when event handler make toolcalls, we chain the response_iterator of the toolcall stream to the original stream and retain buffer.

  3. Introduce unit and integrated test. Unit test focus on logic in parsing response. Integrated test focus on handing response toolcall and call submit tool call and able handing response again from tool call streaming.

@jhakulin
Copy link
Member

jhakulin commented Jan 3, 2025

We need to add extensive tests because lots of changes

Copy link
Member

@jhakulin jhakulin left a comment

Choose a reason for hiding this comment

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

Need to integrate with CI tests

@azure-sdk
Copy link
Collaborator

API change check

APIView has identified API level changes in this PR and created following API reviews.

azure-ai-projects

@howieleung howieleung force-pushed the howie/fix-and-chain-stream branch from 5154fa3 to 08d9c82 Compare January 7, 2025 05:21
@howieleung howieleung force-pushed the howie/fix-and-chain-stream branch from 1fdf60e to 121f588 Compare January 7, 2025 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants