Agents
This Langflow feature is currently in public preview. Development is ongoing, and the features and functionality are subject to change. Langflow, and the use of such, is subject to the DataStax Preview Terms. |
Agent components are used to define the behavior and capabilities of AI agents in your flow. Agents can interact with APIs, databases, and other services, but can also use LLMs as a reasoning engine to decide which course to take in your flow.
CSV Agent
This component creates a CSV agent from a CSV file and LLM.
Parameters
Name | Type | Description |
---|---|---|
llm |
LanguageModel |
Language model to use for the agent |
path |
File |
Path to the CSV file |
agent_type |
String |
Type of agent to create (zero-shot-react-description, openai-functions, or openai-tools) |
Name | Type | Description |
---|---|---|
agent |
AgentExecutor |
CSV agent instance |
Component code
CSVAgent.py
from langchain_experimental.agents.agent_toolkits.csv.base import create_csv_agent
from langflow.base.agents.agent import LCAgentComponent
from langflow.field_typing import AgentExecutor
from langflow.inputs import HandleInput, FileInput, DropdownInput
class CSVAgentComponent(LCAgentComponent):
display_name = "CSVAgent"
description = "Construct a CSV agent from a CSV and tools."
documentation = "https://python.langchain.com/docs/modules/agents/toolkits/csv"
name = "CSVAgent"
inputs = LCAgentComponent._base_inputs + [
HandleInput(name="llm", display_name="Language Model", input_types=["LanguageModel"], required=True),
FileInput(name="path", display_name="File Path", file_types=["csv"], required=True),
DropdownInput(
name="agent_type",
display_name="Agent Type",
advanced=True,
options=["zero-shot-react-description", "openai-functions", "openai-tools"],
value="openai-tools",
),
]
def build_agent(self) -> AgentExecutor:
return create_csv_agent(llm=self.llm, path=self.path, agent_type=self.agent_type, **self.get_agent_kwargs())
CrewAI Agent
This component represents an Agent of CrewAI, allowing for the creation of specialized AI agents with defined roles, goals, and capabilities within a crew.
For more information, see the CrewAI documentation.
Parameters
Name | Display Name | Info |
---|---|---|
role |
Role |
The role of the agent |
goal |
Goal |
The objective of the agent |
backstory |
Backstory |
The backstory of the agent |
tools |
Tools |
Tools at agent’s disposal |
llm |
Language Model |
Language model that will run the agent |
memory |
Memory |
Whether the agent should have memory or not |
verbose |
Verbose |
Enables verbose output |
allow_delegation |
Allow Delegation |
Whether the agent is allowed to delegate tasks to other agents |
allow_code_execution |
Allow Code Execution |
Whether the agent is allowed to execute code |
kwargs |
kwargs |
Additional keyword arguments for the agent |
Name | Display Name | Info |
---|---|---|
output |
Agent |
The constructed CrewAI Agent object |
Component code
CrewAIAgent.py
from crewai import Agent # type: ignore
from langflow.custom import Component
from langflow.io import BoolInput, DictInput, HandleInput, MultilineInput, Output
class CrewAIAgentComponent(Component):
display_name = "CrewAI Agent"
description = "Represents an agent of CrewAI."
documentation: str = "https://docs.crewai.com/how-to/LLM-Connections/"
icon = "CrewAI"
inputs = [
MultilineInput(name="role", display_name="Role", info="The role of the agent."),
MultilineInput(name="goal", display_name="Goal", info="The objective of the agent."),
MultilineInput(name="backstory", display_name="Backstory", info="The backstory of the agent."),
HandleInput(
name="tools",
display_name="Tools",
input_types=["Tool"],
is_list=True,
info="Tools at agents disposal",
value=[],
),
HandleInput(
name="llm",
display_name="Language Model",
info="Language model that will run the agent.",
input_types=["LanguageModel"],
),
BoolInput(
name="memory",
display_name="Memory",
info="Whether the agent should have memory or not",
advanced=True,
value=True,
),
BoolInput(
name="verbose",
display_name="Verbose",
advanced=True,
value=False,
),
BoolInput(
name="allow_delegation",
display_name="Allow Delegation",
info="Whether the agent is allowed to delegate tasks to other agents.",
value=True,
),
BoolInput(
name="allow_code_execution",
display_name="Allow Code Execution",
info="Whether the agent is allowed to execute code.",
value=False,
advanced=True,
),
DictInput(
name="kwargs",
display_name="kwargs",
info="kwargs of agent.",
is_list=True,
advanced=True,
),
]
outputs = [
Output(display_name="Agent", name="output", method="build_output"),
]
def build_output(self) -> Agent:
kwargs = self.kwargs if self.kwargs else {}
agent = Agent(
role=self.role,
goal=self.goal,
backstory=self.backstory,
llm=self.llm,
verbose=self.verbose,
memory=self.memory,
tools=self.tools if self.tools else [],
allow_delegation=self.allow_delegation,
allow_code_execution=self.allow_code_execution,
**kwargs,
)
self.status = repr(agent)
return agent
Hierarchical Crew
This component represents a group of agents, managing how they should collaborate and the tasks they should perform in a hierarchical structure. This component allows for the creation of a crew with a manager overseeing the task execution.
For more information, see the CrewAI documentation.
Parameters
Name | Display Name | Info |
---|---|---|
agents |
Agents |
List of Agent objects representing the crew members |
tasks |
Tasks |
List of HierarchicalTask objects representing the tasks to be executed |
manager_llm |
Manager LLM |
Language model for the manager agent (optional) |
manager_agent |
Manager Agent |
Specific agent to act as the manager (optional) |
verbose |
Verbose |
Enables verbose output for detailed logging |
memory |
Memory |
Specifies the memory configuration for the crew |
use_cache |
Use Cache |
Enables caching of results |
max_rpm |
Max RPM |
Sets the maximum requests per minute |
share_crew |
Share Crew |
Determines if the crew information is shared among agents |
function_calling_llm |
Function Calling LLM |
Specifies the language model for function calling |
Name | Display Name | Info |
---|---|---|
crew |
Crew |
The constructed Crew object with hierarchical task execution |
Component code
HierarchicalCrew.py
from crewai import Crew, Process # type: ignore
from langflow.base.agents.crewai.crew import BaseCrewComponent
from langflow.io import HandleInput
class HierarchicalCrewComponent(BaseCrewComponent):
display_name: str = "Hierarchical Crew"
description: str = (
"Represents a group of agents, defining how they should collaborate and the tasks they should perform."
)
documentation: str = "https://docs.crewai.com/how-to/Hierarchical/"
icon = "CrewAI"
inputs = BaseCrewComponent._base_inputs + [
HandleInput(name="agents", display_name="Agents", input_types=["Agent"], is_list=True),
HandleInput(name="tasks", display_name="Tasks", input_types=["HierarchicalTask"], is_list=True),
HandleInput(name="manager_llm", display_name="Manager LLM", input_types=["LanguageModel"], required=False),
HandleInput(name="manager_agent", display_name="Manager Agent", input_types=["Agent"], required=False),
]
def build_crew(self) -> Crew:
tasks, agents = self.get_tasks_and_agents()
crew = Crew(
agents=agents,
tasks=tasks,
process=Process.hierarchical,
verbose=self.verbose,
memory=self.memory,
cache=self.use_cache,
max_rpm=self.max_rpm,
share_crew=self.share_crew,
function_calling_llm=self.function_calling_llm,
manager_agent=self.manager_agent,
manager_llm=self.manager_llm,
step_callback=self.get_step_callback(),
task_callback=self.get_task_callback(),
)
return crew
JSON Agent
This component creates a JSON agent from a JSON or YAML file and an LLM.
Parameters
Name | Type | Description |
---|---|---|
llm |
LanguageModel |
Language model to use for the agent |
path |
File |
Path to the JSON or YAML file |
Name | Type | Description |
---|---|---|
agent |
AgentExecutor |
JSON agent instance |
Component code
JsonAgent.py
from pathlib import Path
import yaml
from langchain.agents import AgentExecutor
from langchain_community.agent_toolkits import create_json_agent
from langchain_community.agent_toolkits.json.toolkit import JsonToolkit
from langchain_community.tools.json.tool import JsonSpec
from langflow.base.agents.agent import LCAgentComponent
from langflow.inputs import HandleInput, FileInput
class JsonAgentComponent(LCAgentComponent):
display_name = "JsonAgent"
description = "Construct a json agent from an LLM and tools."
name = "JsonAgent"
inputs = LCAgentComponent._base_inputs + [
HandleInput(name="llm", display_name="Language Model", input_types=["LanguageModel"], required=True),
FileInput(name="path", display_name="File Path", file_types=["json", "yaml", "yml"], required=True),
]
def build_agent(self) -> AgentExecutor:
if self.path.endswith("yaml") or self.path.endswith("yml"):
with open(self.path, "r") as file:
yaml_dict = yaml.load(file, Loader=yaml.FullLoader)
spec = JsonSpec(dict_=yaml_dict)
else:
spec = JsonSpec.from_file(Path(self.path))
toolkit = JsonToolkit(spec=spec)
return create_json_agent(llm=self.llm, toolkit=toolkit, **self.get_agent_kwargs())
OpenAI Tools Agent
This component creates an OpenAI Tools Agent using LangChain. For more information, see the LangChain documentation.
Parameters
Name | Type | Description |
---|---|---|
llm |
LanguageModel |
Language model to use for the agent (must be tool-enabled) |
system_prompt |
String |
System prompt for the agent |
user_prompt |
String |
User prompt template (must contain 'input' key) |
chat_history |
List[Data] |
Optional chat history for the agent |
tools |
List[Tool] |
List of tools available to the agent |
Name | Type | Description |
---|---|---|
agent |
AgentExecutor |
OpenAI Tools Agent instance |
Component code
OpenAIToolsAgent.py
from typing import Optional, List
from langchain.agents import create_openai_tools_agent
from langchain_core.prompts import ChatPromptTemplate, PromptTemplate, HumanMessagePromptTemplate
from langflow.base.agents.agent import LCToolsAgentComponent
from langflow.inputs import MultilineInput
from langflow.inputs.inputs import HandleInput, DataInput
from langflow.schema import Data
class OpenAIToolsAgentComponent(LCToolsAgentComponent):
display_name: str = "OpenAI Tools Agent"
description: str = "Agent that uses tools via openai-tools."
icon = "LangChain"
beta = True
name = "OpenAIToolsAgent"
inputs = LCToolsAgentComponent._base_inputs + [
HandleInput(
name="llm",
display_name="Language Model",
input_types=["LanguageModel", "ToolEnabledLanguageModel"],
required=True,
),
MultilineInput(
name="system_prompt",
display_name="System Prompt",
info="System prompt for the agent.",
value="You are a helpful assistant",
),
MultilineInput(
name="user_prompt", display_name="Prompt", info="This prompt must contain 'input' key.", value="{input}"
),
DataInput(name="chat_history", display_name="Chat History", is_list=True, advanced=True),
]
def get_chat_history_data(self) -> Optional[List[Data]]:
return self.chat_history
def create_agent_runnable(self):
if "input" not in self.user_prompt:
raise ValueError("Prompt must contain 'input' key.")
messages = [
("system", self.system_prompt),
("placeholder", "{chat_history}"),
HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=["input"], template=self.user_prompt)),
("placeholder", "{agent_scratchpad}"),
]
prompt = ChatPromptTemplate.from_messages(messages)
return create_openai_tools_agent(self.llm, self.tools, prompt)
OpenAPI Agent
This component creates an OpenAPI Agent to interact with APIs defined by OpenAPI specifications. For more information, see the LangChain documentation on OpenAPI Agents.
Parameters
Name | Type | Description |
---|---|---|
llm |
LanguageModel |
Language model to use for the agent |
path |
File |
Path to the OpenAPI specification file (JSON or YAML) |
allow_dangerous_requests |
Boolean |
Whether to allow potentially dangerous API requests |
Name | Type | Description |
---|---|---|
agent |
AgentExecutor |
OpenAPI Agent instance |
Component code
OpenAPIAgent.py
from pathlib import Path
import yaml
from langchain.agents import AgentExecutor
from langchain_community.agent_toolkits import create_openapi_agent
from langchain_community.tools.json.tool import JsonSpec
from langchain_community.agent_toolkits.openapi.toolkit import OpenAPIToolkit
from langflow.base.agents.agent import LCAgentComponent
from langflow.inputs import BoolInput, HandleInput, FileInput
from langchain_community.utilities.requests import TextRequestsWrapper
class OpenAPIAgentComponent(LCAgentComponent):
display_name = "OpenAPI Agent"
description = "Agent to interact with OpenAPI API."
name = "OpenAPIAgent"
inputs = LCAgentComponent._base_inputs + [
HandleInput(name="llm", display_name="Language Model", input_types=["LanguageModel"], required=True),
FileInput(name="path", display_name="File Path", file_types=["json", "yaml", "yml"], required=True),
BoolInput(name="allow_dangerous_requests", display_name="Allow Dangerous Requests", value=False, required=True),
]
def build_agent(self) -> AgentExecutor:
if self.path.endswith("yaml") or self.path.endswith("yml"):
with open(self.path, "r") as file:
yaml_dict = yaml.load(file, Loader=yaml.FullLoader)
spec = JsonSpec(dict_=yaml_dict)
else:
spec = JsonSpec.from_file(Path(self.path))
requests_wrapper = TextRequestsWrapper()
toolkit = OpenAPIToolkit.from_llm(
llm=self.llm,
json_spec=spec,
requests_wrapper=requests_wrapper,
allow_dangerous_requests=self.allow_dangerous_requests,
)
agent_args = self.get_agent_kwargs()
# This is bit weird - generally other create_*_agent functions have max_iterations in the
# `agent_executor_kwargs`, but openai has this parameter passed directly.
agent_args["max_iterations"] = agent_args["agent_executor_kwargs"]["max_iterations"]
del agent_args["agent_executor_kwargs"]["max_iterations"]
return create_openapi_agent(llm=self.llm, toolkit=toolkit, **agent_args)
SQL Agent
This component creates a SQL Agent to interact with SQL databases.
Parameters
Name | Type | Description |
---|---|---|
llm |
LanguageModel |
Language model to use for the agent |
database_uri |
String |
URI of the SQL database to connect to |
extra_tools |
List[Tool] |
Additional tools to provide to the agent (optional) |
Name | Type | Description |
---|---|---|
agent |
AgentExecutor |
SQL Agent instance |
Component code
SQLAgent.py
from langchain.agents import AgentExecutor
from langchain_community.agent_toolkits import SQLDatabaseToolkit
from langchain_community.agent_toolkits.sql.base import create_sql_agent
from langchain_community.utilities import SQLDatabase
from langflow.base.agents.agent import LCAgentComponent
from langflow.inputs import MessageTextInput, HandleInput
class SQLAgentComponent(LCAgentComponent):
display_name = "SQLAgent"
description = "Construct an SQL agent from an LLM and tools."
name = "SQLAgent"
inputs = LCAgentComponent._base_inputs + [
HandleInput(name="llm", display_name="Language Model", input_types=["LanguageModel"], required=True),
MessageTextInput(name="database_uri", display_name="Database URI", required=True),
HandleInput(
name="extra_tools",
display_name="Extra Tools",
input_types=["Tool", "BaseTool"],
is_list=True,
advanced=True,
),
]
def build_agent(self) -> AgentExecutor:
db = SQLDatabase.from_uri(self.database_uri)
toolkit = SQLDatabaseToolkit(db=db, llm=self.llm)
agent_args = self.get_agent_kwargs()
agent_args["max_iterations"] = agent_args["agent_executor_kwargs"]["max_iterations"]
del agent_args["agent_executor_kwargs"]["max_iterations"]
return create_sql_agent(llm=self.llm, toolkit=toolkit, extra_tools=self.extra_tools or [], **agent_args)
Sequential Crew
This component represents a group of agents with tasks that are executed sequentially. This component allows for the creation of a crew that performs tasks in a specific order.
For more information, see the CrewAI documentation.
Parameters
Name | Display Name | Info |
---|---|---|
tasks |
Tasks |
List of SequentialTask objects representing the tasks to be executed |
verbose |
Verbose |
Enables verbose output for detailed logging |
memory |
Memory |
Specifies the memory configuration for the crew |
use_cache |
Use Cache |
Enables caching of results |
max_rpm |
Max RPM |
Sets the maximum requests per minute |
share_crew |
Share Crew |
Determines if the crew information is shared among agents |
function_calling_llm |
Function Calling LLM |
Specifies the language model for function calling |
Name | Display Name | Info |
---|---|---|
crew |
Crew |
The constructed Crew object with sequential task execution |
Component code
SequentialCrew.py
from crewai import Agent, Crew, Process, Task # type: ignore
from langflow.base.agents.crewai.crew import BaseCrewComponent
from langflow.io import HandleInput
from langflow.schema.message import Message
class SequentialCrewComponent(BaseCrewComponent):
display_name: str = "Sequential Crew"
description: str = "Represents a group of agents with tasks that are executed sequentially."
documentation: str = "https://docs.crewai.com/how-to/Sequential/"
icon = "CrewAI"
inputs = BaseCrewComponent._base_inputs + [
HandleInput(name="tasks", display_name="Tasks", input_types=["SequentialTask"], is_list=True),
]
def get_tasks_and_agents(self) -> tuple[list[Task], list[Agent]]:
return self.tasks, [task.agent for task in self.tasks]
def build_crew(self) -> Message:
tasks, agents = self.get_tasks_and_agents()
crew = Crew(
agents=agents,
tasks=tasks,
process=Process.sequential,
verbose=self.verbose,
memory=self.memory,
cache=self.use_cache,
max_rpm=self.max_rpm,
share_crew=self.share_crew,
function_calling_llm=self.function_calling_llm,
step_callback=self.get_step_callback(),
task_callback=self.get_task_callback(),
)
return crew
Sequential task agent
This component creates a CrewAI Task and its associated Agent, allowing for the definition of sequential tasks with specific agent roles and capabilities.
For more information, see the CrewAI documentation.
Parameters
Name | Display Name | Info |
---|---|---|
role |
Role |
The role of the agent |
goal |
Goal |
The objective of the agent |
backstory |
Backstory |
The backstory of the agent |
tools |
Tools |
Tools at agent’s disposal |
llm |
Language Model |
Language model that will run the agent |
memory |
Memory |
Whether the agent should have memory or not |
verbose |
Verbose |
Enables verbose output |
allow_delegation |
Allow Delegation |
Whether the agent is allowed to delegate tasks to other agents |
allow_code_execution |
Allow Code Execution |
Whether the agent is allowed to execute code |
agent_kwargs |
Agent kwargs |
Additional kwargs for the agent |
task_description |
Task Description |
Descriptive text detailing task’s purpose and execution |
expected_output |
Expected Task Output |
Clear definition of expected task outcome |
async_execution |
Async Execution |
Boolean flag indicating asynchronous task execution |
previous_task |
Previous Task |
The previous task in the sequence (for chaining) |
Name | Display Name | Info |
---|---|---|
task_output |
Sequential Task |
List of SequentialTask objects representing the created task(s) |
Component code
SequentialTaskAgent.py
from crewai import Agent, Task
from langflow.base.agents.crewai.tasks import SequentialTask
from langflow.custom import Component
from langflow.io import BoolInput, DictInput, HandleInput, MultilineInput, Output
class SequentialTaskAgentComponent(Component):
display_name = "Sequential Task Agent"
description = "Creates a CrewAI Task and its associated Agent."
documentation = "https://docs.crewai.com/how-to/LLM-Connections/"
icon = "CrewAI"
inputs = [
# Agent inputs
MultilineInput(name="role", display_name="Role", info="The role of the agent."),
MultilineInput(name="goal", display_name="Goal", info="The objective of the agent."),
MultilineInput(
name="backstory",
display_name="Backstory",
info="The backstory of the agent.",
),
HandleInput(
name="tools",
display_name="Tools",
input_types=["Tool"],
is_list=True,
info="Tools at agent's disposal",
value=[],
),
HandleInput(
name="llm",
display_name="Language Model",
info="Language model that will run the agent.",
input_types=["LanguageModel"],
),
BoolInput(
name="memory",
display_name="Memory",
info="Whether the agent should have memory or not",
advanced=True,
value=True,
),
BoolInput(
name="verbose",
display_name="Verbose",
advanced=True,
value=True,
),
BoolInput(
name="allow_delegation",
display_name="Allow Delegation",
info="Whether the agent is allowed to delegate tasks to other agents.",
value=False,
advanced=True,
),
BoolInput(
name="allow_code_execution",
display_name="Allow Code Execution",
info="Whether the agent is allowed to execute code.",
value=False,
advanced=True,
),
DictInput(
name="agent_kwargs",
display_name="Agent kwargs",
info="Additional kwargs for the agent.",
is_list=True,
advanced=True,
),
# Task inputs
MultilineInput(
name="task_description",
display_name="Task Description",
info="Descriptive text detailing task's purpose and execution.",
),
MultilineInput(
name="expected_output",
display_name="Expected Task Output",
info="Clear definition of expected task outcome.",
),
BoolInput(
name="async_execution",
display_name="Async Execution",
value=False,
advanced=True,
info="Boolean flag indicating asynchronous task execution.",
),
# Chaining input
HandleInput(
name="previous_task",
display_name="Previous Task",
input_types=["SequentialTask"],
info="The previous task in the sequence (for chaining).",
required=False,
),
]
outputs = [
Output(
display_name="Sequential Task",
name="task_output",
method="build_agent_and_task",
),
]
def build_agent_and_task(self) -> list[SequentialTask]:
# Build the agent
agent_kwargs = self.agent_kwargs or {}
agent = Agent(
role=self.role,
goal=self.goal,
backstory=self.backstory,
llm=self.llm,
verbose=self.verbose,
memory=self.memory,
tools=self.tools if self.tools else [],
allow_delegation=self.allow_delegation,
allow_code_execution=self.allow_code_execution,
**agent_kwargs,
)
# Build the task
task = Task(
description=self.task_description,
expected_output=self.expected_output,
agent=agent,
async_execution=self.async_execution,
)
# If there's a previous task, create a list of tasks
if self.previous_task:
if isinstance(self.previous_task, list):
tasks = self.previous_task + [task]
else:
tasks = [self.previous_task, task]
else:
tasks = [task]
self.status = f"Agent: {repr(agent)}\nTask: {repr(task)}"
return tasks
Tool Calling Agent
This component creates a Tool Calling Agent using LangChain.
Parameters
Name | Type | Description |
---|---|---|
llm |
LanguageModel |
Language model to use for the agent |
system_prompt |
String |
System prompt for the agent |
user_prompt |
String |
User prompt template (must contain 'input' key) |
chat_history |
List[Data] |
Optional chat history for the agent |
tools |
List[Tool] |
List of tools available to the agent |
Name | Type | Description |
---|---|---|
agent |
AgentExecutor |
Tool Calling Agent instance |
Component code
ToolCallingAgent.py
from typing import Optional, List
from langchain.agents import create_tool_calling_agent
from langchain_core.prompts import ChatPromptTemplate, PromptTemplate, HumanMessagePromptTemplate
from langflow.base.agents.agent import LCToolsAgentComponent
from langflow.inputs import MultilineInput
from langflow.inputs.inputs import HandleInput, DataInput
from langflow.schema import Data
class ToolCallingAgentComponent(LCToolsAgentComponent):
display_name: str = "Tool Calling Agent"
description: str = "Agent that uses tools"
icon = "LangChain"
beta = True
name = "ToolCallingAgent"
inputs = LCToolsAgentComponent._base_inputs + [
HandleInput(name="llm", display_name="Language Model", input_types=["LanguageModel"], required=True),
MultilineInput(
name="system_prompt",
display_name="System Prompt",
info="System prompt for the agent.",
value="You are a helpful assistant",
),
MultilineInput(
name="user_prompt", display_name="Prompt", info="This prompt must contain 'input' key.", value="{input}"
),
DataInput(name="chat_history", display_name="Chat History", is_list=True, advanced=True),
]
def get_chat_history_data(self) -> Optional[List[Data]]:
return self.chat_history
def create_agent_runnable(self):
if "input" not in self.user_prompt:
raise ValueError("Prompt must contain 'input' key.")
messages = [
("system", self.system_prompt),
("placeholder", "{chat_history}"),
HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=["input"], template=self.user_prompt)),
("placeholder", "{agent_scratchpad}"),
]
prompt = ChatPromptTemplate.from_messages(messages)
return create_tool_calling_agent(self.llm, self.tools, prompt)
Vector Store Agent
This component creates a Vector Store Agent using LangChain.
Parameters
Name | Type | Description |
---|---|---|
llm |
LanguageModel |
Language model to use for the agent |
vectorstore |
VectorStoreInfo |
Vector store information for the agent to use |
Name | Type | Description |
---|---|---|
agent |
AgentExecutor |
Vector Store Agent instance |
Component code
VectorStoreAgent.py
from langchain.agents import AgentExecutor, create_vectorstore_agent
from langchain.agents.agent_toolkits.vectorstore.toolkit import VectorStoreToolkit
from langflow.base.agents.agent import LCAgentComponent
from langflow.inputs import HandleInput
class VectorStoreAgentComponent(LCAgentComponent):
display_name = "VectorStoreAgent"
description = "Construct an agent from a Vector Store."
name = "VectorStoreAgent"
inputs = LCAgentComponent._base_inputs + [
HandleInput(name="llm", display_name="Language Model", input_types=["LanguageModel"], required=True),
HandleInput(name="vectorstore", display_name="Vector Store", input_types=["VectorStoreInfo"], required=True),
]
def build_agent(self) -> AgentExecutor:
toolkit = VectorStoreToolkit(vectorstore_info=self.vectorstore, llm=self.llm)
return create_vectorstore_agent(llm=self.llm, toolkit=toolkit, **self.get_agent_kwargs())
Vector Store Router Agent
This component creates a Vector Store Router Agent using LangChain.
Parameters
Name | Type | Description |
---|---|---|
llm |
LanguageModel |
Language model to use for the agent |
vectorstores |
List[VectorStoreInfo] |
List of vector store information for the agent to route between |
Name | Type | Description |
---|---|---|
agent |
AgentExecutor |
Vector Store Router Agent instance |
Component code
VectorStoreRouterAgent.py
from langchain.agents import create_vectorstore_router_agent
from langchain.agents.agent_toolkits.vectorstore.toolkit import VectorStoreRouterToolkit
from langflow.base.agents.agent import LCAgentComponent
from langchain.agents import AgentExecutor
from langflow.inputs import HandleInput
class VectorStoreRouterAgentComponent(LCAgentComponent):
display_name = "VectorStoreRouterAgent"
description = "Construct an agent from a Vector Store Router."
name = "VectorStoreRouterAgent"
inputs = LCAgentComponent._base_inputs + [
HandleInput(name="llm", display_name="Language Model", input_types=["LanguageModel"], required=True),
HandleInput(
name="vectorstores",
display_name="Vector Stores",
input_types=["VectorStoreInfo"],
is_list=True,
required=True,
),
]
def build_agent(self) -> AgentExecutor:
toolkit = VectorStoreRouterToolkit(vectorstores=self.vectorstores, llm=self.llm)
return create_vectorstore_router_agent(llm=self.llm, toolkit=toolkit, **self.get_agent_kwargs())
XML Agent
This component creates an XML Agent using LangChain. The agent uses XML formatting for tool instructions to the Language Model.
Parameters
Name | Type | Description |
---|---|---|
llm |
LanguageModel |
Language model to use for the agent |
user_prompt |
String |
Custom prompt template for the agent (includes XML formatting instructions) |
tools |
List[Tool] |
List of tools available to the agent |
Name | Type | Description |
---|---|---|
agent |
AgentExecutor |
XML Agent instance |
Component code
XMLAgent.py
from langchain.agents import create_xml_agent
from langchain_core.prompts import ChatPromptTemplate, PromptTemplate, HumanMessagePromptTemplate
from langflow.base.agents.agent import LCToolsAgentComponent
from langflow.inputs import MultilineInput
from langflow.inputs.inputs import HandleInput
class XMLAgentComponent(LCToolsAgentComponent):
display_name: str = "XML Agent"
description: str = "Agent that uses tools formatting instructions as xml to the Language Model."
icon = "LangChain"
beta = True
name = "XMLAgent"
inputs = LCToolsAgentComponent._base_inputs + [
HandleInput(name="llm", display_name="Language Model", input_types=["LanguageModel"], required=True),
MultilineInput(
name="user_prompt",
display_name="Prompt",
value="""
You are a helpful assistant. Help the user answer any questions.
You have access to the following tools:
{tools}
In order to use a tool, you can use <tool></tool> and <tool_input></tool_input> tags. You will then get back a response in the form <observation></observation>
For example, if you have a tool called 'search' that could run a google search, in order to search for the weather in SF you would respond:
<tool>search</tool><tool_input>weather in SF</tool_input>
<observation>64 degrees</observation>
When you are done, respond with a final answer between <final_answer></final_answer>. For example:
<final_answer>The weather in SF is 64 degrees</final_answer>
Begin!
Question: {input}
{agent_scratchpad}
""",
),
]
def create_agent_runnable(self):
messages = [
HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=["input"], template=self.user_prompt))
]
prompt = ChatPromptTemplate.from_messages(messages)
return create_xml_agent(self.llm, self.tools, prompt)