Information
Search Search ⌘K Agents Create a problem-solving agent 1 from langflow.custom import Component from langflow.custom import Component 2 from langflow.io import MessageTextInput, Output from langflow.io import MessageTextInput, Output 3 from langflow.schema import Data from langflow.schema import Data 4 import re import re 5 6 class TextAnalyzerComponent(Component): class TextAnalyzerComponent ( Component ): 7 display_name = "Text Analyzer" display_name = "Text Analyzer" 8 description = "Analyzes and transforms input text." description = "Analyzes and transforms input text." 9 documentation: str = "http://docs.langflow.org/components/custom" documentation: str = "http://docs.langflow.org/components/custom" 10 icon = "chart-bar" icon = "chart-bar" 11 name = "TextAnalyzerComponent" name = "TextAnalyzerComponent" 12 13 inputs = [ inputs = [ 14 MessageTextInput( MessageTextInput( 15 name="input_text", name = "input_text" , 16 display_name="Input Text", display_name = "Input Text" , 17 info="Enter text to analyze", info = "Enter text to analyze" , 18 value="Hello, World!", value = "Hello, World!" , 19 tool_mode=True, tool_mode = True , 20 ), ), 21 ] ] 22 23 outputs = [ outputs = [ 24 Output(display_name="Analysis Result", name="output", method="analyze_text"), Output( display_name = "Analysis Result" , name = "output" , method = "analyze_text" ), 25 ] ] 26 27 def analyze_text(self) -> Data: def analyze_text (self) -> Data: 28 text = self.input_text text = self .input_text 29 30 # Perform text analysis # Perform text analysis 31 word_count = len(text.split()) word_count = len (text.split()) 32 char_count = len(text) char_count = len (text) 33 sentence_count = len(re.findall(r'\w+[.!?]', text)) sentence_count = len (re.findall( r ' \w + [.!?] ' , text)) 34 35 # Transform text # Transform text 36 reversed_text = text[::-1] reversed_text = text[:: - 1 ] 37 uppercase_text = text.upper() uppercase_text = text.upper() 38 39 analysis_result = { analysis_result = { 40 "original_text": text, "original_text" : text, 41 "word_count": word_count, "word_count" : word_count, 42 "character_count": char_count, "character_count" : char_count, 43 "sentence_count": sentence_count, "sentence_count" : sentence_count, 44 "reversed_text": reversed_text, "reversed_text" : reversed_text, 45 "uppercase_text": uppercase_text "uppercase_text" : uppercase_text 46 } } 47 48 data = Data(value=analysis_result) data = Data( value = analysis_result) 49 self.status = data self .status = data 50 return data return data 1 I have access to several tools that assist me in answering your questions, including: I have access to several tools that assist me in answering your questions, including: 2 Search API: This allows me to search for recent information or results on the web. Search API: This allows me to search for recent information or results on the web. 3 HTTP Requests: I can make HTTP requests to various URLs to retrieve data or interact with APIs. HTTP Requests: I can make HTTP requests to various URLs to retrieve data or interact with APIs. 4 Calculator: I can evaluate basic arithmetic expressions. Calculator: I can evaluate basic arithmetic expressions. 5 Text Analyzer: I can analyze and transform input text. Text Analyzer: I can analyze and transform input text. 6 Current Date and Time: I can retrieve the current date and time in various time zones. Current Date and Time: I can retrieve the current date and time in various time zones. 1 inputs = [ inputs = [ 2 MessageTextInput( MessageTextInput( 3 name="input_text", name = "input_text" , 4 display_name="Input Text", display_name = "Input Text" , 5 info="Enter text to analyze", info = "Enter text to analyze" , 6 value="Hello, World!", value = "Hello, World!" , 7 tool_mode=True, tool_mode = True , 8 ), ), 9 ] ] Developing agents in Langchain is complex. The AgentComponent is a component for easily creating an AI agent capable of analyzing tasks using tools you provide. The component contains all of the elements you'll need for creating an agent. Instead of managing LLM models and providers, pick your model and enter your API key. Instead of connecting a Prompt component, enter instructions in the component's Agent Instruction fields. Learn how to build a flow starting with the Tool calling agent component, and see how it can help you solve problems. Create a problem-solving agent in Langflow, starting with the Tool calling agent. This basic flow enables you to chat with the agent with the Playground after you've connected some Tools. Your agent now has tools for performing a web search, doing basic math, and performing API requests. You can solve many problems with just these capabilities. See what problems you can solve with this flow. As your problem becomes more specialized, add a tool. For example, the math agent tutorial project adds a Python REPL component to solve math problems that are too challenging for the calculator. To edit a tool's metadata, click the Edit Tools button in the tool to modify its name or description metadata. These fields help connected agents understand how to use the tool, without having to modify the agent's prompt instructions. For example, the URL component has three tools available when Tool Mode is enabled. A connected agent will have a clear idea of each tool's capabilities based on the name and description metadata. If you think the agent is using a tool incorrectly, edit a tool's metadata to help it understand the tool better. Tool names and descriptions can be edited, but the default tool identifiers cannot be changed. If you want to change the tool identifier, create a custom component. To see which tools the agent is using and how it's using them, ask the agent, What tools are you using to answer my questions? The agent component itself also supports Tool Mode for creating multi-agent flows. Add an agent to your problem-solving flow that uses a different OpenAI model for more specialized problem solving. An agent can use custom components as tools. To add a custom component to the problem-solving agent flow, click New Custom Component. Add custom Python code to the custom component.Here's an example text analyzer for sentiment analysis. If the component you want to use as a tool doesn't have a Tool Mode button, add tool_mode=True to one of the component's inputs, and connect the new Toolset output to the agent's Tools input. Langflow supports Tool Mode for the following data types: For example, the components as tools example above adds tool_mode=True to the MessageTextInput input so the custom component can be used as a tool. An agent can use flows that are saved in your workspace as tools with the Run flow component.