class_docstr: (Experimental) A MathChat agent that can handle math problems.
docstr: Args:
      name (str): name of the agent
      is_termination_msg (function): a function that takes a message in the form of a dictionary and returns a boolean value indicating if this received message is a termination message.
          The dict can contain the following keys: "content", "role", "name", "function_call".
      human_input_mode (str): whether to ask for human inputs every time a message is received.
          Possible values are "ALWAYS", "TERMINATE", "NEVER".
          (1) When "ALWAYS", the agent prompts for human input every time a message is received.
              Under this mode, the conversation stops when the human input is "exit",
              or when is_termination_msg is True and there is no human input.
          (2) When "TERMINATE", the agent only prompts for human input only when a termination message is received or
              the number of auto reply reaches the max_consecutive_auto_reply.
          (3) (Default) When "NEVER", the agent will never prompt for human input. Under this mode, the conversation stops
              when the number of auto reply reaches the max_consecutive_auto_reply or when is_termination_msg is True.
      default_auto_reply (str or dict or None): the default auto reply message when no code execution or llm based reply is generated.
      max_invalid_q_per_step (int): (ADDED) the maximum number of invalid queries per step.
      **kwargs (dict): other kwargs in [UserProxyAgent](../user_proxy_agent#__init__).
docstr_tok: ["Args",":","name","(","str",")",":","name","of","the","agent","is_termination_msg","(","function",")",":","a","function","that","takes","a","message","in","the","form","of","a","dictionary","and","returns","a","boolean","value","indicating","if","this","received","message","is","a","termination","message",".","The","dict","can","contain","the","following","keys",":","``","content","''",",","``","role","''",",","``","name","''",",","``","function_call","''",".","human_input_mode","(","str",")",":","whether","to","ask","for","human","inputs","every","time","a","message","is","received",".","Possible","values","are","``","ALWAYS","''",",","``","TERMINATE","''",",","``","NEVER","''",".","(","1",")","When","``","ALWAYS","''",",","the","agent","prompts","for","human","input","every","time","a","message","is","received",".","Under","this","mode",",","the","conversation","stops","when","the","human","input","is","``","exit","''",",","or","when","is_termination_msg","is","True","and","there","is","no","human","input",".","(","2",")","When","``","TERMINATE","''",",","the","agent","only","prompts","for","human","input","only","when","a","termination","message","is","received","or","the","number","of","auto","reply","reaches","the","max_consecutive_auto_reply",".","(","3",")","(","Default",")","When","``","NEVER","''",",","the","agent","will","never","prompt","for","human","input",".","Under","this","mode",",","the","conversation","stops","when","the","number","of","auto","reply","reaches","the","max_consecutive_auto_reply","or","when","is_termination_msg","is","True",".","default_auto_reply","(","str","or","dict","or","None",")",":","the","default","auto","reply","message","when","no","code","execution","or","llm","based","reply","is","generated",".","max_invalid_q_per_step","(","int",")",":","(","ADDED",")","the","maximum","number","of","invalid","queries","per","step",".","*","*","kwargs","(","dict",")",":","other","kwargs","in","[","UserProxyAgent","]","(","..","\/user_proxy_agent","#","__init__",")","."]
code: def __init__(
      self,
      name: Optional[
          str
      ] = "MathChatAgent",  # default set to MathChatAgent
      is_termination_msg: Optional[
          Callable[[Dict], bool]
      ] = _is_termination_msg_mathchat,  # terminate if \boxed{} in message
      human_input_mode: Optional[str] = "NEVER",  # Fully automated
      default_auto_reply: Optional[
          Union[str, Dict, None]
      ] = DEFAULT_REPLY,
      max_invalid_q_per_step=3,  # a parameter needed in MathChat
      **kwargs,
  ):
      """
      Args:
          name (str): name of the agent
          is_termination_msg (function): a function that takes a message in the form of a dictionary and returns a boolean value indicating if this received message is a termination message.
              The dict can contain the following keys: "content", "role", "name", "function_call".
          human_input_mode (str): whether to ask for human inputs every time a message is received.
              Possible values are "ALWAYS", "TERMINATE", "NEVER".
              (1) When "ALWAYS", the agent prompts for human input every time a message is received.
                  Under this mode, the conversation stops when the human input is "exit",
                  or when is_termination_msg is True and there is no human input.
              (2) When "TERMINATE", the agent only prompts for human input only when a termination message is received or
                  the number of auto reply reaches the max_consecutive_auto_reply.
              (3) (Default) When "NEVER", the agent will never prompt for human input. Under this mode, the conversation stops
                  when the number of auto reply reaches the max_consecutive_auto_reply or when is_termination_msg is True.
          default_auto_reply (str or dict or None): the default auto reply message when no code execution or llm based reply is generated.
          max_invalid_q_per_step (int): (ADDED) the maximum number of invalid queries per step.
          **kwargs (dict): other kwargs in [UserProxyAgent](../user_proxy_agent#__init__).
      """
      super().__init__(
          name=name,
          is_termination_msg=is_termination_msg,
          human_input_mode=human_input_mode,
          default_auto_reply=default_auto_reply,
          **kwargs,
      )
      self.register_reply(
          [Agent, None],
          MathUserProxyAgent._generate_math_reply,
          position=2,
      )
      # fixed var
      self._max_invalid_q_per_step = max_invalid_q_per_step
  
      # mutable
      self._valid_q_count = 0
      self._total_q_count = 0
      self._accum_invalid_q_per_step = 0
      self._previous_code = ""
      self.last_reply = None
  
imports: import re
  import os
  from pydantic import BaseModel, Extra, root_validator
  from typing import Any, Callable, Dict, List, Optional, Union, Tuple
  from time import sleep
  from autogen._pydantic import PYDANTIC_V1
  from autogen.agentchat import Agent, UserProxyAgent
  from autogen.code_utils import UNKNOWN, extract_code, execute_code, infer_lang
  from autogen.math_utils import get_answer
label_desc: Use image node_id 1 to create a new MathUserProxyAgent object from inherited base classes: UserProxyAgent with example: obj = MathUserProxyAgent(name, is_termination_msg, human_input_mode, default_auto_reply, max_invalid_q_per_step)