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

Enable Agents to send messages to themselves. #1215

Merged
merged 4 commits into from
May 14, 2020

Conversation

totorigolo
Copy link
Contributor

@totorigolo totorigolo commented May 12, 2020

Add methods on AgentLink to allow sending messages to itself, as ComponentLink can do. What do you think? 🙂

Related to: #1209

@totorigolo totorigolo force-pushed the agent-send-message branch from 5ecb943 to 5e7862f Compare May 12, 2020 11:33
@jstarry
Copy link
Member

jstarry commented May 12, 2020

@totorigolo did you randomly think to do this? Haha, @mkawalec just opened a PR to do the same #1214 🤣

Can you two sort out which API is preferred? send_message or send 😄

@mkawalec
Copy link
Contributor

:D I personally prefer send over send_message as the types document what we are sending and send is used in other places in Yew.

@mkawalec
Copy link
Contributor

@totorigolo I like that this unifies the API between agents and components. My vote is on this implementation over my PR :)

@mkawalec mkawalec mentioned this pull request May 12, 2020
@totorigolo
Copy link
Contributor Author

totorigolo commented May 12, 2020

@jstarry I had a tab opened in my browser since like two days, in order to test that it works as expected. But yes, this just came as a need while using agents 🙂

And I just discovered about this issue hunt thingy. @mkawalec add/improve an example in a PR and it's yours 😉

About the naming, since there are two message types that you could send to agents (Agent::Message and Agent::Input), and since we cannot handle both with the same function, I think that naming it send_message is more explicit. Plus it's consistent with components.

Talking about the consistency, what about making it a trait, implemented for AgentLink and ComponentLink, with send_message, send_message_batch and callback?

@jstarry
Copy link
Member

jstarry commented May 12, 2020

Haha impeccable timing ;)

If the trait is just for enforcing consistency, I don't think it's necessary

Copy link
Member

@jstarry jstarry left a comment

Choose a reason for hiding this comment

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

I think we can drop the batch method unless you can share a good usecase for it!

@@ -160,6 +176,15 @@ where
.expect("agent was not created to process messages")
.update(msg);
}
AgentLifecycleEvent::MessageBatch(batch) => {
Copy link
Member

Choose a reason for hiding this comment

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

It doesnt look like this adds much value. It's nice to have message batching for components to reduce renders, but not needed for agents

Copy link
Contributor Author

@totorigolo totorigolo May 12, 2020

Choose a reason for hiding this comment

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

I kept it for consistency, never used it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

However, AgentScope's send function does some work for each message: cloning, boxing, pushing in a vec so potentially allocating, locking using Rc<RefCell<()>>. If sending a batch is really needed, this should offer a nice boost. But on the other hand, it's easy to implement if needed, knowing that it's already possible to alternatively send a Msg::Batch(vec![...]).

@mkawalec
Copy link
Contributor

@totorigolo I'll add the example I had in the other PR in a separate PR once this is merged.

@totorigolo
Copy link
Contributor Author

@mkawalec Sure! Could you just add a message sent from handle_input?

@jstarry Is this ready to merge?

@jstarry jstarry merged commit 6ef7cec into yewstack:master May 14, 2020
@totorigolo totorigolo deleted the agent-send-message branch May 14, 2020 06:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants