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.2.tar.gz (17.4 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.2-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: async_media_agents-0.1.2.tar.gz
  • Upload date:
  • Size: 17.4 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.2.tar.gz
Algorithm Hash digest
SHA256 c846f18b973627491fc5c81456c4c2df77363712f01c4c32f8ebafec461d9da2
MD5 92301bf406785219eac57436131fd0d5
BLAKE2b-256 2ad87e9a70ae26b5baf55e1d949acd2502cb9d1afaa26ea8b0c68dbd21e56191

See more details on using hashes here.

Provenance

The following attestation bundles were made for async_media_agents-0.1.2.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.2-py3-none-any.whl.

File metadata

File hashes

Hashes for async_media_agents-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 20f654f5b9915d4bc3a788eb11f6dfcf374fb1e74fc1dbb9ea25769df06830b6
MD5 5d2731fa39f332f945ab24e4d190c1c5
BLAKE2b-256 e90c6357cfb41a6c7705e8d8ac5346047017cabb9d438c7b7b35f858b95fcc58

See more details on using hashes here.

Provenance

The following attestation bundles were made for async_media_agents-0.1.2-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