Open edwinjosechittilappilly opened 3 weeks ago
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
, tools
, user_prompt
, handle_parsing_errors
, memory
, and input_value
. Here is an example:
{
"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 user_prompt
contains the 'input' key. The code raises a ValueError
if the 'input' key is missing from the user_prompt
:
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 JsonAgentComponent
class in Langflow constructs a JSON agent from an LLM and tools:
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 (llm
and toolkit
) are properly configured [1][2][3].
To continue talking to Dosu, mention @dosu.
The doubt was regarding the JSON Filed export / Flow Export.
Scenario: There are 3 flows: Flow A: Task 1 Flow B: Task 2 Flow C: tool calling agent that used Flow A and Flow B as tools using Flow as tools component.
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 run_flow_from_json
function provided in the load.py
file. Here is how you can do it:
Prepare the JSON for Flow C: Ensure that the JSON for Flow C includes the necessary configurations to invoke Flow A and Flow B as tools. For example, the JSON should define the nodes and edges that connect Flow A and Flow B to Flow C.
Use the run_flow_from_json
function: This function will load the flow from the JSON and run it with the specified input.
Here is an example of how you can use the run_flow_from_json
function:
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].
To continue talking to Dosu, mention @dosu.
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.