mirror of
				https://github.com/hwchase17/langchain.git
				synced 2025-11-03 17:54:10 +00:00 
			
		
		
		
	Add a StdIn "Interaction" Tool (#1193)
Lets a chain prompt the user for more input as a part of its execution.
This commit is contained in:
		
							
								
								
									
										1
									
								
								langchain/tools/interaction/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								langchain/tools/interaction/__init__.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					"""Tools for interacting with the user."""
 | 
				
			||||||
							
								
								
									
										22
									
								
								langchain/tools/interaction/tool.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								langchain/tools/interaction/tool.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
				
			|||||||
 | 
					"""Tools for interacting with the user."""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from langchain.tools.base import BaseTool
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class StdInInquireTool(BaseTool):
 | 
				
			||||||
 | 
					    """Tool for asking the user for input."""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    name: str = "Inquire"
 | 
				
			||||||
 | 
					    description: str = (
 | 
				
			||||||
 | 
					        "useful if you do not have enough information to"
 | 
				
			||||||
 | 
					        " effectively use other tools. Input is best as a clarifying"
 | 
				
			||||||
 | 
					        " question (to disambiguate) or a request for more context."
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def _run(self, prompt: str) -> str:
 | 
				
			||||||
 | 
					        """Prompt the user for more input."""
 | 
				
			||||||
 | 
					        return input(f"\n{prompt}")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    async def _arun(self, query: str) -> str:
 | 
				
			||||||
 | 
					        raise NotImplementedError(f"{self.__class__.__name__} does not support async")
 | 
				
			||||||
		Reference in New Issue
	
	Block a user