Skip to content

Safe TaskResult in BaseGroupChat #5109

@Leon0402

Description

@Leon0402

What feature would you like to be added?

I think run_stream in BaseGroupChat is a little bit awkward to use, because it streams both messages and the task result in the end. This leads to code like this for example:

async for message in self.run_stream(
    task=task,
    cancellation_token=cancellation_token,
):
   if isinstance(message, BaseMessage) and message.models_usage is not None:
        usages.append(message.models_usage)
    if isinstance(message, TaskResult):
        result = message

So you basically have to check the types of the messages, find the task result in the message and such stuff. This is partially also an issue with Python, because typings do not allow to specify that TaskResult will always be the last message.

I wonder if it would be better to separate concerns here and have one method for the actual messages and one method for the task result or something like this?

Why is this needed?

Make code easier to use.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions