flower icon indicating copy to clipboard operation
flower copied to clipboard

refactor(framework) Convert `Driver.pull_messages` to no-arg, returning a list

Open chongshenng opened this issue 9 months ago • 1 comments

Issue

Description

Presently, users need to pass the msg_ids returned from driver.push_messages(msgs) to driver.pull_messages(msg_ids) in order to retrieve the response messages. In some cases, users may not want to keep track of msg_ids but still want to retrieve any response messages based on the messages that have been pushed.

Proposal

Explanation

Convert the message_ids arg in the Driver.pull_messages() method to an Optional[Iterable[str]] type. If no message_ids are provided, all message_ids that are stored on the Driver object are retrieved.

This simplifies the usage to:

@app.main()
def main(driver: Driver, context: Context) -> None:
    # Get available nodes
    driver.get_node_ids()
    ...
    
    # Push messages
    driver.push_messages(messages)
    ...
    
    # Get replies
    replies = driver.pull_messages()  # `message_ids` no longer needs to be passed
    for reply in replies:
        # Do something

[!NOTE]
The user may still pass message_ids to driver.pull_messages(). In this case, only the IDs that are stored in the Driver object (during the call to push_messages) will be pulled.

chongshenng avatar Mar 13 '25 16:03 chongshenng

Converting to draft, pending clarification of API usage.

chongshenng avatar Mar 15 '25 20:03 chongshenng

Closing as this is stale.

chongshenng avatar Aug 14 '25 07:08 chongshenng