Update AgentInitializerComponent to initialize a
Langchain Agent
This commit is contained in:
parent
61ad880990
commit
595006cb77
1 changed files with 4 additions and 3 deletions
|
|
@ -1,13 +1,14 @@
|
||||||
from typing import List
|
from typing import Callable, List, Union
|
||||||
|
|
||||||
from langchain.agents import AgentExecutor, AgentType, initialize_agent, types
|
from langchain.agents import AgentExecutor, AgentType, initialize_agent, types
|
||||||
|
|
||||||
from langflow import CustomComponent
|
from langflow import CustomComponent
|
||||||
from langflow.field_typing import BaseChatMemory, BaseLanguageModel, Tool
|
from langflow.field_typing import BaseChatMemory, BaseLanguageModel, Tool
|
||||||
|
|
||||||
|
|
||||||
class AgentInitializerComponent(CustomComponent):
|
class AgentInitializerComponent(CustomComponent):
|
||||||
display_name: str = "Agent Initializer"
|
display_name: str = "Agent Initializer"
|
||||||
description: str = f"Initialize an agent of type: {types.AGENT_TO_CLASS.keys()}"
|
description: str = "Initialize a Langchain Agent."
|
||||||
documentation: str = "https://python.langchain.com/docs/modules/agents/agent_types/"
|
documentation: str = "https://python.langchain.com/docs/modules/agents/agent_types/"
|
||||||
|
|
||||||
def build_config(self):
|
def build_config(self):
|
||||||
|
|
@ -23,7 +24,7 @@ class AgentInitializerComponent(CustomComponent):
|
||||||
|
|
||||||
def build(
|
def build(
|
||||||
self, agent: str, llm: BaseLanguageModel, memory: BaseChatMemory, tools: List[Tool], max_iterations: int
|
self, agent: str, llm: BaseLanguageModel, memory: BaseChatMemory, tools: List[Tool], max_iterations: int
|
||||||
) -> AgentExecutor:
|
) -> Union[AgentExecutor, Callable]:
|
||||||
agent = AgentType(agent)
|
agent = AgentType(agent)
|
||||||
return initialize_agent(
|
return initialize_agent(
|
||||||
tools=tools,
|
tools=tools,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue