What is the best way to validate an user answer and later on post based on their reply a WordPress post?

Describe the problem/error/question

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.

What is the error message (if any)?

N/A

My workflow

Share the output returned by the last node

Information on your n8n setup

  • n8n version: Cloud
  • Database (default: SQLite): Cloud
  • n8n EXECUTIONS_PROCESS setting (default: own, main): Cloud
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Cloud
  • Operating system: Cloud

I thought in something like this:

I got inspired by this example:

Now, I have a couple of problems:

  • 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:
    image

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?

Any ideas what am I doing wrong? Thank you.

I tried to do some extra changes:

Like changing the tools command:

TOOLS

Assistant may use tools to post on his blog based on his request. The tools that humans can use are:

{tools}

{format_instructions}

USER’S INPUT

Here is the user’s input (remember to respond with a markdown code snippet of a json blob with a single action, and NOTHING else):

{{input}}

But still it doesn’t call the tool, it never reaches that point. Any idea why it doesn’t work? Thanks.

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

Thanks @Jim_Le, I don’t know what I’m doing wrong, but the Blogging tool is not being triggered:

I think I have done almost the same as you. Any idea why it’s never triggered?

Thanks.

I also tried something like this:

And got the same result. The tool is never triggered, I’m not sure what I’m doing wrong :/.

hey @fanmixco

can you try to reference the tool publish_blog_entry directly by name in your system message in the AI Agent? See if that helps? :owl:

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.

But still behaves in the same way :/:

Or was your idea different?

Hey @fanmixco ,
yes, although I wouldn’t have used the {{ }}.

My only other ideas would be to try a different model or the Functions Agent.

Please let us know if that helps! :eyes:

Nothing changed, I removed the {{}} and didn’t call it. Which is the function agent?
image

Hi @fanmixco

sorry, I mean the OpenAI Functions Model that you can select in the AI Agent node (instead of the Tool Agent)

Hi Ria, I was able to make some progress with your suggestion, but then a new issue arose:

Any suggestion? Thanks for your help.

Hi @fanmixco,

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.

  1. 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.
  2. 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"]
}
  1. 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”.


I hope that helps!

Oleg

Hi oleg, I’m using the cloud one, where do you pass the JSON? I cannot see it open section by section. I’m using the Open AI as they suggested.

@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.

Hi Oleg, but if I’m using: app.n8n.cloud. How do I update it? My client is using your N8N cloud. Can I update it on my own? Thanks.

@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: