How microsoft/multi-agent-marketplace works
1. Overall shape
- This is a Python monorepo for simulating two-sided marketplaces driven by LLM agents.
- The center of gravity is the magentic-marketplace Python package; everything else supports data generation, experimentation, visualization, or documentation.
2. Core simulation domain
- The marketplace package contains the simulation logic: buyer/seller agent behavior, marketplace actions, message passing, proposal/history storage, and the search/protocol layer.
- This is the main business boundary for “how a marketplace works” versus “how it is served or analyzed.”
3. Agent layer
- Agents are split into customer and business roles under marketplace/agents/....
- Each role has its own prompts, response models, and agent implementation, which indicates role-specific LLM interaction rather than one generic agent abstraction.
- Shared base classes and storage modules suggest agents persist conversational state and proposals across turns.
4. Protocol and search subsystem
- marketplace/protocol defines the interaction contract for discovery and messaging: fetch messages, send messages, search, and protocol orchestration.
- The search layer includes multiple strategies such as lexical, filtered, optimal, simple, and RNR variants, implying the marketplace can be configured with different retrieval/matching behavior.
- This subsystem is important because it mediates which businesses customers see and in what order, affecting experimental outcomes like position bias and welfare.
5. LLM abstraction layer
- marketplace/llm provides a model-agnostic wrapper with concrete client integrations for OpenAI, Anthropic, and Gemini.
- There is a functional/common layer and config module, so model calls are centralized behind a provider boundary rather than scattered through the simulation.
- This makes provider choice an architectural concern: experiments can swap models without changing marketplace logic.
6. Platform layer: server, client, and databases
- The platform package is the runtime/service boundary around the core marketplace logic.
- It includes:
- a server with routes for agents, actions, logs, and health,
- a client SDK for talking to that server,
- database abstractions with both SQLite and PostgreSQL backends,
- auth dependencies/service, and a launcher/logger.
- This suggests the simulation can run as a service with persisted state and a programmatic API, not only as a local script.
7. Data model and persistence
- The platform and marketplace each have models.py/shared modules, indicating a structured domain model that crosses process boundaries.
- Database query modules are separated by concern (agents, actions, logs), which implies the persistent store is organized around marketplace events and agent state.
- Logs are first-class: LLM calls, actions, and agent interactions are intended to be queried after a run, not just printed.
8. Experiment execution and analysis
- The experiments subpackage under magentic_marketplace provides CLI-facing orchestration for running experiments, exporting results, listing experiments, analytics, and audit/tracing.
- The repo also contains standalone experiment scripts under experiments/ for specific studies such as competitive, malicious, position bias, and consideration set size.
- This split suggests two levels: reusable experiment infrastructure in the package, and research-specific notebooks/scripts at the repo root.
9. Data sets and scenario families
- The data/ directory is the primary experiment input space.
- It contains many scenario families: mexican_*, contractors_*, competitive_description, malicious_description, and position_bias.
- Each scenario has separate businesses/ and customers/ YAML files, plus baseline_utilities.json in many datasets, so the simulation inputs are declarative and file-based.
10. Data generation pipeline
- data/data_generation_scripts contains scripts for generating people, items, customers/businesses, baseline utilities, and validators.
- This is an offline content-generation boundary: it produces the YAML/JSON experiment assets consumed by the simulation, rather than participating in runtime behavior.
- The presence of “contractors” and “mexican” generation variants suggests the repo supports multiple domain templates and scale tiers.
11. Visualization/UI
- There are two UI layers:
- a Python-served UI in packages/magentic-marketplace/src/magentic_marketplace/ui,
- a separate TypeScript/Vite app in packages/marketplace-visualizer.
- The visualizer consumes database-backed data and renders businesses, customers, conversations, and panels, which means it is primarily an inspection/debugging tool for simulation output.
- The UI is not the source of truth; it reads from the persisted marketplace state/logs.
12. Repository tooling and automation
- The repo uses uv for Python dependency management, docker-compose for the database service, and GitHub Actions for tests, linting, type checking, and docs deployment.
- Docs are built with VitePress under docs/, and the repository includes scripts for env generation and basic repo hygiene checks.
- These tools support the architecture by enforcing consistency across simulation code, data assets, and experiment reproducibility.
13. Typical end-to-end flow
- A user selects a dataset in data/..., runs the CLI or an experiment script, the simulation loads business/customer YAML plus baseline utilities, agents interact through the protocol and LLM layer, and the platform persists actions/logs in SQLite or PostgreSQL.
- After execution, analytics/export tools read those persisted traces and produce result summaries, plots, or UI views.
14. Key boundaries to draw in an architecture diagram
- Separate offline asset generation from online simulation execution.
- Separate core marketplace logic from LLM providers and from platform/persistence.
- Treat the UI/visualizer as a consumer of stored results, not part of the simulation engine.
- Treat experiments as orchestration around the core engine rather than core domain code.
Main entry points: platform Platform · database Databases · marketplace Marketplace · server Server
Components 20
Core engine
Marketplace simulation and LLM abstractions
- Marketplace · Core marketplace simulation domain and behavior
packages/magentic-marketplace/src/magentic_marketplace/marketplace - Agents · Customer and business agent implementations with prompts and response models
packages/magentic-marketplace/src/magentic_marketplace/marketplace/agents - Protocol · Discovery, search, fetch-message, and send-message orchestration
packages/magentic-marketplace/src/magentic_marketplace/marketplace/protocol - Search · Lexical, filtered, optimal, simple, and RNR search variants
packages/magentic-marketplace/src/magentic_marketplace/marketplace/protocol/search - LLM layer · Model-agnostic LLM abstraction and provider clients
packages/magentic-marketplace/src/magentic_marketplace/marketplace/llm - Shared models · Cross-boundary marketplace data models
packages/magentic-marketplace/src/magentic_marketplace/marketplace/shared/models.py
Platform
Service layer, persistence, client, and shared runtime models
- Platform · Server, client, database, auth, launcher, and logger around the marketplace core
packages/magentic-marketplace/src/magentic_marketplace/platform - Server · HTTP server and routes for agents, actions, logs, and health
packages/magentic-marketplace/src/magentic_marketplace/platform/server - Client SDK · Programmatic client for the platform server
packages/magentic-marketplace/src/magentic_marketplace/platform/client - Databases · SQLite and PostgreSQL storage implementations plus queries
packages/magentic-marketplace/src/magentic_marketplace/platform/database - Platform models · Runtime-facing platform data models and converters
packages/magentic-marketplace/src/magentic_marketplace/platform/shared/models.py
Research
Reusable experiment orchestration and study-specific scripts
- CLI · Package entrypoint for running marketplace workflows
packages/magentic-marketplace/src/magentic_marketplace/cli.py - Experiments · Reusable experiment commands for run, export, analytics, audit, and trace extraction
packages/magentic-marketplace/src/magentic_marketplace/experiments - Study scripts · Standalone experiment runners, analysis, and plots for named studies
experiments
Data assets
Declarative scenario inputs and offline generation pipeline
- Scenario data · Declarative business/customer datasets and baseline utilities
data - Data gen · Offline scripts for generating customers, businesses, items, and baselines
data/data_generation_scripts
Inspection UI
Python UI and standalone visualizer for stored runs
- Python UI · Package-served UI for inspecting marketplace state
packages/magentic-marketplace/src/magentic_marketplace/ui - Visualizer · Standalone Vite app for browsing stored marketplace runs
packages/marketplace-visualizer/src
Docs and tooling
Documentation, CI, and repo automation
- Docs site · VitePress concepts and usage documentation
docs - Repo tooling · CI workflows, environment scripts, compose config, and dependency locks
Connections 27
- CLI → Marketplace: runs · CLI invokes the simulation engine
- CLI → Experiments: orchestrates · CLI exposes experiment commands
- Experiments → Marketplace: drives · Reusable experiment logic runs marketplace simulations
- Study scripts → Experiments: uses · Research scripts wrap the reusable experiment package
- Study scripts → Scenario data: loads · Study scripts consume declarative scenario data
- Data gen → Scenario data: produces · Generation scripts create dataset YAML and baseline JSON assets
- Marketplace → Agents: contains · Core simulation includes buyer and seller agent roles
- Marketplace → Protocol: coordinates · Marketplace behavior is mediated through the interaction protocol
- Protocol → Search: uses · Protocol relies on retrieval and ranking strategies
- Agents → LLM layer: calls · Agents use the shared LLM provider boundary
- Agents → Shared models: reads/writes · Agents persist shared marketplace state and proposals
- Protocol → Databases: queries · Protocol actions are backed by database access
- Databases → Platform models: stores · Persistence layer maps platform runtime models
- Server → Databases: persists · Server routes read and write marketplace state through the database
- Server → Platform models: serves · API exposes platform runtime models
- Client SDK → Server: consumes · Client SDK talks to the server API
- Platform → Server: includes · Platform package includes the server runtime
- Platform → Client SDK: includes · Platform package includes the client SDK
- Platform → Databases: includes · Platform package includes persistence backends
- Platform → Shared models: shares · Runtime and core share common models across boundaries
- Python UI → Platform: renders · Served UI sits on top of platform data and runtime
- Visualizer → Databases: reads · Visualizer consumes persisted run data
- Docs site → Experiments: documents · Docs explain CLI and experiment workflows
- Docs site → Platform: documents · Docs cover platform concepts and usage
- Repo tooling → Docs site: deploys · Repo tooling includes docs deployment automation
- Repo tooling → Platform: validates · CI and scripts validate the package and platform code
- Repo tooling → Scenario data: checks · Automation helps keep data assets and experiments consistent