Metadata-Version: 2.5
Name: papeete-actor-synchronous-messaging
Version: 0.1.1
Summary: A runnable papeete-actor restricted to two verbs — request and query. No publications, no subscriptions.
Author-email: Papeete Consulting <yoann.remy@outlook.com>
License-Expression: MIT
Keywords: actor-model,agents,bounded-context,conformance,llm
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3.11
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
Requires-Python: >=3.11
Requires-Dist: papeete-actor-message>=0.1.0
Requires-Dist: papeete-actor>=1.0.0
Requires-Dist: pyyaml>=6.0
Provides-Extra: claude
Requires-Dist: anthropic>=0.69; extra == 'claude'
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == 'dev'
Provides-Extra: openai
Requires-Dist: openai>=1.40; extra == 'openai'
Description-Content-Type: text/markdown

# papeete-actor-synchronous-messaging

A [papeete-actor](https://github.com/papeete-hub/papeete-actor) you can **run**, restricted to
two verbs.

```
request   ask an actor to do something.
query     ask an actor something.
```

That is the whole vocabulary. No publications, no subscriptions, no event log, no outbox, no
positions, no cadence — and no method on this package that emits an unaddressed fact.

```bash
pip install papeete-actor-synchronous-messaging
```

## The restriction is the product

`papeete-actor` publishes the ecosystem's identity contract. Nothing in the ecosystem *runs* an
actor: a manifest declares who it is, but no code turns that into a box that receives a call,
decides, and replies.

This is that box, deliberately crippled. An earlier design tried to describe an actor with four
directions; two of them were **unaddressed facts, pulled on somebody else's cadence**, and that
is where the hard problems live — positions, redelivery, backfill, supersession, dead letters.
Cutting them out leaves a synchronous, addressed, refusable conversation, small enough to
prove correct in CI and therefore small enough to be the first thing anyone actually runs.

> **This is a papeete-actor that declares no publications and no subscriptions.**

Not "must not" — **cannot**. There is no verb for an unaddressed fact, and no method that would
take one. The guarantee is an absence, which is why the suite can assert it with `hasattr`.

## Back to basics: not even the message's wire shape is fixed here

This package used to also own a message contract — an envelope, a `ref`, four fixed payload
kinds (`request`/`ack`/`query`/`answer`) with their own required fields. That is gone
([ADR-PAS-0007](./adr/ADR-PAS-0007-back-to-basics-actions-and-queries-only.md)). What this
package is now is narrower and more literal than its own name once implied: it lets a caller
address a door an actor declared, with `request` for an action and `query` for a query, and it
hands back whatever the answering actor's own code produced. What crosses a door — its wire
shape, whether it correlates with anything, what "accepted" even means — is not this package's
business. It is dealt with in the actor's own code, as
[`examples/waiter/order_book.py`](./examples/waiter/order_book.py) and
[`examples/customer/decide.py`](./examples/customer/decide.py) do.

**A door still has to name something real, though.** Every door is a *message* —
[`papeete-actor-message`](https://github.com/papeete-hub/papeete-actor-message)'s own
`actor-message.yaml`/`actor-data.yaml` say what data exists and how it groups into an intent,
wire-agnostically. This package is the downstream repo that package's own ADR-PAM-0001 left the
wiring to: a door naming no message in the actor's own catalog is refused
(`card.py`'s cross-check). `papeete-actor-message` is a dependency this package always has —
not an unused import, a gate.

```python
ack = customer.request(to="Waiter", action="take-order",
                       subject="table 5: the wild mushroom risotto",
                       means="the standard order, no allergies flagged")
# ack == {"accepted": True, "order": "order-0001", "line": "order-0001: recorded — ..."}
# — the Waiter's own vocabulary. A different actor would hand back something else entirely.

answer = customer.query(to="Waiter", query="order-status", about=ack["order"],
                        asks="what became of it?")
```

## An actor's folder, in four files, three of them not ours

```
examples/waiter/
  actor.yaml                       papeete-actor-manifest/v0 — name, description. Owned by
                                    papeete-actor, consumed here at a pin, never restated.
  actor-data.yaml                  papeete-actor-data/v0 — a named, minimally-typed data
                                    dictionary. Owned by papeete-actor-message, at a pin.
  actor-message.yaml               papeete-actor-message/v0 — named messages, each a pure
                                    regrouping of data references under an intent. Owned by
                                    papeete-actor-message, at a pin. Wire-agnostic by that
                                    package's own design.
  actor-synchronous-messaging.yaml synchronous-messaging-doors/v0 — actions and queries, nothing else.
                                    Owned by this package. Every door names a message the
                                    catalog above declares.
  order_book.py                    the Waiter's own store, and the only thing it writes
```

`actor-synchronous-messaging.yaml` is a closed shape: `manifest`, `actions`, `queries` at the
top level, `id`/`means`/`completion` on each door — nothing else. No `hard_boundary`, no
`autonomy`, no `nature`/`rail`/`accepts_from`. Which list a door sits in *is* its nature; there
is nothing left to classify once it is placed. What a door's `id` names, though, is not free:
it must resolve against `actor-message.yaml`'s own `messages[].name` — a door is a message,
ridden by `request` or by `query`, never a string invented on the spot.

```bash
papeete-actor-synchronous-messaging lint-card examples/customer examples/waiter
```

## There is no coupling to resolve

An earlier version of this package had a `dependencies:` section, a `Context`, and a
`registry.yaml` — a whole layer between "I have a peer's id" and "I can call it." That layer is
gone. An actor that wants to call another one simply does, by the mailbox name it already has —
often the name a call arrived UNDER:

```python
class Decisions:
    def _confirm_substitution(self, actor, payload, judged, from_):
        # `from_` is the Waiter — the actor that opened THIS exchange. Calling it back needs
        # no coupling, no context, no registry: just its name, and door ids this file knows.
        known = actor.query(to=from_, query="order-status", asks="what does my order say?")
        ack = actor.request(to=from_, action="take-order", subject=..., means=...)
```

Knowing a peer's door ids is that actor's own business knowledge, the same way any real
service client knows the API it depends on. Nothing here discovers it, and nothing refuses an
undeclared edge anymore — the edge is just a call.

## Determinism sits at existence — now the actor's own discipline

A `work` callable is handed the actor, not a pre-computed judgement, so it decides for itself
whether a question is a lookup against its own state or something that needs judgement:

```python
def work(self, actor, offer, verb, payload, from_):
    if offer.id == "order-status":
        # A LOOKUP. "Do I hold this?" is a dict check — the engine is never consulted for it.
        return self._order_status(payload)
    judged = actor.judge(offer, verb, payload, from_)   # only called when it is actually needed
    ...
```

This package no longer knows what "exists" for an arbitrary actor's own state, so it cannot
enforce this centrally — but the pattern is exactly the one `simple-actor-protocol/v0` used to
narrow the engine's schema to enforce, and the example actors still follow it.

## The engine is a port, not a vendor

```python
class Engine(Protocol):
    def judge(self, *, system: str, prompt: str, schema: dict | None = None) -> dict: ...
```

Three adapters, and neither vendor is a dependency of this package:

| engine | used for | needs |
|---|---|---|
| `scripted` | the conformance suite — no network, no key, runs on fork PRs | nothing |
| `claude` | local development — **never runs in CI** (`pytest -m claude`) | `pip install 'papeete-actor-synchronous-messaging[claude]'` |
| `openai` | **CI asserts the protocol with this one** | `pip install 'papeete-actor-synchronous-messaging[openai]'` |

Running one suite against two unrelated vendors is the evidence for this package's own claim —
*"what a papeete-actor is built with is interior; the doors are membrane"* ([ADR-PAS-0003](./adr/ADR-PAS-0003-the-engine-is-a-port.md)).
`schema` is optional: this package's own call sites never pass one, since there is no fixed
payload shape left to constrain an engine to — a caller with its own schema still can.

The system prompt is **generated from the doors**, so impersonating a different actor is a
matter of pointing at a different folder — never of editing a prompt.

## Try it

`examples/customer` and `examples/waiter` are real, run-it-yourself actors — clone this repo,
`pip install -e .`, and the commands below just work. See `examples/README.md` for more.

```bash
papeete-actor-synchronous-messaging contracts
papeete-actor-synchronous-messaging lint-card examples/customer examples/waiter
papeete-actor-synchronous-messaging converse --from examples/customer \
                              --to   examples/waiter --engine scripted
```

```python
from papeete_actor_synchronous_messaging.actor import Actor
from papeete_actor_synchronous_messaging.engine import resolve
from papeete_actor_synchronous_messaging.mailbox import InProcessMailbox

box = InProcessMailbox()
engine = resolve("claude")                       # or "openai", or "scripted"
customer = Actor.from_card("examples/customer", engine, mailbox=box)
waiter   = Actor.from_card("examples/waiter",   engine, mailbox=box)

ack = customer.request(to="Waiter", action="take-order",
                       subject="table 5: the wild mushroom risotto",
                       means="the standard order, no allergies flagged")

answer = customer.query(to="Waiter", query="order-status", about=ack.get("order"),
                        asks="what became of it?")

assert not hasattr(customer, "publish")           # the guarantee is the absent method
```

## The contract is in this repo

[`src/papeete_actor_synchronous_messaging/schemas/`](./src/papeete_actor_synchronous_messaging/schemas/)
— ordinary committed source. **The package IS `synchronous-messaging-doors/v0`**, not a runtime
that goes looking for it. `uv build` reaches nothing outside its own checkout, and
`papeete-actor-synchronous-messaging contracts` is the assertion that the schema arrived in the
wheel.

**Identity is not this package's job, and neither is a message's own shape.** `papeete-actor`
supplies an actor's identity (`name`, `description`, in `actor.yaml`) at a pin.
`papeete-actor-message` supplies its data dictionary and message catalog (`actor-data.yaml`,
`actor-message.yaml`) at a pin. This package reads both and adds only the doors — the wiring
from a message name to `request` or `query`.

## Impersonation — where this is heading

`Actor.from_card(path, engine)` boots an actor from **any** folder holding `actor.yaml`,
`actor-data.yaml`, `actor-message.yaml`, and `actor-synchronous-messaging.yaml`. A business
actor's own identity file already exists today (`actor.yaml` is `papeete-actor`'s own
contract); it becomes impersonatable here the moment its business is also expressed as data,
messages, and a doors sidecar naming them — no bigger card contract to satisfy, no
`hard_boundary`/`autonomy` to declare, because this package no longer asks for them. See
[`doc/SYNCHRONOUS-MESSAGING.md`](./doc/SYNCHRONOUS-MESSAGING.md).

## Licence

MIT.
