Comments (3)
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.
from langflow.
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.
from langflow.
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.
from langflow.
Related Issues (20)
- RC1 : Python API : Circular API import HOT 1
- [pre alpha] ERROR: Failed building wheel for faiss-cpu HOT 3
- LANGFLOW_OPEN_BROWSER ignored in .env file HOT 1
- 1.0.3 seems not working HOT 5
- when set custom component in V0.6.5,it is work。 but when start v1.0.0,it is not have custom menu。 HOT 3
- v1.0 AttributeError: build_model not found in AzureChatOpenAIComponent HOT 1
- Deploying to Railway, never starts the app successfully! HOT 1
- Error when using Azure OpenAI model v1.0.0 HOT 7
- Nothing is working in v1.0.3 HOT 1
- Migration to New Custom Components in Langflow HOT 4
- run make init 报错了 HOT 5
- Question about HuggingFace deployment HOT 2
- Issue with saving data to Chroma DB HOT 4
- Chroma DB build Error HOT 3
- I'm having issues setting up langflow through docker-compose HOT 8
- Can't store secret key global variables on Railway deployment (Fernet key must be 32 url-safe base64-encoded bytes) HOT 1
- In Home page the alignment for github button is not correct HOT 2
- Couldn't get the vector search option HOT 7
- Implement CI for checking PR titles use conventional-commit
- Images Not Displaying Correctly in langflow (1.0.5) Docker Container Behind Traefik Proxy HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from langflow.