Skip to content

SessionAdapter

autogen.beta.network.adapters.base.SessionAdapter #

Bases: Protocol

Code half of the manifest/adapter split.

Adapters are looked up at session-create time by (manifest.type, manifest.version). Re-registering an adapter at a new version does not retroactively change in-flight sessions — they keep their original manifest snapshot.

manifest instance-attribute #

manifest

initial_state #

initial_state(metadata)

Empty state for a fresh session.

Source code in autogen/beta/network/adapters/base.py
def initial_state(self, metadata: SessionMetadata) -> AdapterState:
    """Empty state for a fresh session."""
    ...

fold #

fold(envelope, state)

Append envelope into the derived state. Pure function.

Called once per WAL append by the hub. Must be deterministic so Hub.hydrate() can re-fold from disk.

Source code in autogen/beta/network/adapters/base.py
def fold(self, envelope: Envelope, state: AdapterState) -> AdapterState:
    """Append ``envelope`` into the derived state. Pure function.

    Called once per WAL append by the hub. Must be deterministic so
    ``Hub.hydrate()`` can re-fold from disk.
    """
    ...

validate_create #

validate_create(metadata)

Raise on invalid creation (bad participant count, missing knobs, ...).

Source code in autogen/beta/network/adapters/base.py
def validate_create(self, metadata: SessionMetadata) -> None:
    """Raise on invalid creation (bad participant count, missing knobs, ...)."""
    ...

validate_send #

validate_send(metadata, envelope, state)

Raise if this envelope is not allowed by the protocol at this point.

Receives state BEFORE fold(envelope, ...) runs.

Source code in autogen/beta/network/adapters/base.py
def validate_send(
    self,
    metadata: SessionMetadata,
    envelope: Envelope,
    state: AdapterState,
) -> None:
    """Raise if this envelope is not allowed by the protocol at this point.

    Receives state BEFORE ``fold(envelope, ...)`` runs.
    """
    ...

on_accepted #

on_accepted(metadata, envelope, state)

Decide post-accept transitions.

Receives state AFTER fold(envelope, ...) has run.

Source code in autogen/beta/network/adapters/base.py
def on_accepted(
    self,
    metadata: SessionMetadata,
    envelope: Envelope,
    state: AdapterState,
) -> AdapterResult:
    """Decide post-accept transitions.

    Receives state AFTER ``fold(envelope, ...)`` has run.
    """
    ...

default_view_policy #

default_view_policy(metadata, participant_id)

Per-participant default projection for this session type.

Source code in autogen/beta/network/adapters/base.py
def default_view_policy(
    self,
    metadata: SessionMetadata,
    participant_id: str,
) -> ViewPolicy:
    """Per-participant default projection for this session type."""
    ...

extract_turn_input #

extract_turn_input(envelope)

Decode an inbound substantive envelope into the input the next speaker's LLM should receive on its turn.

Return None (or empty string) for envelopes this adapter doesn't act on — the handler will skip the round.

The default behaviour (default_extract_turn_input) handles EV_TEXT. Adapters that emit additional substantive event types (e.g. EV_PACKET for the workflow adapter) override to decode those.

Source code in autogen/beta/network/adapters/base.py
def extract_turn_input(self, envelope: Envelope) -> "str | Input | list[Input] | None":
    """Decode an inbound substantive envelope into the input the
    next speaker's LLM should receive on its turn.

    Return ``None`` (or empty string) for envelopes this adapter
    doesn't act on — the handler will skip the round.

    The default behaviour (``default_extract_turn_input``) handles
    ``EV_TEXT``. Adapters that emit additional substantive event
    types (e.g. ``EV_PACKET`` for the workflow adapter) override
    to decode those.
    """
    ...

build_round_envelope #

build_round_envelope(metadata, sender_id, reply, events, state, hub)

Build the envelope that captures one Agent.ask round.

Called by the handler after Agent.ask returns. Adapters encode the round result into the envelope shape they expect: the default (default_build_round_envelope) emits EV_TEXT(reply.body) if non-empty, else None (silent round, no envelope posted).

Returning None means "this round produced nothing worth recording" — the caller skips the post.

Source code in autogen/beta/network/adapters/base.py
def build_round_envelope(
    self,
    metadata: SessionMetadata,
    sender_id: str,
    reply: "AgentReply",
    events: "list[BaseEvent]",
    state: AdapterState,
    hub: "Hub",
) -> Envelope | None:
    """Build the envelope that captures one ``Agent.ask`` round.

    Called by the handler after ``Agent.ask`` returns. Adapters
    encode the round result into the envelope shape they expect:
    the default (``default_build_round_envelope``) emits
    ``EV_TEXT(reply.body)`` if non-empty, else ``None`` (silent
    round, no envelope posted).

    Returning ``None`` means "this round produced nothing worth
    recording" — the caller skips the post.
    """
    ...

render_envelope #

render_envelope(envelope)

Project envelope to its LLM-visible string for view policies.

Called by ViewPolicy.project once per envelope in the WAL slice the participant should see. Adapters that emit only EV_TEXT delegate to default_render_envelope; adapters with richer round-end shapes (e.g. WorkflowAdapter with EV_PACKET) handle their own types and fall through to the default for the universal cases.

Returning None means "skip this envelope in the projection" (non-substantive event types, malformed payload, etc.).

Source code in autogen/beta/network/adapters/base.py
def render_envelope(self, envelope: Envelope) -> str | None:
    """Project ``envelope`` to its LLM-visible string for view policies.

    Called by ``ViewPolicy.project`` once per envelope in the WAL
    slice the participant should see. Adapters that emit only
    ``EV_TEXT`` delegate to ``default_render_envelope``; adapters
    with richer round-end shapes (e.g. ``WorkflowAdapter`` with
    ``EV_PACKET``) handle their own types and fall through to
    the default for the universal cases.

    Returning ``None`` means "skip this envelope in the projection"
    (non-substantive event types, malformed payload, etc.).
    """
    ...