Skip to main content

A multi-agent workflow for processing audio, image, and video data.

Project description

async-media-agents

Async Multi-Agent POC using LangGraph + FastMCP + real media processing.

Overview

A lightweight async multi-agent system that processes images, audio, and video via base64-encoded payloads. Uses LangGraph for workflow orchestration, FastMCP for tool registration, and real processing libraries (Pillow, OpenCV, stdlib wave).

Architecture

                User Request
                      |
              SupervisorAgent
                      |
       Fan-out (parallel conditional edge)
      ┌──────────┼──────────┐
      |          |          |
  ImageAgent  AudioAgent VideoAgent
      |          |          |
  Pillow     stdlib wave  OpenCV
  processor   processor   processor
      |          |          |
      └──────────┼──────────┘
           Fan-in to Aggregator

Features

  • Real media processing — Powered by Pillow (Images), OpenCV (Video), and stdlib wave (Audio).
  • Parallel execution — High-performance fan-out/fan-in orchestration using LangGraph.
  • MCP Integration — Model Context Protocol support via FastMCP for tool registration.
  • Robust error handling — Graceful recovery from corrupt base64 or invalid formats.
  • Shared state — Concurrent-safe state management via Annotated reducers.
  • Type Safety — Comprehensive static analysis with basedpyright.

Requirements

langgraph
langchain
fastmcp
Pillow
opencv-python-headless
numpy
pytest
pytest-asyncio

Setup

1. Create and activate a virtual environment

# Create the virtual environment
python -m venv .venv

# Activate it
source .venv/bin/activate        # Linux / macOS
.venv\Scripts\activate           # Windows (cmd)

2. Install dependencies

pip install -r requirements.txt

Project Structure

project/
├── async_media_agents/
│   ├── agents/
│   │   ├── image_agent.py         # Specialized image logic
│   │   ├── audio_agent.py         # Specialized audio logic
│   │   ├── video_agent.py         # Specialized video logic
│   │   └── supervisor.py          # Orchestration & routing
│   │
│   ├── tools/
│   │   ├── mcp_server.py          # FastMCP server registration
│   │   ├── mcp_client.py          # Async client interface
│   │   └── processors/            # Pure processing logic (decoupled)
│   │       ├── image_processor.py # Pillow-based
│   │       ├── audio_processor.py # stdlib wave
│   │       └── video_processor.py # OpenCV-based
│   │
│   ├── graph/
│   │   └── workflow.py            # LangGraph workflow definition
│   │
│   ├── state/
│   │   ├── state.py               # Shared AgentState with reducers
│   │   └── shared_memory.py       # Global shared context utilities
│   │
│   └── __init__.py
│
├── scripts/
│   └── test_workflow.py           # Integration & payload tests
│
├── main.py                         # CLI demo & examples
├── requirements.txt
├── pyproject.toml                  # Project & Tool configuration
└── README.md

Usage

Run the demo

python main.py

The demo demonstrates three core patterns:

  1. Text-based routing — Auto-detects task type from user natural language.
  2. Parallel processing — Simultaneously processes multiple media types via fan-out.
  3. Supervisor workflow — Uses the Supervisor agent to route to a single target.

Run tests

Tests can be executed directly or through pytest:

# Direct execution (includes payload generation logs)
python scripts/test_workflow.py

# Using pytest
pytest scripts/test_workflow.py

The test suite covers:

  • Base64 payload integrity (PNG, WAV, MP4)
  • Real metadata extraction via processors
  • Parallel transport through the workflow
  • Partial payload handling
  • Robust error handling for corrupted data

Programmatic use

from async_media_agents.graph.workflow import Workflow

wf = Workflow()

# Text-based — auto-routes to image/audio/video agent
result = await wf.run("Analyze this image")

# Parallel — feeds base64 to all three agents
result = await wf.run_parallel(
    image_data="base64_encoded_png",
    audio_data="base64_encoded_wav",
    video_data="base64_encoded_mp4",
)

Processing Pipeline

Media Library Extracted Metadata
Image Pillow width, height, format, mode, thumbnail
Audio stdlib wave duration, sample rate, channels, sample width, frames
Video opencv-python-headless duration, fps, resolution, frame count, dimensions

All processors return structured dicts: {"status": "success", "metadata": {...}} or {"status": "error", "error": "..."}.

Static Analysis

The project uses basedpyright for type checking:

pip install basedpyright
basedpyright .

Configuration lives in pyproject.toml under [tool.pyright].

State Management

AgentState extends MessagesState with custom fields. Fields written concurrently during parallel fan-out use Annotated reducers for safe merging:

  • results_merge_results dict merge
  • metadata_merge_results dict merge
  • current_agent_last_wins
  • error_last_wins

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

async_media_agents-0.1.3.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

async_media_agents-0.1.3-py3-none-any.whl (20.7 kB view details)

Uploaded Python 3

File details

Details for the file async_media_agents-0.1.3.tar.gz.

File metadata

  • Download URL: async_media_agents-0.1.3.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for async_media_agents-0.1.3.tar.gz
Algorithm Hash digest
SHA256 c04a7e82aa8ac18e45fa45c8dde802cf35b2b4270946c47645f912d39123a893
MD5 566de2ee1c53b2f420d349627028236b
BLAKE2b-256 7e68b123ceb710c623e4b24f66a10f6408c49b5c118f213ab3687b957085313a

See more details on using hashes here.

Provenance

The following attestation bundles were made for async_media_agents-0.1.3.tar.gz:

Publisher: publish.yml on Abka012/async-media-agents

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file async_media_agents-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for async_media_agents-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d83d7c5e10b4ca3f2883ddbe4d993f367bcd1c3d8df260c5f304cbc444fb65bd
MD5 71c79b1f511586d5fde79515cfb7c96e
BLAKE2b-256 f830992160ed7e60df0359a6ee49594858cf16f46288b6d4d3a2eb2b09aa3584

See more details on using hashes here.

Provenance

The following attestation bundles were made for async_media_agents-0.1.3-py3-none-any.whl:

Publisher: publish.yml on Abka012/async-media-agents

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page