I’m quite new using N8N and LangChain (or any post-processing text tool for LLMs). I am building a Telegram bot and I want that after I get an answer, I could say something like, “Can you post it in my blog?” And if I type a text like that one, it should ask me something like, “What would be the title?” And then post it in my WordPress if not, it should continue our conversation.
I have been able to get answers from OpenAI and post it via WordpPress as in the workflow I shared later, but I don’t know exactly what I should change. I guess I need to change something in the Output parser, but I’m not so sure, has anyone built anything like this? Thank you.
The WordPress section is never triggered. I don’t know why, I almost copied the same example with just minor changes like the general message:
Call this tool whenever the user requests to publish something on their blog/WordPress. Please send the user request for the post as an inline query string.
It seems the $json.query is always empty:
Or I don’t how to access it. I also tried: {{ $json.output }} and got the same result.
I don’t know how to reply to the user that the post has been created with a friendly message. Should I call the OpenAI message again in some way? Or what would be the best approach?
In my experience, the AI tools agent is vastly superior to the other options when tool usage is key. Here’s a quick example which I tested and it seems to work fine. Requirement: You’ll need version 1.44.1 or above to use the Tools Agent
Hi Ria, thanks for your reply, I changed the system message to this one:
You are a blogging assistant. You help the user ideate on blog entries, create the blog content and can also publish to the blog.
Converse with the user and try to determine the title and subject of the blog entry they want to create. It is your role to generate the content for it. Once you have decided you have enough data to create a blog entry, provide the user with a short summary and ask if the user would like to publish it using the tool {{publish_blog_entry}}. If confirmed, publish the blog entry.
I tried to reproduce your use-case, only supplementing the Wordpress with Google Sheet, but the principle is the same. I’ve used this workflow and it seems to be working as expected
There’s a few things I had to change to get this to work.
As @Jim_Le already mentioned, Tools Agent is generally way more reliable than Conversational agent, that’s why it’s the default Agent in the latest versions of n8n.
Since v1.44 we now also support providing either JSON schema or an example JSON object to the workflow tool. This comes really handy for when you need to pass more than one argument to your tool. Without it, the query would just be a stringified object, so you’d also need to take care of parsing it inside your “sub-workflow”. You can see in the publish_blog_entry that I’ve used following schema:
{
"type": "object",
"properties": {
"title": {
"type": "string",
"description": "The title of the blog entry"
},
"summary": {
"type": "string",
"description": "The summary of the blog entry"
},
"content": {
"type": "string",
"description": "The main body content of the blog entry"
},
"tags": {
"type": "array",
"description": "Any semantic tags which could be derived from the content",
"items": {
"type": "string"
}
}
},
"required": ["title", "content", "summary", "tags"]
}
It’s important that the sub-workflow returns “response” property, in my workflow I’ve branched the Google Sheet step to return both on success and on error.
With these changes I was able to get the LLM to draft me an article and to also “publish it”.
@fanmixco This was released in 1.43.0 so might need to update your instance. The JSON schema is inputed into the tool when you connect it to the agent:
Seems like our preview instance is not yet updated so this option isn’t visible, but if you update your instance it should.
@fanmixco Only administrators of the instance can update it. If you’re an administrator you can do so by navigating to admin panel, then “Manage” and there you should see “n8n version” select. Here’s a quick video for better demonstration:
I had to remove the tags since it didn’t recognize the JSON properly and said the tag didn’t exist:
{
"type": "object",
"properties": {
"title": {
"type": "string",
"description": "The title of the blog entry"
},
"summary": {
"type": "string",
"description": "The summary of the blog entry"
},
"content": {
"type": "string",
"description": "The main body content of the blog entry"
}
},
"required": ["title", "content", "summary"]
}
Also, I got a new error:
“The workflow did not return an item with the property ‘response’”
@fanmixco I think you’re almost there. You just need to make that the tool(Publish Blog Tool) returns an object which contains response property. I’m not sure what’s the output of Wordpress node, but the easiest way to achieve this would be to add a Set node. You could also connect second set node to an error output of Wordpress node, to let LLM know in case there’s an error. Something like this:
In case this doesn’t work, please share a few screenshots from the execution tab. It would be helpful to see both main and sub-workflow executions.