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: Reply based on the conversation history and the sender.
  
  Either messages or sender must be provided.
  Register a reply_func with `None` as one trigger for it to be activated when `messages` is non-empty and `sender` is `None`.
  Use registered auto reply functions to generate replies.
  By default, the following functions are checked in order:
  1. check_termination_and_human_reply
  2. generate_function_call_reply (deprecated in favor of tool_calls)
  3. generate_tool_calls_reply
  4. generate_code_execution_reply
  5. generate_oai_reply
  Every function returns a tuple (final, reply).
  When a function returns final=False, the next function will be checked.
  So by default, termination and human reply will be checked first.
  If not terminating and human reply is skipped, execute function or code and return the result.
  AI replies are generated only when no code execution is performed.
  
  Args:
      messages: a list of messages in the conversation history.
      default_reply (str or dict): default reply.
      sender: sender of an Agent instance.
      exclude: a list of functions to exclude.
  
  Returns:
      str or dict or None: reply. None if no reply is generated.
docstr_tok: ["Reply","based","on","the","conversation","history","and","the","sender",".","Either","messages","or","sender","must","be","provided",".","Register","a","reply_func","with","`","None","`","as","one","trigger","for","it","to","be","activated","when","`","messages","`","is","non-empty","and","`","sender","`","is","`","None","`",".","Use","registered","auto","reply","functions","to","generate","replies",".","By","default",",","the","following","functions","are","checked","in","order",":","1.","check_termination_and_human_reply","2.","generate_function_call_reply","(","deprecated","in","favor","of","tool_calls",")","3.","generate_tool_calls_reply","4.","generate_code_execution_reply","5.","generate_oai_reply","Every","function","returns","a","tuple","(","final",",","reply",")",".","When","a","function","returns","final=False",",","the","next","function","will","be","checked",".","So","by","default",",","termination","and","human","reply","will","be","checked","first",".","If","not","terminating","and","human","reply","is","skipped",",","execute","function","or","code","and","return","the","result",".","AI","replies","are","generated","only","when","no","code","execution","is","performed",".","Args",":","messages",":","a","list","of","messages","in","the","conversation","history",".","default_reply","(","str","or","dict",")",":","default","reply",".","sender",":","sender","of","an","Agent","instance",".","exclude",":","a","list","of","functions","to","exclude",".","Returns",":","str","or","dict","or","None",":","reply",".","None","if","no","reply","is","generated","."]
code: def generate_reply(
      self,
      messages: Optional[List[Dict]] = None,
      sender: Optional[Agent] = None,
      exclude: Optional[List[Callable]] = None,
  ) -> Union[str, Dict, None]:
      """Reply based on the conversation history and the sender.
  
      Either messages or sender must be provided.
      Register a reply_func with `None` as one trigger for it to be activated when `messages` is non-empty and `sender` is `None`.
      Use registered auto reply functions to generate replies.
      By default, the following functions are checked in order:
      1. check_termination_and_human_reply
      2. generate_function_call_reply (deprecated in favor of tool_calls)
      3. generate_tool_calls_reply
      4. generate_code_execution_reply
      5. generate_oai_reply
      Every function returns a tuple (final, reply).
      When a function returns final=False, the next function will be checked.
      So by default, termination and human reply will be checked first.
      If not terminating and human reply is skipped, execute function or code and return the result.
      AI replies are generated only when no code execution is performed.
  
      Args:
          messages: a list of messages in the conversation history.
          default_reply (str or dict): default reply.
          sender: sender of an Agent instance.
          exclude: a list of functions to exclude.
  
      Returns:
          str or dict or None: reply. None if no reply is generated.
      """
      if all((messages is None, sender is None)):
          error_msg = (
              f"Either {messages=} or {sender=} must be provided."
          )
          logger.error(error_msg)
          raise AssertionError(error_msg)
  
      if messages is None:
          messages = self._oai_messages[sender]
  
      # Call the hookable method that gives registered hooks a chance to process the last message.
      # Message modifications do not affect the incoming messages or self._oai_messages.
      messages = self.process_last_message(messages)
  
      for reply_func_tuple in self._reply_func_list:
          reply_func = reply_func_tuple["reply_func"]
          if exclude and reply_func in exclude:
              continue
          if inspect.iscoroutinefunction(reply_func):
              continue
          if self._match_trigger(reply_func_tuple["trigger"], sender):
              final, reply = reply_func(
                  self,
                  messages=messages,
                  sender=sender,
                  config=reply_func_tuple["config"],
              )
              if final:
                  return reply
      return self._default_auto_reply
  
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 31 for calling the ConversableAgent obj's underlying member method code with example usage: obj.generate_reply(messages, sender, exclude) and returns: self, reply