Channel API¶
Channels are independently installable transports for one persistent agent identity. See Channels and Listening for lifecycle, delivery semantics, and an extension example.
nagents.channels.Channel
¶
Bases: ABC
A trusted connector. Installations remain explicit; imports do not connect.
open initializes resources, listen delivers events with backpressure,
and close releases resources after producers/execution have stopped.
Transport acknowledgements belong to the connector. Agent responses are
emitted only through explicit send/action tools, never auto-forwarded.
actions supplies connector operations through the existing channel_list,
channel_send and channel_action tools. on_event is optional execution
observation for status notices, independent of tools and typing activity.
Source code in src/nagents/channels/types.py
activity(event)
async
¶
approval(message)
¶
Recognize a decision for a rendered approval prompt, without doing I/O.
Only connectors that render approval prompts and advertise approvals
implement this. Returning a value claims the interaction: the host either
applies a fully validated decision or ignores it, and never enqueues it as
model input. Returning None leaves the message to normal handling.
Source code in src/nagents/channels/types.py
command(message)
¶
fetch_attachment(attachment)
async
¶
Download a referenced attachment for model input.
Only connectors that advertise fetch_attachment in capabilities
need to implement this. Return the raw bytes and the effective media type
within the host's caps; raise a sanitized ChannelError otherwise. The
host never treats the returned content as instructions.
Source code in src/nagents/channels/types.py
listen(receive)
abstractmethod
async
¶
on_event(event)
async
¶
Optionally render a source-scoped status notice; default does nothing.
Cooperate with cancellation and bound transport I/O. Hosts should await dispatch_channel_execution_event for failure isolation and joined, bounded dispatch. Never retry an uncertain notice send automatically.
Source code in src/nagents/channels/types.py
send(message)
abstractmethod
async
¶
nagents.channels.ChannelDispatcher
¶
A bound catalog and tools, independent of execution and connector lifecycle.
Source code in src/nagents/channels/dispatcher.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 | |
action_schema(channel, action)
¶
Return a detached advertised schema; reject unknown channels/actions.
Source code in src/nagents/channels/dispatcher.py
catalog()
¶
Return a fresh, detached snapshot, including for an empty dispatcher.
channel_action(channel, action, arguments)
async
¶
Perform one advertised connector action; consult channel_list for its argument schema.
Source code in src/nagents/channels/dispatcher.py
channel_list()
async
¶
Discover configured channels, descriptive capabilities, and action schemas.
Source code in src/nagents/channels/dispatcher.py
channel_send(channel, destination, text, thread_id='', reply_to='', attachments=None)
async
¶
Send one explicit message to a chosen channel and destination, without retries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
attachments
|
list[str] | None
|
Up to three workspace-relative file paths to upload with the message. Connectors may reject unsupported attachments; the text may be empty when files are present. |
None
|
reply_to
|
str
|
Remote transport message ID in the chosen channel/conversation, not an ingress message_id. Use the inbound reply_to when replying to that event; otherwise leave empty. |
''
|
Source code in src/nagents/channels/dispatcher.py
contains_channel(name, channel)
¶
Check bound name AND connector identity without trusting mutable names.
register_tools(registry)
¶
Own temporary tool registration without replacing or restoring tools.
Preflight all names before registration. On every exit remove only the exact definitions installed here, preserving any subsequent replacement. Connector lifecycle and execution policy remain the caller's concern.
Source code in src/nagents/channels/dispatcher.py
nagents.channels.ChannelContentCapabilities
dataclass
¶
Optional directional declarations, validated and snapshotted at binding.
An omitted direction is undeclared, not unsupported or unrestricted. An
explicit direction with false text support and no file types supports
neither. Existing transport Channel.capabilities retain their meanings.
Source code in src/nagents/channels/types.py
nagents.channels.ChannelReceiveCapabilities
dataclass
¶
Content admitted into agent input; via identifies the admission owner.
Host-managed input does not imply support for Channel.listen. File
limits are optional declarations, independent of provider modality support.
Source code in src/nagents/channels/types.py
nagents.channels.ChannelSendCapabilities
dataclass
¶
Accepted explicit outbound content. Text support does not permit text files.
Source code in src/nagents/channels/types.py
nagents.channels.ChannelRenderCapabilities
dataclass
¶
Recipient presentation support, independent of model input or authorization.
Source code in src/nagents/channels/types.py
nagents.channels.ChannelMessage
dataclass
¶
An external event. Its identity is stable within the connector instance.
Conversation/thread IDs describe the source; they do not select an Agent
session. All connectors attached to one listener share that listener's session.
reply_to is a transport message ID suitable for replying to this event;
it can differ from the ingress message_id used for deduplication.
Metadata must be JSON-compatible and must not contain credentials.
Source code in src/nagents/channels/types.py
nagents.channels.ChannelSend
dataclass
¶
An explicit outgoing message selected by the application or model.
Source code in src/nagents/channels/types.py
nagents.channels.ChannelAttachment
dataclass
¶
A connector-owned reference, not automatically downloaded or executed.
Source code in src/nagents/channels/types.py
nagents.channels.ChannelDelivery
dataclass
¶
Remote message identifiers returned after confirmed delivery.
Source code in src/nagents/channels/types.py
nagents.channels.ChannelAction
dataclass
¶
Advertise an integration-specific operation, such as editing a message.
Source code in src/nagents/channels/types.py
nagents.channels.ChannelPlugin
dataclass
¶
Callable entry point with a configuration schema for management clients.
JSON Schema properties marked writeOnly: true are credentials: clients
collect them separately and never echo saved values. The host validates and
persists configuration; the factory performs connector-specific validation.
Ordinary callable factories remain supported by load_channel.
Source code in src/nagents/channels/types.py
nagents.channels.ChannelCommand
dataclass
¶
A connector-recognized host command; the host decides which commands exist.
Source code in src/nagents/channels/types.py
nagents.channels.ChannelActivity
dataclass
¶
Session activity for transport indicators, independent of model replies.
Source code in src/nagents/channels/types.py
nagents.channels.ChannelError
¶
Bases: Exception
A sanitized connector failure suitable for a tool result.
No implicit send retries are performed. outcome_unknown means a remote
side effect may have happened. Never put credential-bearing URLs in errors.
Source code in src/nagents/channels/types.py
nagents.channels.ChannelEvent
dataclass
¶
Observe execution locally; observation never sends a channel reply.
Source code in src/nagents/channels/types.py
nagents.channels.load_channel(name, config)
¶
Load one installed, explicitly selected factory; never auto-enable plugins.
A factory receives a JSON-compatible configuration dictionary and returns a
Channel. Constructors/factories must defer network I/O until open.
Source code in src/nagents/channels/plugins.py
Local delivery metadata¶
These records describe durable local deliveries separately from model messages. An origin is correlation data, not authorization; host execution must supply and validate it. Tool receipts and notifications contain references rather than media bytes. Concrete interface adapters use the journal through their owned host.
nagents.channels.delivery_types.DeliveryOrigin
dataclass
¶
Durable correlation captured by the owned execution/assistant-write bridge.
Values are data, not execution authority. A host must validate its live invocation before using an origin to commit a local delivery.
Source code in src/nagents/channels/delivery_types.py
nagents.channels.delivery_types.DeliveryAsset
dataclass
¶
An opaque attachment reference; no content bytes in presentation metadata.
Source code in src/nagents/channels/delivery_types.py
nagents.channels.delivery_types.DeliveryReceipt
dataclass
¶
One committed local delivery, independently identifiable across reloads.
Source code in src/nagents/channels/delivery_types.py
channel_delivery()
¶
Return a compact tool receipt, without duplicating text or media bytes.
Source code in src/nagents/channels/delivery_types.py
notification()
¶
Return a small invalidation notice; hosts retrieve content separately.
Even a large text delivery must not exceed a bounded replay/subscription queue's budget. Repeated notices identify the same committed delivery.
Source code in src/nagents/channels/delivery_types.py
nagents.channels.delivery_types.DeliveryHistory
dataclass
¶
Stable anchor-based groups; rendering belongs to the owning interface.
Source code in src/nagents/channels/delivery_types.py
nagents.channels.local_delivery.LocalDeliveryService
¶
Connect an execution-bound authority to a journal without starting listeners.
Trusted hosts supply an authority backed by their approved invocation bridge, never by tool arguments or an inherited context variable alone. This service does not register channels, grant approval or infer an executing session.
Source code in src/nagents/channels/local_delivery.py
send(channel, message, capabilities, *, notify=discard_notification)
async
¶
Commit once, then publish a small best-effort invalidation notice.
Cancellation joins the owned commit. If commit succeeded its receipt and identity remain durable even when cancellation prevents a returned tool result. Notification failure never makes a known commit a failed send. Observers must cooperate with cancellation, like other channel hooks.
Source code in src/nagents/channels/local_delivery.py
nagents.session.deliveries.DeliveryJournal
¶
Source code in src/nagents/session/deliveries.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | |
prepare(origin, channel, message, capabilities)
¶
Validate actual bytes and snapshot the entire payload before any await.
Source code in src/nagents/session/deliveries.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
nagents.session.deliveries.PreparedDelivery
¶
Single-use write. Cancellation joins storage; inspect receipt/outcome afterward.
receipt is a zero-or-one tuple, including after caller cancellation.
outcome is prepared, pending, committed, failed, or unknown. A second commit raises
RuntimeError, even after failure; separate prepares always allocate fresh IDs.
Failed means no commit or established rollback; unknown raises a sanitized
ChannelError with outcome_unknown=True. Recovery only reads the allocated ID.