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: Append a message to the ChatCompletion conversation.
  
  If the message received is a string, it will be put in the "content" field of the new dictionary.
  If the message received is a dictionary but does not have any of the three fields "content", "function_call", or "tool_calls",
      this message is not a valid ChatCompletion message.
  If only "function_call" or "tool_calls" is provided, "content" will be set to None if not provided, and the role of the message will be forced "assistant".
  
  Args:
      message (dict or str): message to be appended to the ChatCompletion conversation.
      role (str): role of the message, can be "assistant" or "function".
      conversation_id (Agent): id of the conversation, should be the recipient or sender.
  
  Returns:
      bool: whether the message is appended to the ChatCompletion conversation.
docstr_tok: ["Append","a","message","to","the","ChatCompletion","conversation",".","If","the","message","received","is","a","string",",","it","will","be","put","in","the","``","content","''","field","of","the","new","dictionary",".","If","the","message","received","is","a","dictionary","but","does","not","have","any","of","the","three","fields","``","content","''",",","``","function_call","''",",","or","``","tool_calls","''",",","this","message","is","not","a","valid","ChatCompletion","message",".","If","only","``","function_call","''","or","``","tool_calls","''","is","provided",",","``","content","''","will","be","set","to","None","if","not","provided",",","and","the","role","of","the","message","will","be","forced","``","assistant","''",".","Args",":","message","(","dict","or","str",")",":","message","to","be","appended","to","the","ChatCompletion","conversation",".","role","(","str",")",":","role","of","the","message",",","can","be","``","assistant","''","or","``","function","''",".","conversation_id","(","Agent",")",":","id","of","the","conversation",",","should","be","the","recipient","or","sender",".","Returns",":","bool",":","whether","the","message","is","appended","to","the","ChatCompletion","conversation","."]
code: def _append_oai_message(
      self, message: Union[Dict, str], role, conversation_id: Agent
  ) -> bool:
      """Append a message to the ChatCompletion conversation.
  
      If the message received is a string, it will be put in the "content" field of the new dictionary.
      If the message received is a dictionary but does not have any of the three fields "content", "function_call", or "tool_calls",
          this message is not a valid ChatCompletion message.
      If only "function_call" or "tool_calls" is provided, "content" will be set to None if not provided, and the role of the message will be forced "assistant".
  
      Args:
          message (dict or str): message to be appended to the ChatCompletion conversation.
          role (str): role of the message, can be "assistant" or "function".
          conversation_id (Agent): id of the conversation, should be the recipient or sender.
  
      Returns:
          bool: whether the message is appended to the ChatCompletion conversation.
      """
      message = self._message_to_dict(message)
      # create oai message to be appended to the oai conversation that can be passed to oai directly.
      oai_message = {
          k: message[k]
          for k in (
              "content",
              "function_call",
              "tool_calls",
              "tool_responses",
              "tool_call_id",
              "name",
              "context",
          )
          if k in message and message[k] is not None
      }
      if "content" not in oai_message:
          if (
              "function_call" in oai_message
              or "tool_calls" in oai_message
          ):
              oai_message[
                  "content"
              ] = None  # if only function_call is provided, content will be set to None.
          else:
              return False
  
      if message.get("role") in ["function", "tool"]:
          oai_message["role"] = message.get("role")
      else:
          oai_message["role"] = role
  
      if oai_message.get("function_call", False) or oai_message.get(
          "tool_calls", False
      ):
          oai_message[
              "role"
          ] = "assistant"  # only messages with role 'assistant' can have a function call.
      self._oai_messages[conversation_id].append(oai_message)
      return True
  
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 13 for calling the ConversableAgent obj's underlying member method code with example usage: obj._append_oai_message(message, role, conversation_id) and returns: True, False