# Agent post gate

Free resources from the APIWings guide [How an AI agent can publish your social media posts safely](https://apiwings.com/blog/ai-agent-publish-social-media-posts). Code: MIT. Data and templates: CC BY 4.0.

The gate decides whether a post proposed by an AI agent may go to your publishing service. It returns `publish`, `needs_approval` or `blocked`, the reasons, the approval hash and the idempotency key. `publish` means "authorized to send", not "published": only the network's result confirms that.

## Files

| File | What it is |
|---|---|
| `agent-post-gate.mjs` | The gate in JavaScript (Node 18 or later, no dependencies) |
| `agent_post_gate.py` | The same gate in Python (3.9 or later, no dependencies) |
| `agent-post-policy.json` | Policy template: accounts, allowed domains, limits, secret patterns, network rules with sources |
| `agent-tools.json` | Three least-privilege tools for the agent, in MCP format |
| `example-agent-proposals.json` | The worked example: eight proposals and their state |
| `gate-test-cases.json` | 420 test cases with the expected result |
| `test-gate.mjs`, `test_gate.py` | Run the test cases |
| `ai-agent-posting-cheat-sheet.pdf` | One-page cheat sheet |

## Run the tests

```
node test-gate.mjs
python test_gate.py
```

Both print `420 of 420 cases pass` (checked on Node 22 and Python 3.13, 25 November 2026). Both implementations return identical results, including the approval hash and the idempotency key.

## Use it

```js
import { check } from "./agent-post-gate.mjs";
const result = check(proposal, policy, state); // state: { now, history, approval }
```

```python
from agent_post_gate import check
result = check(proposal, policy, state)
```

The gate checks policy only. It does not check each network's text and media limits (see the cross-post validator in [posting to multiple social networks with one API call](https://apiwings.com/blog/post-to-multiple-social-networks-api)), follow redirects, or check who is allowed to approve: do those in your backend.
