langchain.agents.xml.base.XMLAgent

class langchain.agents.xml.base.XMLAgent(*, tools: List[BaseTool], llm_chain: LLMChain)[source]

Bases: BaseSingleActionAgent

Agent that uses XML tags.

Parameters
  • tools – list of tools the agent can choose from

  • llm_chain – The LLMChain to call to predict the next action

Examples

from langchain.agents import XMLAgent
from langchain

tools = ...
model =

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]

Chain to use to predict action.

param tools: List[langchain.tools.base.BaseTool] [Required]

List of tools this agent has access to.

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

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]]
static get_default_output_parser() XMLAgentOutputParser[source]
static get_default_prompt() ChatPromptTemplate[source]
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 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
property return_values: List[str]

Return values of the agent.