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
f"Message type {type(message)} not in target types {self._expected_types} of {self.id}"
115
-
)
119
+
ifself._unknown_type_policy=="warn":
120
+
warnings.warn(
121
+
f"Message type {type(message)} not in target types {self._expected_types} of {self.id}. Set unknown_type_policy to 'error' to raise an exception, or 'ignore' to suppress this warning.",
122
+
stacklevel=1,
123
+
)
124
+
returnNone
125
+
elifself._unknown_type_policy=="error":
126
+
raiseCantHandleException(
127
+
f"Message type {type(message)} not in target types {self._expected_types} of {self.id}. Set unknown_type_policy to 'warn' to suppress this exception, or 'ignore' to suppress this warning."
"""The closure agent allows you to define an agent using a closure, or function without needing to define a class. It allows values to be extracted out of the runtime.
153
+
154
+
The closure can define the type of message which is expected, or `Any` can be used to accept any type of message.
155
+
156
+
Example:
157
+
158
+
.. code-block:: python
159
+
160
+
import asyncio
161
+
from autogen_core import SingleThreadedAgentRuntime, MessageContext, ClosureAgent, ClosureContext
162
+
from dataclasses import dataclass
163
+
164
+
from autogen_core._default_subscription import DefaultSubscription
165
+
from autogen_core._default_topic import DefaultTopicId
runtime (AgentRuntime): Runtime to register the agent to
197
+
type (str): Agent type of registered agent
198
+
closure (Callable[[ClosureContext, T, MessageContext], Awaitable[Any]]): Closure to handle messages
199
+
unknown_type_policy (Literal["error", "warn", "ignore"], optional): What to do if a type is encountered that does not match the closure type. Defaults to "warn".
200
+
skip_direct_message_subscription (bool, optional): Do not add direct message subscription for this agent. Defaults to False.
201
+
description (str, optional): Description of what agent does. Defaults to "".
202
+
subscriptions (Callable[[], list[Subscription] | Awaitable[list[Subscription]]] | None, optional): List of subscriptions for this closure agent. Defaults to None.
0 commit comments