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

Agent v2 #1708

Closed
jstarry opened this issue Jan 23, 2021 · 3 comments
Closed

Agent v2 #1708

jstarry opened this issue Jan 23, 2021 · 3 comments
Labels
A-yew-agent Area: The yew-agent crate breaking change feature-request A feature request

Comments

@jstarry
Copy link
Member

jstarry commented Jan 23, 2021

Problem

The current Agent trait API includes a way to handle "messages" and "input" and it's not immediately clear when to use each of these. Messages are unidirectional and primarily intended for internal agent usage. Input messages are for bidirectional communication and have a corresponding output message type and are intended for external client usage.

Suggested Changes

  • Rename "input" to "message" and allow agents to implement handlers for arbitrary number of message input/output pairs
  • Rename "message" to "event" and remove external access from AgentLink
  • Remove the "respond" method from AgentLink
@frostu8
Copy link

frostu8 commented Apr 8, 2021

In addition to the leading suggested changes, I think we should split the Agent trait into two variants like AgentCast and AgentCall, so that agent logic is better compartmentalized. After all, why should you worry about defining the Input or Ouput types when you're only going to use an Event type?

We could use a blanket trait to implement a single Agent class so an agent can still be both AgentCast and AgentCall.

/// An agent that consumes a value.
pub trait AgentCast<IN> {
    fn create(link: AgentLink<Self>) -> Self;
    // ...other general agent functions, if needed.

    fn cast(&mut self, input: IN);
}

/// An agent that consumes a value and returns a new value.
pub trait AgentCall<IN> {
    type Output;

    fn create(link: AgentLink<Self>) -> Self;
    // ...other general agent functions, if needed.
    fn call(&mut self, input: IN) -> Self::Output;
    // this might look closer to this when it is implemented:
    // fn call(&mut self, input: IN)
}

/// An agent.
#[doc(hidden)]
pub trait Agent {
    fn create(link: AgentLink<Self>) -> Self;
    // ...other general agent functions, if needed.
}

// these blanket implementations abstract away the hassle of having to
// implement two traits from the programmer, so they can focus more on
// the implementation

impl<T, IN> Agent for T
where T: AgentCast<IN> {
    fn create(link: AgentLink<Self>) -> Self {
        <Self as AgentCast<IN>>::create(link)
    }
    // ...other general agent functions, if needed.
}

impl<T, IN> Agent for T
where T: AgentCall<IN> {
    fn create(link: AgentLink<Self>) -> Self {
        <Self as AgentCall<IN>>::create(link)
    }
    // ...other general agent functions, if needed.
}

I'm not too knowledgeable about the internals yet, so excuse my assumptions.

@mc1098
Copy link
Contributor

mc1098 commented Sep 13, 2021

Now that the new Component trait has landed #1961 - with the removal of ComponentLink its buddy AgentLink feels somewhat out of sync. We should consider harmonizing the two as somewhat discussed in #2050.

@mc1098 mc1098 added the A-yew-agent Area: The yew-agent crate label Sep 20, 2021
@ranile
Copy link
Member

ranile commented Jan 5, 2022

Irrelevant since agents aren't implemented by Yew. The improvement will be in gloo.

See #2326

@ranile ranile closed this as completed Jan 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-yew-agent Area: The yew-agent crate breaking change feature-request A feature request
Projects
None yet
Development

No branches or pull requests

4 participants