AG2 Playground AG2 Network Home Docs Page 08 of 08 · closing

BYO Adapter

Every adapter you've met so far — Consulting, Discussion, Workflow — is just an instance of one protocol: ChannelAdapter. Five methods, a manifest, a pure state machine. This page walks the protocol while building a brand-new PollAdapter: one initiator, N respondents, each replies once, the channel auto-closes when everyone has answered.
Network canvas · the protocol + a live example pip (init.) r1 r2 r3
manifest
class-level
ChannelManifest
idle
initial_state
once / channel
(metadata)AdapterState
idle
validate_send
per envelope
(meta, env, state)None
idle
fold
per envelope
(env, state)AdapterState
idle
on_accepted
per envelope
(meta, env, state)AdapterResult
idle
pip
initiator
r1
respondent
r2
respondent
r3
respondent
No channel yet. Once pip.open(type="poll", target=[r1,r2,r3]) runs, messages appear here.
PollState
question_sent False
replied { }
channel no channel
Register & use · hub.register_adapter(PollAdapter()) that's the entire extension point — no factories, no plugin manifests
from autogen.beta.network import Hub
from autogen.beta.knowledge import MemoryKnowledgeStore

hub = await Hub.open(MemoryKnowledgeStore())
hub.register_adapter(PollAdapter())            # keyed by (manifest.type, manifest.version)

# now any agent can open type="poll" channels:
channel = await pip.open(
    type="poll", version=1,
    target=[r1.agent_id, r2.agent_id, r3.agent_id],
)
await channel.send("What's your one-word focus for next quarter?")
# r1, r2, r3 each reply once → channel auto-closes with reason="poll_complete"
That's the whole protocol. Five methods (four really, since text-only I/O reuses framework defaults). A pure state machine. No inheritance, no factory, no plugin manifest — just instantiate your class and call hub.register_adapter(...). Re-registering doesn't affect in-flight channels, because each channel snapshots its manifest at creation. Build whatever turn-taking model your domain actually needs.