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)
- Chat exception message contains 'vertex' keyword which is confusing when used with other providers HOT 1
- Langflow show black screen on launch HOT 8
- feat: add Milvus components
- only getting first few letters of the output HOT 3
- [pre-release alpha bug] a46 with python 3.11.9 won't start HOT 5
- LANGFLOW black screen on launch HOT 2
- [Feature Request] Integration of Agent Protocol from AI-Engineer-Foundation into Langflow HOT 2
- Integrating Custom Callback to Output Agent Steps in Recode Format HOT 2
- Duplicate "session_id" in response of API on pre-release. HOT 6
- Error in the Code Export: Boolean values are in the incorrect syntax. 'false' should be changed to 'False', 'true' should be changed to 'True'. HOT 2
- No Response when running the Flow using cURL or Python API HOT 2
- TypeError: RedisCache.upsert() got an unexpected keyword argument 'lock' HOT 1
- Error building node TextLoader HOT 1
- sqlite3.OperationalError: table _alembic_tmp_flow already exists during Langflow startup HOT 1
- Testing alpha release with docker compose: required keyword-only argument: 'recursive_guard' HOT 2
- [Feature Request] Add support for `dimensions` parameter in embedding models
- [Feature Request] Support secretes stored in Kubernetes
- [Feature Request] A generic SecretService to support store secrets
- langflow build hangs 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.