docstr: Construct a new StreamlitCallbackHandler. This CallbackHandler is geared
  towards use with a LangChain Agent; it displays the Agent's LLM and tool-usage
  "thoughts" inside a series of Streamlit expanders.
  
  Parameters
  ----------
  
  parent_container
      The `st.container` that will contain all the Streamlit elements that the
      Handler creates.
  
  max_thought_containers
  
      .. note::
          This parameter is deprecated and is ignored in the latest version of
          the callback handler.
  
      The max number of completed LLM thought containers to show at once. When
      this threshold is reached, a new thought will cause the oldest thoughts to
      be collapsed into a "History" expander. Defaults to 4.
  
  expand_new_thoughts
      Each LLM "thought" gets its own `st.expander`. This param controls whether
      that expander is expanded by default. Defaults to False.
  
  collapse_completed_thoughts
      If True, LLM thought expanders will be collapsed when completed.
      Defaults to False.
  
  thought_labeler
      An optional custom LLMThoughtLabeler instance. If unspecified, the handler
      will use the default thought labeling logic. Defaults to None.
docstr_tok: ["Construct","a","new","StreamlitCallbackHandler",".","This","CallbackHandler","is","geared","towards","use","with","a","LangChain","Agent",";","it","displays","the","Agent","'s","LLM","and","tool-usage","''","thoughts","''","inside","a","series","of","Streamlit","expanders",".","Parameters","--","--","--","--","--","parent_container","The","`","st.container","`","that","will","contain","all","the","Streamlit","elements","that","the","Handler","creates",".","max_thought_containers","..","note",":",":","This","parameter","is","deprecated","and","is","ignored","in","the","latest","version","of","the","callback","handler",".","The","max","number","of","completed","LLM","thought","containers","to","show","at","once",".","When","this","threshold","is","reached",",","a","new","thought","will","cause","the","oldest","thoughts","to","be","collapsed","into","a","``","History","''","expander",".","Defaults","to","4.","expand_new_thoughts","Each","LLM","``","thought","''","gets","its","own","`","st.expander","`",".","This","param","controls","whether","that","expander","is","expanded","by","default",".","Defaults","to","False",".","collapse_completed_thoughts","If","True",",","LLM","thought","expanders","will","be","collapsed","when","completed",".","Defaults","to","False",".","thought_labeler","An","optional","custom","LLMThoughtLabeler","instance",".","If","unspecified",",","the","handler","will","use","the","default","thought","labeling","logic",".","Defaults","to","None","."]
code: def __init__(
      self,
      parent_container: DeltaGenerator,
      *,
      max_thought_containers: int = 4,
      expand_new_thoughts: bool = False,
      collapse_completed_thoughts: bool = False,
      thought_labeler: Optional[LLMThoughtLabeler] = None,
  ):
      """Construct a new StreamlitCallbackHandler. This CallbackHandler is geared
      towards use with a LangChain Agent; it displays the Agent's LLM and tool-usage
      "thoughts" inside a series of Streamlit expanders.
  
      Parameters
      ----------
  
      parent_container
          The `st.container` that will contain all the Streamlit elements that the
          Handler creates.
  
      max_thought_containers
  
          .. note::
              This parameter is deprecated and is ignored in the latest version of
              the callback handler.
  
          The max number of completed LLM thought containers to show at once. When
          this threshold is reached, a new thought will cause the oldest thoughts to
          be collapsed into a "History" expander. Defaults to 4.
  
      expand_new_thoughts
          Each LLM "thought" gets its own `st.expander`. This param controls whether
          that expander is expanded by default. Defaults to False.
  
      collapse_completed_thoughts
          If True, LLM thought expanders will be collapsed when completed.
          Defaults to False.
  
      thought_labeler
          An optional custom LLMThoughtLabeler instance. If unspecified, the handler
          will use the default thought labeling logic. Defaults to None.
      """
      self._parent_container = parent_container
      self._history_parent = parent_container.container()
      self._current_thought: Optional[LLMThought] = None
      self._completed_thoughts: List[LLMThought] = []
      self._max_thought_containers = max(max_thought_containers, 1)
      self._expand_new_thoughts = expand_new_thoughts
      self._collapse_completed_thoughts = collapse_completed_thoughts
      self._thought_labeler = thought_labeler or LLMThoughtLabeler()
  
imports: from __future__ import annotations
  import time
  from enum import Enum
  from typing import TYPE_CHECKING, Any, Dict, List, NamedTuple, Optional
  from langchain.callbacks.base import BaseCallbackHandler
  from langchain.schema import AgentAction, AgentFinish, LLMResult
  from streamlit.runtime.metrics_util import gather_metrics
label_desc: Use image node_id 1 to create a new StreamlitCallbackHandler object from inherited base classes: BaseCallbackHandler with example: obj = StreamlitCallbackHandler(parent_container)