Skip to main content
Post

#PowerPlatformTip 174: 'Self-Healing Connector Actions in Copilot Studio - Retry & Remember'

#PowerPlatformTip 174: 'Self-Healing Connector Actions in Copilot Studio - Retry & Remember'

TL;DR: A connector bound directly as a Copilot Studio tool ends the call with an error such as HTTP404NotFound or HTTP422UnprocessableEntity when the API answers with a non-2xx status. The agent gets an error code, not the API’s explanation. Wrap the call in a flow that catches every status and always returns clean JSON (ok, status, error, data). The agent reads that, corrects its parameters and retries in a capped loop. Put proven corrections into the tool description so every user benefits.

Updated November 24, 2026: Microsoft renamed the GitHub Copilot harness to Microsoft Copilot harness. Memory is rolling out for general availability. Memory section adjusted to the current Microsoft Learn wording.

You gave your Custom Connector to a Copilot Studio agent as a tool and let generative orchestration build the call (#PowerPlatformTip 173). Now make it survive real-world API errors. Real APIs return 400/404/422 for a wrong path or a malformed body - and a directly bound connector action turns those into a failed tool call, so the agent can neither fix itself nor explain what went wrong. A thin flow wrapper turns every error into feedback the agent can act on.

💡 Challenge

You want an agent that answers “log 2 hours on project X” by calling the right MOCO endpoint on its own. But a directly bound connector action that gets a 400/404/422 ends as a failed tool call (Copilot Studio error codes HTTP400BadRequest, HTTP404NotFound, HTTP422UnprocessableEntity). The response body that explains what was wrong never reaches the agent as tool output, so it can neither correct itself nor explain the problem - a dead end on the first bad path or body.

✅ Solution

Route the actual HTTP call through a Power Automate flow that catches every status and always returns a clean, structured JSON. The agent reads that JSON, corrects its parameters and tries again in a capped loop - true self-healing. This is the connector-specific sibling of the result() pattern from #PowerPlatformTip 168.

flowchart TD
    A["Agent calls flow tool"] --> B["Scope: connector/HTTP call"]
    B -->|success| C["Respond: ok = true, data"]
    B -->|failed or timed out| D["Respond: ok = false, status, error"]
    C --> E["Agent uses data"]
    D --> F{"Attempts < max?"}
    F -->|yes| G["Agent corrects parameters"] --> A
    F -->|no| H["Agent explains failure to user"]
    G -.->|proven fix| I[("Tool description / instructions")]

🔧 How It’s Done

1. Understand the direct-binding limit.

🔸 Bound as a tool, a non-2xx status ends the tool call with an error code such as HTTP404NotFound or HTTP422UnprocessableEntity. Instructions can’t change this - it happens at the connector layer, not in the model.

2. Wrap the call in a flow (the self-healing part).

🔸 Put the connector/HTTP action inside a Scope (see #PowerPlatformTip 45).

🔸 On the next action set Configure run after to run on is successful, has failed and has timed out (the try-catch-finally idea from #PowerPlatformTip 15).

🔸 Always end with Respond to the agent returning a fixed shape, e.g. { "ok": false, "status": 422, "error": "…", "data": null }, regardless of the real HTTP status.

🔸 Expressions for the failure response (assuming the call action is named HTTP): status = coalesce(outputs('HTTP')?['statusCode'], 0) and error = string(coalesce(body('HTTP'), 'no response')). For a custom connector action, use its action name instead. In the success response use ok = true and data = body('HTTP').

🔸 Keep the flow fast: an agent flow that runs longer than 100 seconds ends with FlowActionTimedOut. Set a short timeout on the HTTP action so the failure branch still answers in time.

🔸 Licence note: the HTTP action and custom connectors are premium.

3. Add the flow as the agent’s tool.

🔸 Build the flow on the “When an agent calls the flow” trigger and end it with the “Respond to the agent” action.

🔸 In Copilot Studio: Tools > Add a tool > your flow. Enable generative orchestration so the agent selects the tool and fills inputs itself.

🔸 Because the flow never “fails”, the agent always receives readable JSON and can reason: retry with a corrected path/body, or explain the problem.

4. Retry loop, then keep the fix.

🔸 Because the flow returns a readable error instead of failing, the agent can reconsult the definition, rebuild and retry, looping until it gets a 2xx. Cap it: instruct a max number of attempts (e.g. 3) so it doesn’t loop or burn tokens forever.

🔸 Corrections that always apply (the right path, a required field) belong in the tool description or the agent instructions. Then every user and every conversation starts with the fix.

🔸 Agents on the Microsoft Copilot harness (formerly called GitHub Copilot harness) can also use Memory, turned on in the Build tab. Memory is rolling out for general availability and may still be in preview in some regions. It is stored per user: it helps that one user’s later conversations and is deleted after 28 days of inactivity, counted from the last time the agent used that user’s memories. Agents that have their own account use one shared memory for everyone instead. Memory complements the tool description, it doesn’t replace it.

5. Guardrails for writes.

🔸 For POST/PUT (e.g. creating activities) add a confirmation step before sending - in the flow, or via the agent’s instructions - to avoid wrong bookings in MOCO.

🎉 Result

The agent picks the endpoint, builds the body and recovers from its own mistakes in a bounded loop instead of dead-ending on a hard error. Proven fixes in the tool description keep it from repeating them. You keep the exact “catch any status, return it, let it retry” behavior you already trust from Power Automate.

🌟 Key Advantages

🔸 Self-healing: the flow wrapper guarantees a readable response, so the agent can retry with corrections.

🔸 Deterministic contract: one JSON shape for success and failure keeps the model’s reasoning stable.

🔸 Learns from mistakes: a correction written into the tool description applies to every user from the next call on.

🔸 Bounded: a max-attempts rule keeps the loop, and your token spend, under control.

🔸 Safe writes: confirmation before POST/PUT prevents accidental records.

🛠️ FAQ

1. Why not bind the connector directly, it’s simpler?

It is, until an endpoint returns 404/422. Then the tool call fails with HTTP404NotFound or HTTP422UnprocessableEntity and the agent can’t recover, because the non-2xx is handled at the connector layer and the API’s explanation never arrives as tool output. The flow wrapper is what enables self-healing.

2. What exactly should the flow return?

A fixed JSON contract, e.g. ok, status, error, data. Same shape on success and failure so the model always knows how to read it. Keep the payload small too: filter large MOCO lists with query/limit inputs, because an oversized tool output fails with AsyncResponsePayloadTooLarge.

3. Can the agent remember the fix so it doesn’t repeat the error?

For all users: write the fix into the tool description or the instructions. For a single user: agents on the Microsoft Copilot harness can use Memory from the Build tab, which stores context per user and deletes it after 28 days of inactivity.

4. How do I stop it from looping forever?

Put a max-attempts rule in the agent instructions (e.g. try at most 3 times, then explain the failure). The readable JSON makes each retry productive; the cap keeps it bounded. Start with read-only GETs, validate, then enable writes.

This tip is by Marcel Lehmann, Microsoft MVP (Business Applications) and founder of the Power Platform Academy, which runs free live workshops (in German). See the next free workshop dates (in German). For companies that want this implemented for them, see KMUpower: Power Platform consulting & automation for SMEs (DACH).

This post is licensed under CC BY 4.0 by the author.

Microsoft and the Power Platform product names (for example Power Apps, Power Automate, Copilot Studio) are trademarks of the Microsoft group of companies. This is an independent website. It is not operated, sponsored or endorsed by Microsoft.