Dynamic json object with DynamicTools or DynamicStrcuturedTools #4339
-
I have an agent that generates a json object dynamically, how do I get the agent to push that json object into a dynamicTool or dynamicStructuredTool. this is my tool for reference:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
🤖 Hey @KeenanFernandes2000! 👋 Back at it again, I see? Hope you're doing well and ready to dive into some more coding adventures! 😄 To modify your agent to push a dynamically generated JSON object into a DynamicTool or DynamicStructuredTool, you need to adjust the Here's an example of how you can do this: const runnableAgent = RunnableSequence.from([
{
input: (i: { input: string; steps: AgentStep[] }) => i.input,
agent_scratchpad: (i: { input: string; steps: AgentStep[] }) =>
formatLogToString(i.steps),
},
prompt,
model,
{
// This is the new step where you generate the JSON object
action: (i: { input: string; steps: AgentStep[] }) => {
// Generate your JSON object here
const jsonObject = {
action: "wordDocGen",
action_input: {
// Your dynamic data here
},
};
// Convert the JSON object to a string and return it
return JSON.stringify(jsonObject);
},
},
outputParser,
]); In this example, I've added a new step in the Please replace the comment The structure of the JSON object that the agent needs to generate dynamically is defined by the Here is the structure: {
"title": "Person",
"description": "Identifying information about a person.",
"type": "object",
"properties": {
"name": { "title": "Name", "description": "The person's name", "type": "string" },
"age": { "title": "Age", "description": "The person's age", "type": "integer" },
"fav_food": {
"title": "Fav Food",
"description": "The person's favorite food",
"type": "string"
}
},
"required": ["name", "age"]
} The generated JSON object should look like this: { "name": "John Doe", "age": 30, "fav_food": "chocolate chip cookies" } This is based on the context provided in the code snippet where the You can find more information about this in the examples/src/agents/structured_chat_runnable.ts and examples/src/chains/openai_functions_json_schema.ts files in the langchainjs repository. SourcesThis response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Beta Was this translation helpful? Give feedback.
-
@dosu-bot what if my data is the json object and be infinitely bigger this is the main structure of my dynamic data: but in my case there can be as many headings and content for each headings in the array. How can i just push the full json object to the tool |
Beta Was this translation helpful? Give feedback.
-
The error message "Invalid value for 'content': expected a string, got null" indicates that the To resolve this issue, you can modify your code to check for null values and replace them with an empty string (or another default string value) before processing. Here's a quick example of how you might adjust your code to handle null function processInput(input: any) {
const content = input.content != null ? input.content : "";
// Use 'content' in your processing logic, now guaranteed to be a string
} This adjustment ensures that your processing logic always receives a string for the
|
Beta Was this translation helpful? Give feedback.
The error message "Invalid value for 'content': expected a string, got null" indicates that the
content
field in your JSON object was expected to be a string, but a null value was found instead. This typically happens when theDynamicTool
or similar processing logic in your code checks the type of thecontent
field and does not accept null as a valid input.To resolve this issue, you can modify your code to check for null values and replace them with an empty string (or another default string value) before processing. Here's a quick example of how you might adjust your code to handle null
content
values: