class_docstr: The TextEnvironment enables interaction of a LLM with an environment using tools.
docstr: Step the environment forward one turn.
  
  Args:
      history (`TextHistory`): The history to step forward.
docstr_tok: ["Step","the","environment","forward","one","turn",".","Args",":","history","(","`","TextHistory","`",")",":","The","history","to","step","forward","."]
code: def step(self, history):
      """
      Step the environment forward one turn.
  
      Args:
          history (`TextHistory`): The history to step forward.
      """
      truncated, ended = self.task_end_check(history)
      if ended:
          history.complete(truncated=truncated)
      if history.completed:
          return history
  
      tool, query = self.parse_tool_call(history.last_text_segment)
      if tool is None or query is None:
          response = f"Unknown tool call: {history.last_text_segment}"
      else:
          if tool not in self.tools:
              response = f"Unknown tool {tool}."
          try:
              response = self.tools[tool](query)
          except Exception as error:
              response = f"Tool error: {str(error)}"
  
      if len(response) > self.max_tool_response:
          response = response[: (self.max_tool_response - 3)] + "..."
  
      history.append_segment(
          response + self.response_token,
          self.tokenizer(
              response + self.response_token, return_tensors="pt"
          )
          .input_ids[0]
          .to(self.model.pretrained_model.device),
          system=True,
      )
  
      return history
  
imports: import re
  import warnings
  import torch
  from accelerate.utils import extract_model_from_parallel
  from transformers import StoppingCriteria, StoppingCriteriaList
  from ..import_utils import is_rich_available
label_desc: Use image node_id 3 for calling the TextEnvironment obj's underlying member method code with example usage: obj.step(history) and returns: history, history