HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/langchain/agents/react/__pycache__/base.cpython-310.pyc
o

���g��@s^dZddlmZddlmZmZmZmZmZddl	m
Z
ddlmZddl
mZddlmZddlmZmZdd	lmZdd
lmZddlmZmZmZddlmZdd
lmZddl m!Z!ddl"m#Z#ddl$m%Z%errddl&m'Z'e
dedd�Gdd�de��Z(e
dedd�Gdd�d��Z)e
dedd�Gdd�de(��Z*e
dedd�Gdd�de��Z+dS)zPChain that implements the ReAct paper from https://arxiv.org/pdf/2210.03629.pdf.�)�annotations)�
TYPE_CHECKING�Any�List�Optional�Sequence)�
deprecated)�Document)�BaseLanguageModel)�BasePromptTemplate)�BaseTool�Tool)�Field)�AGENT_DEPRECATION_WARNING)�Agent�
AgentExecutor�AgentOutputParser)�	AgentType��ReActOutputParser��TEXTWORLD_PROMPT��WIKI_PROMPT)�validate_tools_single_input)�Docstorez0.1.0z1.0)�message�removalcs�eZdZUdZeed�Zded<eddd	��Z	e
ddd��Zeddd��Zed�fdd��Z
e
ddd��Ze
d dd��Ze
ddd��Z�ZS)!�ReActDocstoreAgentzAgent for the ReAct chain.)�default_factoryr�
output_parser�kwargsr�returncKst�S)Nr)�clsr!�r$�F/usr/local/lib/python3.10/dist-packages/langchain/agents/react/base.py�_get_default_output_parser$�z-ReActDocstoreAgent._get_default_output_parser�strcCstjS)z#Return Identifier of an agent type.)r�REACT_DOCSTORE��selfr$r$r%�_agent_type(szReActDocstoreAgent._agent_type�tools�Sequence[BaseTool]rcC�tS�zReturn default prompt.r�r#r-r$r$r%�
create_prompt-�z ReActDocstoreAgent.create_prompt�Nonecs^t|j|�t��|�t|�dkrtd|����dd�|D�}|ddhkr-td|����dS)N�z-Exactly two tools must be specified, but got cS�h|]}|j�qSr$��name��.0�toolr$r$r%�	<setcomp>8�z5ReActDocstoreAgent._validate_tools.<locals>.<setcomp>�Lookup�Searchz,Tool names should be Lookup and Search, got �r�__name__�super�_validate_tools�len�
ValueError�r#r-�
tool_names��	__class__r$r%rC2s��z"ReActDocstoreAgent._validate_toolscC�dS)z&Prefix to append the observation with.z
Observation: r$r*r$r$r%�observation_prefix>r3z%ReActDocstoreAgent.observation_prefix�	List[str]cCsdgS)Nz
Observation:r$r*r$r$r%�_stopCr'zReActDocstoreAgent._stopcCrJ)z#Prefix to append the LLM call with.zThought:r$r*r$r$r%�
llm_prefixGr3zReActDocstoreAgent.llm_prefix)r!rr"r�r"r(�r-r.r"r�r-r.r"r4�r"rL)rA�
__module__�__qualname__�__doc__rrr �__annotations__�classmethodr&�propertyr,r2rCrKrMrN�
__classcell__r$r$rHr%rs"
rc@sJeZdZdZddd�Zdd	d
�Zddd�Zedd
d��Zeddd��Z	dS)�DocstoreExplorerz5Class to assist with exploration of a document store.�docstorercCs||_d|_d|_d|_dS)z=Initialize with a docstore, and set initial document to None.N�r)r[�document�
lookup_str�lookup_index)r+r[r$r$r%�__init__Us
zDocstoreExplorer.__init__�termr(r"cCs,|j�|�}t|t�r||_|jSd|_|S)z5Search for a term in the docstore, and if found save.N)r[�search�
isinstancer	r]�_summary)r+ra�resultr$r$r%rb\s
zDocstoreExplorer.searchcs��jdur	td��|���jkr|���_d�_n�jd7_�fdd��jD�}t|�dkr2dS�jt|�kr;dSd	�jd�d
t|��d�}|�d|�j��S)
z%Lookup a term in document (if saved).Nz/Cannot lookup without a successful search firstr�csg|]}�j|��vr|�qSr$)r^�lower)r:�pr*r$r%�
<listcomp>osz+DocstoreExplorer.lookup.<locals>.<listcomp>z
No ResultszNo More Resultsz(Result �/�)� )r]rErgr^r_�_paragraphsrD)r+ra�lookups�
result_prefixr$r*r%�lookupfs

zDocstoreExplorer.lookupcCs
|jdS)Nr)rmr*r$r$r%rdxs
zDocstoreExplorer._summaryrLcCs |jdur	td��|jj�d�S)Nz(Cannot get paragraphs without a documentz

)r]rE�page_content�splitr*r$r$r%rm|s
zDocstoreExplorer._paragraphsN)r[r)rar(r"r(rOrR)
rArSrTrUr`rbrprXrdrmr$r$r$r%rZMs



rZcs4eZdZdZeddd��Zed�fd	d
��Z�ZS)
�ReActTextWorldAgentz$Agent for the ReAct TextWorld chain.r-r.r"rcCr/r0rr1r$r$r%r2�r3z!ReActTextWorldAgent.create_promptr4cs\t|j|�t��|�t|�dkrtd|����dd�|D�}|dhkr,td|����dS)Nrfz,Exactly one tool must be specified, but got cSr6r$r7r9r$r$r%r<�r=z6ReActTextWorldAgent._validate_tools.<locals>.<setcomp>�PlayzTool name should be Play, got r@rFrHr$r%rC�s
�z#ReActTextWorldAgent._validate_toolsrPrQ)rArSrTrUrWr2rCrYr$r$rHr%rs�srscs"eZdZdZd
�fdd	�Z�ZS)�
ReActChainz3[Deprecated] Chain that implements the ReAct paper.�llmr
r[rr!rcsPt|�}td|jdd�td|jdd�g}t�||�}t�jd||d�|��dS)	z'Initialize with the LLM and a docstore.r?z"Search for a term in the docstore.)r8�func�descriptionr>zLookup a term in the docstore.)�agentr-Nr$)rZr
rbrpr�from_llm_and_toolsrBr`)r+rvr[r!�docstore_explorerr-ryrHr$r%r`�s���zReActChain.__init__)rvr
r[rr!r)rArSrTrUr`rYr$r$rHr%ru�sruN),rU�
__future__r�typingrrrrr�langchain_core._apir�langchain_core.documentsr	�langchain_core.language_modelsr
�langchain_core.promptsr�langchain_core.toolsrr
�pydanticr�langchain._api.deprecationr�langchain.agents.agentrrr�langchain.agents.agent_typesr�$langchain.agents.react.output_parserr�'langchain.agents.react.textworld_promptr�"langchain.agents.react.wiki_promptr�langchain.agents.utilsr�!langchain_community.docstore.baserrrZrsrur$r$r$r%�<module>sT�.�1��