class_docstr: (In preview) A class for generic conversable agents which can be configured as assistant or user proxy.
  
  After receiving each message, the agent will send a reply to the sender unless the msg is a termination msg.
  For example, AssistantAgent and UserProxyAgent are subclasses of this class,
  configured with different default settings.
  
  To modify auto reply, override `generate_reply` method.
  To disable/enable human response in every turn, set `human_input_mode` to "NEVER" or "ALWAYS".
  To modify the way to get human input, override `get_human_input` method.
  To modify the way to execute code blocks, single code block, or function call, override `execute_code_blocks`,
  `run_code`, and `execute_function` methods respectively.
  To customize the initial message when a conversation starts, override `generate_init_message` method.
class_docstr_tok: ["(","In","preview",")","A","class","for","generic","conversable","agents","which","can","be","configured","as","assistant","or","user","proxy",".","After","receiving","each","message",",","the","agent","will","send","a","reply","to","the","sender","unless","the","msg","is","a","termination","msg",".","For","example",",","AssistantAgent","and","UserProxyAgent","are","subclasses","of","this","class",",","configured","with","different","default","settings",".","To","modify","auto","reply",",","override","`","generate_reply","`","method",".","To","disable\/enable","human","response","in","every","turn",",","set","`","human_input_mode","`","to","``","NEVER","''","or","``","ALWAYS","''",".","To","modify","the","way","to","get","human","input",",","override","`","get_human_input","`","method",".","To","modify","the","way","to","execute","code","blocks",",","single","code","block",",","or","function","call",",","override","`","execute_code_blocks","`",",","`","run_code","`",",","and","`","execute_function","`","methods","respectively",".","To","customize","the","initial","message","when","a","conversation","starts",",","override","`","generate_init_message","`","method","."]
docstr: Register a reply function.
  
  The reply function will be called when the trigger matches the sender.
  The function registered later will be checked earlier by default.
  To change the order, set the position to a positive integer.
  
  Both sync and async reply functions can be registered. The sync reply function will be triggered
  from both sync and async chats. However, an async reply function will only be triggered from async
  chats (initiated with `ConversableAgent.a_initiate_chat`). If an `async` reply function is registered
  and a chat is initialized with a sync function, `ignore_async_in_sync_chat` determines the behaviour as follows:
  - if `ignore_async_in_sync_chat` is set to `False` (default value), an exception will be raised, and
  - if `ignore_async_in_sync_chat` is set to `True`, the reply function will be ignored.
  
  Args:
      trigger (Agent class, str, Agent instance, callable, or list): the trigger.
          - If a class is provided, the reply function will be called when the sender is an instance of the class.
          - If a string is provided, the reply function will be called when the sender's name matches the string.
          - If an agent instance is provided, the reply function will be called when the sender is the agent instance.
          - If a callable is provided, the reply function will be called when the callable returns True.
          - If a list is provided, the reply function will be called when any of the triggers in the list is activated.
          - If None is provided, the reply function will be called only when the sender is None.
          Note: Be sure to register `None` as a trigger if you would like to trigger an auto-reply function with non-empty messages and `sender=None`.
      reply_func (Callable): the reply function.
          The function takes a recipient agent, a list of messages, a sender agent and a config as input and returns a reply message.
      position: the position of the reply function in the reply function list.
      config: the config to be passed to the reply function, see below.
      reset_config: the function to reset the config, see below.
      ignore_async_in_sync_chat: whether to ignore the async reply function in sync chats. If `False`, an exception
          will be raised if an async reply function is registered and a chat is initialized with a sync
          function.
  ```python
  def reply_func(
      recipient: ConversableAgent,
      messages: Optional[List[Dict]] = None,
      sender: Optional[Agent] = None,
      config: Optional[Any] = None,
  ) -> Tuple[bool, Union[str, Dict, None]]:
  ```
      position (int): the position of the reply function in the reply function list.
          The function registered later will be checked earlier by default.
          To change the order, set the position to a positive integer.
      config (Any): the config to be passed to the reply function.
          When an agent is reset, the config will be reset to the original value.
      reset_config (Callable): the function to reset the config.
          The function returns None. Signature: ```def reset_config(config: Any)```
docstr_tok: ["Register","a","reply","function",".","The","reply","function","will","be","called","when","the","trigger","matches","the","sender",".","The","function","registered","later","will","be","checked","earlier","by","default",".","To","change","the","order",",","set","the","position","to","a","positive","integer",".","Both","sync","and","async","reply","functions","can","be","registered",".","The","sync","reply","function","will","be","triggered","from","both","sync","and","async","chats",".","However",",","an","async","reply","function","will","only","be","triggered","from","async","chats","(","initiated","with","`","ConversableAgent.a_initiate_chat","`",")",".","If","an","`","async","`","reply","function","is","registered","and","a","chat","is","initialized","with","a","sync","function",",","`","ignore_async_in_sync_chat","`","determines","the","behaviour","as","follows",":","-","if","`","ignore_async_in_sync_chat","`","is","set","to","`","False","`","(","default","value",")",",","an","exception","will","be","raised",",","and","-","if","`","ignore_async_in_sync_chat","`","is","set","to","`","True","`",",","the","reply","function","will","be","ignored",".","Args",":","trigger","(","Agent","class",",","str",",","Agent","instance",",","callable",",","or","list",")",":","the","trigger",".","-","If","a","class","is","provided",",","the","reply","function","will","be","called","when","the","sender","is","an","instance","of","the","class",".","-","If","a","string","is","provided",",","the","reply","function","will","be","called","when","the","sender","'s","name","matches","the","string",".","-","If","an","agent","instance","is","provided",",","the","reply","function","will","be","called","when","the","sender","is","the","agent","instance",".","-","If","a","callable","is","provided",",","the","reply","function","will","be","called","when","the","callable","returns","True",".","-","If","a","list","is","provided",",","the","reply","function","will","be","called","when","any","of","the","triggers","in","the","list","is","activated",".","-","If","None","is","provided",",","the","reply","function","will","be","called","only","when","the","sender","is","None",".","Note",":","Be","sure","to","register","`","None","`","as","a","trigger","if","you","would","like","to","trigger","an","auto-reply","function","with","non-empty","messages","and","`","sender=None","`",".","reply_func","(","Callable",")",":","the","reply","function",".","The","function","takes","a","recipient","agent",",","a","list","of","messages",",","a","sender","agent","and","a","config","as","input","and","returns","a","reply","message",".","position",":","the","position","of","the","reply","function","in","the","reply","function","list",".","config",":","the","config","to","be","passed","to","the","reply","function",",","see","below",".","reset_config",":","the","function","to","reset","the","config",",","see","below",".","ignore_async_in_sync_chat",":","whether","to","ignore","the","async","reply","function","in","sync","chats",".","If","`","False","`",",","an","exception","will","be","raised","if","an","async","reply","function","is","registered","and","a","chat","is","initialized","with","a","sync","function",".","``","`","python","def","reply_func","(","recipient",":","ConversableAgent",",","messages",":","Optional","[","List","[","Dict","]","]","=","None",",","sender",":","Optional","[","Agent","]","=","None",",","config",":","Optional","[","Any","]","=","None",",",")","-",">","Tuple","[","bool",",","Union","[","str",",","Dict",",","None","]","]",":","``","`","position","(","int",")",":","the","position","of","the","reply","function","in","the","reply","function","list",".","The","function","registered","later","will","be","checked","earlier","by","default",".","To","change","the","order",",","set","the","position","to","a","positive","integer",".","config","(","Any",")",":","the","config","to","be","passed","to","the","reply","function",".","When","an","agent","is","reset",",","the","config","will","be","reset","to","the","original","value",".","reset_config","(","Callable",")",":","the","function","to","reset","the","config",".","The","function","returns","None",".","Signature",":","``","`","def","reset_config","(","config",":","Any",")","``","`"]
code: def register_reply(
      self,
      trigger: Union[
          Type[Agent], str, Agent, Callable[[Agent], bool], List
      ],
      reply_func: Callable,
      position: int = 0,
      config: Optional[Any] = None,
      reset_config: Optional[Callable] = None,
      *,
      ignore_async_in_sync_chat: bool = False,
  ):
      """Register a reply function.
  
      The reply function will be called when the trigger matches the sender.
      The function registered later will be checked earlier by default.
      To change the order, set the position to a positive integer.
  
      Both sync and async reply functions can be registered. The sync reply function will be triggered
      from both sync and async chats. However, an async reply function will only be triggered from async
      chats (initiated with `ConversableAgent.a_initiate_chat`). If an `async` reply function is registered
      and a chat is initialized with a sync function, `ignore_async_in_sync_chat` determines the behaviour as follows:
      - if `ignore_async_in_sync_chat` is set to `False` (default value), an exception will be raised, and
      - if `ignore_async_in_sync_chat` is set to `True`, the reply function will be ignored.
  
      Args:
          trigger (Agent class, str, Agent instance, callable, or list): the trigger.
              - If a class is provided, the reply function will be called when the sender is an instance of the class.
              - If a string is provided, the reply function will be called when the sender's name matches the string.
              - If an agent instance is provided, the reply function will be called when the sender is the agent instance.
              - If a callable is provided, the reply function will be called when the callable returns True.
              - If a list is provided, the reply function will be called when any of the triggers in the list is activated.
              - If None is provided, the reply function will be called only when the sender is None.
              Note: Be sure to register `None` as a trigger if you would like to trigger an auto-reply function with non-empty messages and `sender=None`.
          reply_func (Callable): the reply function.
              The function takes a recipient agent, a list of messages, a sender agent and a config as input and returns a reply message.
          position: the position of the reply function in the reply function list.
          config: the config to be passed to the reply function, see below.
          reset_config: the function to reset the config, see below.
          ignore_async_in_sync_chat: whether to ignore the async reply function in sync chats. If `False`, an exception
              will be raised if an async reply function is registered and a chat is initialized with a sync
              function.
      ```python
      def reply_func(
          recipient: ConversableAgent,
          messages: Optional[List[Dict]] = None,
          sender: Optional[Agent] = None,
          config: Optional[Any] = None,
      ) -> Tuple[bool, Union[str, Dict, None]]:
      ```
          position (int): the position of the reply function in the reply function list.
              The function registered later will be checked earlier by default.
              To change the order, set the position to a positive integer.
          config (Any): the config to be passed to the reply function.
              When an agent is reset, the config will be reset to the original value.
          reset_config (Callable): the function to reset the config.
              The function returns None. Signature: ```def reset_config(config: Any)```
      """
      if not isinstance(trigger, (type, str, Agent, Callable, list)):
          raise ValueError(
              "trigger must be a class, a string, an agent, a callable or a list."
          )
      self._reply_func_list.insert(
          position,
          {
              "trigger": trigger,
              "reply_func": reply_func,
              "config": copy.copy(config),
              "init_config": config,
              "reset_config": reset_config,
          },
      )
      if ignore_async_in_sync_chat and inspect.iscoroutinefunction(
          reply_func
      ):
          self._ignore_async_func_in_sync_chat_list.append(reply_func)
  
imports: import asyncio
  import copy
  import functools
  import inspect
  import json
  import logging
  import re
  from collections import defaultdict
  from typing import Any, Awaitable, Callable, Dict, List, Literal, Optional, Tuple, Type, TypeVar, Union
  from ..None import OpenAIWrapper
  from ..code_utils import DEFAULT_MODEL, UNKNOWN, content_str, execute_code, extract_code, infer_lang
  from ..function_utils import get_function_schema, load_basemodels_if_needed, serialize_to_str
  from .agent import Agent
  from .._pydantic import model_dump
label_desc: Use image node_id 2 for calling the ConversableAgent obj's underlying member method code with example usage: obj.register_reply(trigger, reply_func, position, config, reset_config) without return types