langchain.agents.agent.LLMSingleActionAgent

class langchain.agents.agent.LLMSingleActionAgent(*, llm_chain: LLMChain, output_parser: AgentOutputParser, stop: List[str])[source]

Bases: BaseSingleActionAgent

Base class for single action agents.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

param llm_chain: langchain.chains.llm.LLMChain [Required]

LLMChain to use for agent.

param output_parser: langchain.agents.agent.AgentOutputParser [Required]

Output parser to use for agent.

param stop: List[str] [Required]

List of strings to stop on.

async aplan(intermediate_steps: List[Tuple[AgentAction, str]], callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None, **kwargs: Any) Union[AgentAction, AgentFinish][source]

Given input, decided what to do.

Parameters
  • intermediate_steps – Steps the LLM has taken to date, along with observations

  • callbacks – Callbacks to run.

  • **kwargs – User inputs.

Returns

Action specifying what tool to use.

dict(**kwargs: Any) Dict[source]

Return dictionary representation of agent.

classmethod from_llm_and_tools(llm: BaseLanguageModel, tools: Sequence[BaseTool], callback_manager: Optional[BaseCallbackManager] = None, **kwargs: Any) BaseSingleActionAgent
get_allowed_tools() Optional[List[str]]
plan(intermediate_steps: List[Tuple[AgentAction, str]], callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = None, **kwargs: Any) Union[AgentAction, AgentFinish][source]

Given input, decided what to do.

Parameters
  • intermediate_steps – Steps the LLM has taken to date, along with the observations.

  • callbacks – Callbacks to run.

  • **kwargs – User inputs.

Returns

Action specifying what tool to use.

return_stopped_response(early_stopping_method: str, intermediate_steps: List[Tuple[AgentAction, str]], **kwargs: Any) AgentFinish

Return response when agent has been stopped due to max iterations.

save(file_path: Union[Path, str]) None

Save the agent.

Parameters

file_path – Path to file to save the agent to.

Example: .. code-block:: python

# If working with agent executor agent.agent.save(file_path=”path/agent.yaml”)

tool_run_logging_kwargs() Dict[source]
property input_keys: List[str]

Return the input keys.

Returns

List of input keys.

property return_values: List[str]

Return values of the agent.

Examples using LLMSingleActionAgent