# Multi-Agent Network Analyzer (`constant_quadruped/multi-agent-network-analyzer`) Actor

Extracts topological interaction paths, communication delay, and synergic execution indices from multi-agent swarms.

- **URL**: https://apify.com/constant\_quadruped/multi-agent-network-analyzer.md
- **Developed by:** [CQ](https://apify.com/constant_quadruped) (community)
- **Categories:** Agents, AI, Developer tools
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

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

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js/docs.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python/docs.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

## Multi-Agent Network Analyzer

Turn a log of agent-to-agent messages into a **directed interaction graph**. The actor
reads message records (each with a *source*, a *target*, and an optional *delay*),
aggregates them into directed edges, and reports, for every edge:

- **source** agent
- **target** agent
- **count** — how many messages went `source -> target`
- **delayMs** — the mean communication latency for that edge (in milliseconds), or `null`
  if none of the messages on that edge carried a delay value

Edges are filtered by a configurable minimum transaction count and sorted by count
(busiest links first).

This actor does **not** call any external AI/LLM service and requires **no API keys**.
It only processes the message records you give it.

---

### What it does (and does not do)

**Does:**
- Reads message records from one of four sources (see below).
- Normalizes flexible field names (e.g. `from`/`to`/`latency` or `src`/`dst`/`delay`).
- Aggregates messages into directed `source -> target` edges with a transaction count
  and a mean latency.
- Drops edges below `minTransactions`.
- Pushes one dataset item per surviving edge and writes a summary to the `OUTPUT`
  key-value record.

**Does not:**
- It does not infer agent roles, compute synergy/efficiency scores, or do any graph
  centrality / topological analysis beyond per-edge counts and average latency.
- It does not generate or invent data. If no input source is provided, it logs an
  explanatory message and exits without producing a graph.

---

### Input

Provide **exactly one** input source. They are checked in this priority order:

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `records` | array | one source required | Inline array of message-record objects. Easiest for testing. |
| `datasetId` | string | one source required | ID of an Apify dataset whose items are message records. |
| `recordsUrl` | string | one source required | HTTP(S) URL returning JSON: either an array of records, or an object with the array under `items` / `records` / `data` / `messages` / `edges`. |
| `kvStoreId` + `kvRecordKey` | string + string | one source required | Read a JSON record (array or object) from an Apify key-value store. |
| `minTransactions` | integer | no (default `5`) | Only keep edges with at least this many transactions. |

#### Message record fields (flexible names)

Each record needs a source and a target; the delay is optional. Field names are
normalized, so the following are all accepted:

- **source** ← `source` \| `from` \| `src` \| `sender` \| `sourceAgent` \| `source_agent`
- **target** ← `target` \| `to` \| `dst` \| `receiver` \| `targetAgent` \| `target_agent`
- **delay (ms)** ← `delayMs` \| `delay_ms` \| `delay` \| `latency` \| `latencyMs` \| `durationMs` \| `duration`

Records missing a source **or** a target are skipped. Records with a non-numeric
delay are still counted toward the edge, but contribute no latency sample.

---

### Output

**Dataset** — one item per edge that passed the `minTransactions` filter:

```json
{
  "source": "ManagerAgent",
  "target": "SearchAgent",
  "count": 3,
  "delayMs": 50
}
````

The dataset is never left empty. If no input source is given, no edge meets the
threshold, or a source cannot be loaded, a single informational row is pushed instead:

```json
{
  "message": "No agent links met minTransactions=5 (loaded 4 records, 4 usable messages).",
  "edges": 0,
  "totalMessages": 4
}
```

**Key-value store `OUTPUT`** — a run summary plus the full edge list:

```json
{
  "source": "inline records[] (4 records)",
  "totalMessages": 4,
  "distinctEdges": 2,
  "edgesAfterFilter": 2,
  "minTransactions": 1,
  "edges": [
    { "source": "ManagerAgent", "target": "SearchAgent", "count": 3, "delayMs": 50 },
    { "source": "SearchAgent", "target": "SynthesizerAgent", "count": 1, "delayMs": 90 }
  ]
}
```

***

### Example

Input:

```json
{
  "records": [
    { "source": "ManagerAgent", "target": "SearchAgent", "delayMs": 40 },
    { "source": "ManagerAgent", "target": "SearchAgent", "delayMs": 50 },
    { "source": "ManagerAgent", "target": "SearchAgent", "delayMs": 60 },
    { "source": "SearchAgent", "target": "SynthesizerAgent", "delayMs": 90 }
  ],
  "minTransactions": 1
}
```

Result: two edges — `ManagerAgent -> SearchAgent` (count 3, avg latency `(40+50+60)/3 = 50` ms)
and `SearchAgent -> SynthesizerAgent` (count 1, latency 90 ms).

***

### Setup / auth

None. No credentials or API keys are required. When run on the Apify platform, the
`datasetId` / `kvStoreId` sources resolve against the storages your account can access.

***

### Limitations

- Averages are unweighted means of the numeric delay values present on each edge; records
  without a parseable delay are counted but contribute no latency sample.
- Records are loaded fully into memory and aggregated in a single pass, so extremely large
  datasets (tens of millions of records) may hit memory limits.
- `recordsUrl` must return JSON the actor can parse as a record array (directly or under
  `items` / `records` / `data` / `messages` / `edges`). On an unreachable URL, an HTTP
  error, or an inaccessible dataset / key-value store, the run fails soft: it logs the
  error, pushes a single informational row (with the error in `message`), writes the same
  message to `OUTPUT`, and completes without crashing or hard-failing the run.
- If a source is supplied but no edge meets `minTransactions`, the dataset holds one
  informational summary row (`message`, `edges: 0`, `totalMessages`) rather than being empty.
- If no input source is supplied, the run completes successfully and logs guidance on what
  to provide; it does not produce a graph.

# Actor input Schema

## `records` (type: `array`):

Inline array of agent-message records. Each record needs a source, target, and (optionally) a delay. Field names are flexible: source|from|src|sender, target|to|dst|receiver, delayMs|delay|latency|duration.

## `datasetId` (type: `string`):

ID of an Apify dataset whose items are agent-message records to analyze.

## `recordsUrl` (type: `string`):

HTTP(S) URL returning JSON: either an array of message records, or an object with the records under items/records/data/messages.

## `kvStoreId` (type: `string`):

ID of an Apify key-value store to read message records from (used with kvRecordKey).

## `kvRecordKey` (type: `string`):

Key of the record (JSON array or object) inside the key-value store.

## `minTransactions` (type: `integer`):

Filter links with at least this many transactions.

## Actor input object example

```json
{
  "records": [
    {
      "source": "ManagerAgent",
      "target": "SearchAgent",
      "delayMs": 40
    },
    {
      "source": "ManagerAgent",
      "target": "SearchAgent",
      "delayMs": 50
    },
    {
      "source": "SearchAgent",
      "target": "SynthesizerAgent",
      "delayMs": 90
    }
  ],
  "minTransactions": 5
}
```

# Actor output Schema

## `overview` (type: `string`):

Source-to-target agent links with transaction volume and average latency.

# 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 = {
    "records": [
        {
            "source": "ManagerAgent",
            "target": "SearchAgent",
            "delayMs": 40
        },
        {
            "source": "ManagerAgent",
            "target": "SearchAgent",
            "delayMs": 50
        },
        {
            "source": "SearchAgent",
            "target": "SynthesizerAgent",
            "delayMs": 90
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("constant_quadruped/multi-agent-network-analyzer").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 = { "records": [
        {
            "source": "ManagerAgent",
            "target": "SearchAgent",
            "delayMs": 40,
        },
        {
            "source": "ManagerAgent",
            "target": "SearchAgent",
            "delayMs": 50,
        },
        {
            "source": "SearchAgent",
            "target": "SynthesizerAgent",
            "delayMs": 90,
        },
    ] }

# Run the Actor and wait for it to finish
run = client.actor("constant_quadruped/multi-agent-network-analyzer").call(run_input=run_input)

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

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

```

## CLI example

```bash
echo '{
  "records": [
    {
      "source": "ManagerAgent",
      "target": "SearchAgent",
      "delayMs": 40
    },
    {
      "source": "ManagerAgent",
      "target": "SearchAgent",
      "delayMs": 50
    },
    {
      "source": "SearchAgent",
      "target": "SynthesizerAgent",
      "delayMs": 90
    }
  ]
}' |
apify call constant_quadruped/multi-agent-network-analyzer --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=constant_quadruped/multi-agent-network-analyzer",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Multi-Agent Network Analyzer",
        "description": "Extracts topological interaction paths, communication delay, and synergic execution indices from multi-agent swarms.",
        "version": "1.0",
        "x-build-id": "yuPcqESedfWHbacMq"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/constant_quadruped~multi-agent-network-analyzer/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-constant_quadruped-multi-agent-network-analyzer",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/constant_quadruped~multi-agent-network-analyzer/runs": {
            "post": {
                "operationId": "runs-sync-constant_quadruped-multi-agent-network-analyzer",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/constant_quadruped~multi-agent-network-analyzer/run-sync": {
            "post": {
                "operationId": "run-sync-constant_quadruped-multi-agent-network-analyzer",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "properties": {
                    "records": {
                        "title": "Inline Message Records",
                        "type": "array",
                        "description": "Inline array of agent-message records. Each record needs a source, target, and (optionally) a delay. Field names are flexible: source|from|src|sender, target|to|dst|receiver, delayMs|delay|latency|duration."
                    },
                    "datasetId": {
                        "title": "Apify Dataset ID",
                        "type": "string",
                        "description": "ID of an Apify dataset whose items are agent-message records to analyze."
                    },
                    "recordsUrl": {
                        "title": "Records JSON URL",
                        "type": "string",
                        "description": "HTTP(S) URL returning JSON: either an array of message records, or an object with the records under items/records/data/messages."
                    },
                    "kvStoreId": {
                        "title": "Key-Value Store ID",
                        "type": "string",
                        "description": "ID of an Apify key-value store to read message records from (used with kvRecordKey)."
                    },
                    "kvRecordKey": {
                        "title": "Key-Value Record Key",
                        "type": "string",
                        "description": "Key of the record (JSON array or object) inside the key-value store."
                    },
                    "minTransactions": {
                        "title": "Min Transactions",
                        "type": "integer",
                        "description": "Filter links with at least this many transactions.",
                        "default": 5
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
