Chat with agent.
(self,
user_input: str,
history: List[dict] = None)
| 72 | self.agent._llm.template_parser = value |
| 73 | |
| 74 | def chat(self, |
| 75 | user_input: str, |
| 76 | history: List[dict] = None) -> Tuple[str, List[dict], List[dict]]: |
| 77 | """Chat with agent.""" |
| 78 | if history: |
| 79 | self.agent._session_history = history |
| 80 | |
| 81 | from lagent.schema import ActionReturn, AgentReturn |
| 82 | generation: AgentReturn = self.agent.chat(user_input) |
| 83 | |
| 84 | inner_steps = generation.inner_steps |
| 85 | answer = generation.response |
| 86 | steps = [] |
| 87 | |
| 88 | for step in generation.actions: |
| 89 | step: ActionReturn |
| 90 | steps.append( |
| 91 | dict( |
| 92 | type=step.type, |
| 93 | args=step.args, |
| 94 | result=step.result, |
| 95 | thought=step.thought, |
| 96 | state=int(step.state), |
| 97 | errmsg=step.errmsg, |
| 98 | valid=int(step.valid), |
| 99 | )) |
| 100 | |
| 101 | return answer, steps, inner_steps |
| 102 | |
| 103 | |
| 104 | FORCE_STOP_PROMPT_EN = ( |