You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow AgentSet.do() to take Callable function (#2219)
This PR enhances `AgentSet.do` to take a callable or str. Currently, AgentSet.do takes a `str` which maps to a method on the agents in the set. This PR makes it possible to also use a `Callable` instead.
This callable will be called with the `agent` as the first argument.
⚠️ Breaking change ⚠️
A small breaking change is introduced here: the `method_name` parameter is renamed to `method`. For models that use this as a keyword argument this is a breaking change, and need to replace `do(method_name="something")` with `do(method="something")`.
Invoke a method or function on each agent in the AgentSet.
224
224
225
225
Args:
226
-
method_name (str): The name of the method to call on each agent.
226
+
method (str, callable): the callable to do on each agents
227
+
228
+
* in case of str, the name of the method to call on each agent.
229
+
* in case of callable, the function to be called with each agent as first argument
230
+
227
231
return_results (bool, optional): If True, returns the results of the method calls; otherwise, returns the AgentSet itself. Defaults to False, so you can chain method calls.
228
-
*args: Variable length argument list passed to the method being called.
229
-
**kwargs: Arbitrary keyword arguments passed to the method being called.
232
+
*args: Variable length argument list passed to the callable being called.
233
+
**kwargs: Arbitrary keyword arguments passed to the callable being called.
230
234
231
235
Returns:
232
-
AgentSet | list[Any]: The results of the method calls if return_results is True, otherwise the AgentSet itself.
236
+
AgentSet | list[Any]: The results of the callable calls if return_results is True, otherwise the AgentSet itself.
233
237
"""
234
238
# we iterate over the actual weakref keys and check if weakref is alive before calling the method
0 commit comments