# Wrap and self-heal AI agent tools with HTTP and Postgres: n8n workflow

> Started by an event in a connected app, and works across Postgres. 25 steps, 5 branches, 1 loop or waits: large, and worth reading before you trust it with...

Source: https://millionrounds.com/workflow/wrap-and-self-heal-ai-agent-tools-with-http-and-postgres (Millionrounds; every figure on the page links to its filing or article)

[Automation library](https://millionrounds.com/workflows) · [Content](https://millionrounds.com/workflows?category=Content#library)

# Wrap and self-heal AI agent tools with HTTP and Postgres

Started by an event in a connected app, and works across Postgres. 25 steps, 5 branches, 1 loop or waits: large, and worth reading before you trust it with anything live.

Large

[Download free](https://millionrounds.com/login?next=%2Fapp%2Fworkflow%2Fwrap-and-self-heal-ai-agent-tools-with-http-and-postgres)

**25 steps** Large: read it before trusting it with anything live

**5** Branches: places the flow splits

**1** Loop or waits

**1** Service it connects to

## The flow

Starts it 2 Logic 20 Service 3

The steps in the order they run, from what starts it.

- 1 **When Called by Tool** Execute Workflow trigger *Starts it*
- 2 **Demo, Manual Trigger** Manual trigger *Starts it*
- 3 **Parse Tool Input** Code *Logic*
- 4 **Demo, Sample Tool Call** Set *Logic*
- 5 **IF, Parse OK?** If *Logic*
- 6 **IF, Requires Approval?** If *Logic*
- 7 **Return Tool Result** Set *Logic*
- 8 **Build Approval Context** Set *Logic*
- 9 **Route by Tool Name** Switch *Logic*
- 10 **Wait for Approval (Form)** Wait *Logic*
- 11 **Execute HTTP Request** Http Request *Service*
- 12 **Validate SQL (read-only)** Code *Logic*
- 13 **Execute Web Search** Http Request *Service*
- 14 **Unknown Tool → TOOL_ERROR** Set *Logic*
- 15 **Process Decision** Code *Logic*
- 16 **HTTP Success → Tool Result** Code *Logic*
- 17 **HTTP Error → TOOL_ERROR** Code *Logic*
- 18 **IF, SQL Valid?** If *Logic*
- 19 **Search Success → Tool Result** Code *Logic*
- 20 **Search Error → TOOL_ERROR** Code *Logic*
- 21 **IF, Approved?** If *Logic*
- 22 **Execute Postgres Query** Postgres *Service*
- 23 **PG Invalid → Pass-through** Set *Logic*
- 24 **PG Success → Tool Result** Code *Logic*
- 25 **PG Error → TOOL_ERROR** Code *Logic*

## How it's built

- **Starts on:** An event in a connected app
- **Steps:** 25, with 5 branches, 1 loop or waits
- **Size:** Large: read it before trusting it with anything live
- **Connects to:** Postgres
- **Model:** None. This is plumbing, not judgement

## Questions

What does it need to run?

An n8n account, plus your own Postgres account. You connect your own accounts after importing it; none are included.

What starts it?

It starts on an event in a connected app.

Does it use AI?

No. Every step is fixed logic or a call to a service, so it does the same thing every time.

How long does it take to set up?

Take your time. At 25 steps it is large: read it before trusting it with anything live.

How do I import it?

Copy the workflow, open a new workflow in n8n and paste. The steps appear on the canvas, ready for your own accounts.

**Before you run it**

Nothing here has been tested by us. It is somebody's working automation, read and described from its own steps. Treat the connections it wants as a list of accounts it will touch, and read the 25 steps before you point it at anything that matters.

## Run it in n8n

- **Create your n8n account** Free to start. n8n is where the workflow runs. [Create an n8n account ↗](https://millionrounds.com/n8n)
- **Download the workflow** Free with a Millionrounds account. [Download free](https://millionrounds.com/login?next=%2Fapp%2Fworkflow%2Fwrap-and-self-heal-ai-agent-tools-with-http-and-postgres)
- **Paste it into n8n** Open a new workflow in n8n and paste. Then connect your own accounts.

Stored with the author's traces removed: canvas notes, instance identifiers, saved credential names and any live document they had left behind.

## Connects to

Each opens the other workflows that use it.

[Postgres](https://millionrounds.com/workflows?service=Postgres#library)

## Workflows like it

Also content, with the same services where possible, closest in size first.

- [**Viral content opportunities from Twitter, Reddit** 24 steps · Email, Postgres](https://millionrounds.com/workflow/viral-content-opportunities-from-twitter-reddit)
- [**Automate blog-to-social media with OpenAI and Reddit** 24 steps · calls a model · LinkedIn, Postgres](https://millionrounds.com/workflow/automate-blog-to-social-media-with-openai-and-reddit)
- [**Route and analyze customer feedback with Qwen3-VL and Tally** 26 steps · calls a model · Discord, Postgres](https://millionrounds.com/workflow/route-and-analyze-customer-feedback-with-qwen3-vl-and-tally)
- [**Route weather-based delivery holds with Open-Meteo and Gemini** 26 steps · calls a model · Postgres, Slack](https://millionrounds.com/workflow/route-weather-based-delivery-holds-with-open-meteo-and-gemin)
- [**Auto-generate & publish SEO articles to WordPress with OpenAI** 23 steps · calls a model · Postgres](https://millionrounds.com/workflow/auto-generate-and-publish-seo-articles-to-wordpress-with-ope)
- [**Automated Instagram content creation from trending posts** 27 steps · calls a model · Postgres, Telegram](https://millionrounds.com/workflow/automated-instagram-content-creation-from-trending-posts)
