> ## Documentation Index
> Fetch the complete documentation index at: https://docs.expectedparrot.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Shared-state manual

> Build shared state from first principles, from a typed poll to coordinated interviews.

> [!NOTE]
>
> This is the canonical shared-state manual. The API is experimental. Read the [execution contracts](https://docs.expectedparrot.com/en/latest/coordinated-research/execution-contracts.md) for current persistence, visibility, and compatibility guarantees.

Shared state is data that several EDSL interviews can read and change. It makes
group voting, bargaining, discussion boards, forecasting, auctions, and common
task pools possible.

The [execution contracts](https://docs.expectedparrot.com/en/latest/coordinated-research/execution-contracts.md)
define the current persistence, retry, definition-binding, and workflow
integration guarantees. The [language specification](https://docs.expectedparrot.com/en/latest/shared-state/semantics.md)
provides formal semantics and identifies additional conformance requirements.
Use the execution contracts to resolve ambiguities about current behavior.

This guide constructs one shared data structure explicitly. Nothing is hidden
behind a recipe factory. Once every part is understood, we add grouping,
surveys, storage, and convenience constructors.

## The mental model

A shared-state system has four distinct layers:

```text theme={null}
Machine definition
    ↓
SharedState space
    ↓
SharedStateMap of spaces
    ↓
Execution store
```

A **Machine** defines one kind of data structure: what it stores, which writes
are legal, and what readers can see.

A **SharedState** is one concrete space containing one or more named machines.
For example, the space for `family-1` might contain a poll and a message board.

A **SharedStateMap** maps scope keys such as `family-1` and `family-2` to
independent `SharedState` spaces.

A **store** persists spaces while interviews execute. It may be managed locally
or remotely. Storage is separate from the data definitions.

We will build these layers in that order.

## Example: choosing an activity

Four people will choose among:

```python theme={null}
activities = [
    "bike ride",
    "sailing",
    "hike",
    "beach day",
]
```

We want one vote per person, represented by a dictionary:

```python theme={null}
{
    "Amina": "hike",
    "Boris": "sailing",
}
```

Keys are voter names. Values must be one of the four activities. A voter's first
vote wins; retries or later attempts do not replace it.

That plain-language description is the specification we will encode.

## Manual chapters

* [Machines, commands, and views](https://docs.expectedparrot.com/en/latest/shared-state/machines.md) — Define fields, atomic transitions, requirements, and participant-visible views.
* [Testing and serialization](https://docs.expectedparrot.com/en/latest/shared-state/testing-and-serialization.md) — Test a machine without a survey and preserve its definition as versioned JSON.
* [Scopes, surveys, and execution](https://docs.expectedparrot.com/en/latest/shared-state/scopes-and-surveys.md) — Bind machines to groups, order interviews, and inspect persistent state provenance.
* [Collections and lifecycle](https://docs.expectedparrot.com/en/latest/shared-state/collections-and-lifecycle.md) — Build logs, derive collection views, and distinguish completion from closing.
* [Shared-state pattern cookbook](https://docs.expectedparrot.com/en/latest/shared-state/patterns.md) — Adapt complete patterns for ballots, markets, private signals, task pools, and payoffs.
* [Randomization and exact money](https://docs.expectedparrot.com/en/latest/shared-state/randomization-and-money.md) — Reproduce keyed draws and tie-breaking, and settle integer units with explicit rounding.
* [Survey quotas and screening](https://docs.expectedparrot.com/en/latest/shared-state/survey-quotas.md) — Ask respondent type, reserve ten A and ten B places, and end screened-out interviews.
* [Adaptive reason discovery](https://docs.expectedparrot.com/en/latest/shared-state/reason-discovery.md) — Grow a reason list through Other responses and stop after ten quiet agents.
* [Adaptive question coverage](https://docs.expectedparrot.com/en/latest/shared-state/question-coverage.md) — Assign up to three under-covered questions per agent and stop at ten valid answers per question.
* [Adaptive pairwise comparisons](https://docs.expectedparrot.com/en/latest/shared-state/pairwise-comparisons.md) — Compare products, update scores, and select later pairs using those scores and exploration.
* [Appointment booking](https://docs.expectedparrot.com/en/latest/shared-state/appointment-booking.md) — Hold, confirm, and release slots with durable reservation identities.
* [Adaptive price elicitation](https://docs.expectedparrot.com/en/latest/shared-state/price-elicitation.md) — Narrow a personal integer price interval within one survey pass.
* [Balanced experimental assignment](https://docs.expectedparrot.com/en/latest/shared-state/balanced-assignment.md) — Balance several characteristics while assigning conditions atomically.
* [Team formation](https://docs.expectedparrot.com/en/latest/shared-state/team-formation.md) — Let respondents choose teams while enforcing role-specific capacity.
* [Second-price auction](https://docs.expectedparrot.com/en/latest/shared-state/second-price-auction.md) — Collect sealed bids and settle one unit.
* [Uniform-price auction](https://docs.expectedparrot.com/en/latest/shared-state/uniform-price-auction.md) — Allocate multiple units and settle at the highest rejected bid.
* [Posted-price market](https://docs.expectedparrot.com/en/latest/shared-state/posted-price-market.md) — Sell inventory using versioned quotes and atomic payment.
* [Primitive examples and validation](https://docs.expectedparrot.com/en/latest/shared-state/algorithms-and-reference.md) — Build and replay nineteen mechanisms from general Machine primitives, with a record of design limitations.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.