This abstract class provides a base implementation for a :class:`ChatAgent`. To create a new chat agent, subclass this class and implement the :meth:`on_messages`, :meth:`on_reset`, and :attr:`produced_message_types`. If streaming is required, also implement the :meth:`on_messages_stream` method.
An agent is considered stateful and maintains its state between calls to the :meth:`on_messages` or :meth:`on_messages_stream` methods. The agent should store its state in the agent instance. The agent should also implement the :meth:`on_reset` method to reset the agent to its initialization state.
.. note::
The caller should only pass the new messages to the agent on each call to the :meth:`on_messages` or :meth:`on_messages_stream` method. Do not pass the entire conversation history to the agent on each call. This design principle must be followed when creating a new agent. """
asyncdefon_messages(self, messages: Sequence[ChatMessage], cancellation_token: CancellationToken) -> Response: print("InterpreterAgent is called")
iflen(messages[0]) == 2: ## 即有初始prompt和PIL Image if"Improve the description based on the following feedback:"in messages[0][0]: feedback = messages[0][0] img = messages[0][1] prompt = [prompt_interpreter + feedback, img] ## 这里的prompt_interpreter就是给interpreter设置的personality prompt else: prompt = [messages[0][0], messages[0][1]] eliflen(messages[0]) > 2: if"Improve the description based on the following feedback:"in messages[0][0]: feedback = messages[0][0] prompt = [prompt_interpreter_m + feedback] else: prompt = [prompt_interpreter_m]
for i inrange(1, len(messages[0])): prompt.append(messages[0][i]) else: response = TextMessage(content = "No image input, Caption is None.", source=self.name) return Response(chat_message=response)