Source code for are.simulation.agents.default_agent.tools.action_executor
# Copyright (c) Meta Platforms, Inc. and affiliates.# All rights reserved.## This source code is licensed under the terms described in the LICENSE file in# the root directory of this source tree.fromabcimportabstractmethodfromdataclassesimportdataclassfromtypingimportAny,Callablefromare.simulation.agents.agent_logimportBaseAgentLog,FinalAnswerLogfromare.simulation.agents.default_agent.utils.logging_utilsimport(get_default_logger,get_parent_logger,)fromare.simulation.agents.llm.typesimportMMObservationfromare.simulation.exceptionsimportFormatError,InvalidActionAgentErrorfromare.simulation.toolsimportTool
[docs]defextract_action(self,llm_output:str,split_token:str)->AgentAction:try:split=llm_output.split(split_token)iflen(split)<2:raiseIndexError(f"Expected at least 2 parts after splitting by '{split_token}', got {len(split)}")rationale,action=(split[-2],split[-1],)exceptExceptionase:self.logger.error(e,exc_info=True)raiseInvalidActionAgentError(f"Error: No '{split_token}' token provided in your output.\nYour output:\n{llm_output}\n. Be sure to include an action, prefaced with '{split_token}'!\nException: {e}")iflen(split)>2:raiseFormatError(f"Found multiple actions in output {llm_output} - please provide only one thought and one action")returnAgentAction(rationale,action)