-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JSON for Tool calling agent that invokes multiple Flows as Tool #2112
Comments
To structure the JSON for a tool-calling agent that invokes multiple flows, ensure that the JSON includes the necessary configuration parameters such as {
"llm": {
"display_name": "LLM",
"type": "BaseLanguageModel",
"value": "your_llm_model"
},
"tools": [
{
"display_name": "Tool1",
"type": "Tool",
"value": "your_tool_1"
},
{
"display_name": "Tool2",
"type": "Tool",
"value": "your_tool_2"
}
],
"user_prompt": {
"display_name": "Prompt",
"multiline": true,
"info": "This prompt must contain 'input' key.",
"value": "{input}"
},
"handle_parsing_errors": {
"display_name": "Handle Parsing Errors",
"info": "If True, the agent will handle parsing errors. If False, the agent will raise an error.",
"advanced": true,
"value": true
},
"memory": {
"display_name": "Memory",
"info": "Memory to use for the agent.",
"value": "your_memory_configuration"
},
"input_value": {
"display_name": "Inputs",
"info": "Input text to pass to the agent.",
"value": "your_input_text"
}
} To troubleshoot the error you are encountering, ensure that the if "input" not in user_prompt:
raise ValueError("Prompt must contain 'input' key.") Additionally, you can refer to the JSON structure used in Langflow for a JSON Agent, which includes nodes and edges to define the flow. The from langchain.agents import AgentExecutor
from langchain_community.agent_toolkits import create_json_agent
from langchain_community.agent_toolkits.json.toolkit import JsonToolkit
from langflow.custom import CustomComponent
from langflow.field_typing import BaseLanguageModel
class JsonAgentComponent(CustomComponent):
display_name = "JsonAgent"
description = "Construct a json agent from an LLM and tools."
def build_config(self):
return {
"llm": {"display_name": "LLM"},
"toolkit": {"display_name": "Toolkit"},
}
def build(
self,
llm: BaseLanguageModel,
toolkit: JsonToolkit,
) -> AgentExecutor:
return create_json_agent(llm=llm, toolkit=toolkit) This class provides a clear structure for creating a JSON agent, ensuring that the necessary components ( |
The doubt was regarding the JSON Filed export / Flow Export. Scenario: Now if I Export the JSON (Python code run as flow) of Flow C It doesn't work. |
To properly export and run the JSON for Flow C, ensuring that it correctly invokes Flow A and Flow B as tools, you can use the
Here is an example of how you can use the from pathlib import Path
from your_module import run_flow_from_json # Replace 'your_module' with the actual module name
# Path to the JSON file for Flow C
flow_c_json_path = Path("path/to/flow_c.json")
# Input value to be processed by Flow C
input_value = "your_input_value"
# Load and run the flow
results = run_flow_from_json(
flow=flow_c_json_path,
input_value=input_value,
tweaks=None, # Optional tweaks can be provided here
input_type="chat", # Adjust input type as needed
output_type="chat", # Adjust output type as needed
disable_logs=True # Set to False if you want to enable logging
)
# Process the results
for result in results:
print(result) This code will load the JSON for Flow C, build the graph, run it with the specified input, and print the results. Make sure to adjust the parameters as needed for your specific use case. For example, the JSON structure might look like this: {
"name": "Flow C",
"description": "Flow C that invokes Flow A and Flow B",
"data": {
"nodes": [
{
"id": "FlowA",
"type": "genericNode",
"data": {
"type": "FlowA",
"node": {
"template": {
"input": {
"type": "str",
"required": true,
"value": ""
}
}
}
}
},
{
"id": "FlowB",
"type": "genericNode",
"data": {
"type": "FlowB",
"node": {
"template": {
"input": {
"type": "str",
"required": true,
"value": ""
}
}
}
}
},
{
"id": "FlowC",
"type": "genericNode",
"data": {
"type": "FlowC",
"node": {
"template": {
"input": {
"type": "str",
"required": true,
"value": ""
}
}
}
}
}
],
"edges": [
{
"source": "FlowA",
"target": "FlowC",
"data": {
"sourceHandle": "output",
"targetHandle": "input"
}
},
{
"source": "FlowB",
"target": "FlowC",
"data": {
"sourceHandle": "output",
"targetHandle": "input"
}
}
]
}
} This JSON structure defines Flow C with nodes for Flow A and Flow B, and edges connecting the outputs of Flow A and Flow B to the input of Flow C [1][2][3][4]. |
Hi @edwinjosechittilappilly, |
How to deploy an agent that uses another flow as a tool.
How will the JSON output be ?
Error When running the JSON of the Tool calling agent.
The text was updated successfully, but these errors were encountered: