# Agent Economic Action Gate (`bono718/agent-economic-action-gate`) Actor

Evaluate whether an AI agent should buy or execute a paid action. Deterministic expected-value math compares baseline, proposed action and substitutes. Returns BUY, SKIP, STOP or ESCALATE, a rational price ceiling and structured reasons.

- **URL**: https://apify.com/bono718/agent-economic-action-gate.md
- **Developed by:** [Alessandro Bonometti](https://apify.com/bono718) (community)
- **Categories:** AI, Agents, Developer tools
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.002 / economic evaluation

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Agent Economic Action Gate

Should an agent buy or execute an action? Evaluate its marginal economic utility against doing nothing and using a substitute.

Deterministic, structured, no LLM inference. Returns **BUY**, **SKIP**, **STOP**, or **ESCALATE**, the break-even price ceiling, expected value, marginal value, and substitute comparisons. This tool never executes an action or moves money on your behalf.

### Example

A task is worth $100 on success. Baseline success probability is 50%. A $3 verifier improves it by 15 percentage points. A substitute costs $2 and achieves 60% success.

- Baseline expected value: $50.
- Proposed action expected value after cost: $62.
- Substitute expected value after cost: $58.
- Result: **BUY**. Break-even price ceiling: **$7**. Advantage over best outside option: **$4**.

Use the included `examples/input.json` as a complete request. `success_probability_delta: 0.15` means +15 percentage points, not +15% relative improvement.

### Input contract

- `task_value`: nonnegative net payoff if successful, excluding action costs and sunk costs; at most 1e12.
- `currency`: uppercase three-letter label shared by every amount. No currency conversion.
- `baseline_success_probability`: probability of success without purchasing an action.
- `confidence`: caller estimate reliability in \[0,1]. Omitted or below 0.8 yields ESCALATE.
- `action`: `id`, nonnegative all-in `cost`, and `success_probability_delta`. Baseline + delta must be in \[0,1].
- `alternatives`: up to 100 mutually exclusive substitutes, each with `id`, `cost`, absolute `success_probability`, and optional `confidence` (inherits global confidence).

All estimates must refer to the same task, payoff, timeframe and currency. Unknown fields, strings in numeric fields, duplicate IDs and invalid probabilities are rejected.

### Economic rules and limits

`EV = probability * task_value - incremental_cost`.

`max_rational_price = max(0, gross_action_value - best_outside_EV)`.

BUY requires strictly greater value than baseline, substitutes and stopping. Ties prefer no purchase. SKIP may recommend a substitute. STOP means every modeled option has nonpositive expected value. ESCALATE requests better estimates; it does not recommend spending.

The model assumes zero payoff on failure, zero additional cost for the baseline, and zero payoff for stopping. It compares one action against individual substitutes; it does not model sequential purchases, dependencies, risk aversion or portfolios. Include only cases that fit these assumptions. Confidence is a policy gate, not a statistical confidence interval. Estimates are supplied by the caller and are not independently verified.

Decisions use 40-digit decimal arithmetic. Returned numeric amounts are rounded to 15 significant digits. `max_rational_price` is a break-even ceiling; purchase requires a strict advantage at the actual price. A zero ceiling with `break_even_attainable: false` means even a free action cannot match the best alternative.

### Monetization

One valid, completed evaluation is one billable unit, regardless of decision. Invalid input is not an evaluation. Apify charges the `economic-evaluation` event and a separately disclosed start event when enabled. A valid ESCALATE is still a completed evaluation of insufficient confidence.

HTTP routes are protected: `/rapidapi/v1/evaluate` requires the private RapidAPI proxy secret; `/x402/v1/evaluate` uses verified payments. No public unpaid evaluation route exists. MCP forwards to the buyer's RapidAPI subscription and never runs a free local evaluation.

### Run

Node 22+. `npm ci`, `npm test`, `npm run evaluate -- examples/input.json`.

`npm start` runs Apify. `npm run serve` runs HTTP with `.env` configuration; default binds only to localhost. For a production HTTPS host, set `HOST=0.0.0.0`, a reverse proxy/managed ingress, and channel credentials. Unconfigured channels return 503.

For x402 set CDP API credentials, a receiving wallet address, and explicitly choose development/testnet or production/Base mainnet. Bazaar metadata is included; actual indexing requires a successful settled payment and must be verified independently. Price defaults in configuration are deployment candidates, not evidence of live pricing.

For RapidAPI import `openapi.json`, configure the public base URL and proxy secret, and enable the provider's paid request plan. Do not expose the proxy secret to buyers. For MCP set `CI002_RAPIDAPI_ENDPOINT` to the HTTPS RapidAPI gateway evaluate URL and `RAPIDAPI_KEY`, then `npm run mcp`.

Canonical scope: `CI-002_FREEZE_SPEC_v1.0.md`. See `IMPLEMENTATION_POLICY.md` for explicit V1 conventions and deployment state.

# Actor input Schema

## `task_value` (type: `number`):

Net economic payoff on success, relative to stopping. Zero payoff on failure. Excludes action cost and sunk costs.

## `currency` (type: `string`):

One currency for all amounts. No FX conversion.

## `baseline_success_probability` (type: `number`):

baseline\_success\_probability

## `confidence` (type: `number`):

Caller estimate reliability. Below 0.8 or omitted produces ESCALATE; not a probability multiplier.

## `action` (type: `object`):

Action object: id, all-in cost, success\_probability\_delta in percentage points (0.15 = +15 points).

## `alternatives` (type: `array`):

Array of substitutes with id, cost, absolute success\_probability and optional confidence. Same currency and task payoff.

## Actor input object example

```json
{
  "task_value": 100,
  "currency": "USD",
  "baseline_success_probability": 0.5,
  "confidence": 0.95,
  "action": {
    "id": "paid-verifier",
    "cost": 3,
    "success_probability_delta": 0.15
  },
  "alternatives": [
    {
      "id": "other-verifier",
      "cost": 2,
      "success_probability": 0.6,
      "confidence": 0.9
    }
  ]
}
```

# Actor output Schema

## `results` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "task_value": 100,
    "currency": "USD",
    "baseline_success_probability": 0.5,
    "confidence": 0.95,
    "action": {
        "id": "paid-verifier",
        "cost": 3,
        "success_probability_delta": 0.15
    },
    "alternatives": [
        {
            "id": "other-verifier",
            "cost": 2,
            "success_probability": 0.6,
            "confidence": 0.9
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("bono718/agent-economic-action-gate").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "task_value": 100,
    "currency": "USD",
    "baseline_success_probability": 0.5,
    "confidence": 0.95,
    "action": {
        "id": "paid-verifier",
        "cost": 3,
        "success_probability_delta": 0.15,
    },
    "alternatives": [{
            "id": "other-verifier",
            "cost": 2,
            "success_probability": 0.6,
            "confidence": 0.9,
        }],
}

# Run the Actor and wait for it to finish
run = client.actor("bono718/agent-economic-action-gate").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "task_value": 100,
  "currency": "USD",
  "baseline_success_probability": 0.5,
  "confidence": 0.95,
  "action": {
    "id": "paid-verifier",
    "cost": 3,
    "success_probability_delta": 0.15
  },
  "alternatives": [
    {
      "id": "other-verifier",
      "cost": 2,
      "success_probability": 0.6,
      "confidence": 0.9
    }
  ]
}' |
apify call bono718/agent-economic-action-gate --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,bono718/agent-economic-action-gate"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/ast2qtkHYKphYsEtN/builds/abxx0M3LThDzqN2ff/openapi.json
