agent with run flow components as tools #6939
Replies: 1 comment 2 replies
-
|
Hey there, @SudeeraDilshan! I'm here to help you out. If you have any questions or need assistance with anything, feel free to ask. To implement an agent in Python using a JSON file to configure run flow components as tools, you can use the
Here is a code snippet illustrating this process: from langflow.base.agents.agent import LCAgentComponent
from langflow.inputs import FileInput, HandleInput
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
class JsonAgentComponent(LCAgentComponent):
display_name = "JsonAgent"
description = "Construct a json agent from an LLM and tools."
name = "JsonAgent"
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:
path = Path(self.path)
if path.suffix in ("yaml", "yml"):
with path.open(encoding="utf-8") as file:
yaml_dict = yaml.load(file, Loader=yaml.FullLoader)
spec = JsonSpec(dict_=yaml_dict)
else:
spec = JsonSpec.from_file(path)
toolkit = JsonToolkit(spec=spec)
return create_json_agent(llm=self.llm, toolkit=toolkit, **self.get_agent_kwargs())This code sets up an agent that can be configured using a JSON or YAML file, where each component in the file represents a flow [1]. To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have an agent and I have connected run flow components as tools for the agent.each run flow component represent flow .How can I implement agent with python code by using json file related to the flow.
Beta Was this translation helpful? Give feedback.
All reactions