Skip to main content

Module queue_source

Module queue_source 

Source
Expand description

Core traits and types.

Always available regardless of feature flags. Includes:

  • Agent - The fundamental trait for all agents
  • Tool / Toolset - For extending agents with capabilities
  • Session / State - For managing conversation context
  • Event - For streaming agent responses
  • AdkError / Result - Unified error handling Queue wake-ups: messages from a broker become durable runs.

A QueueSource is a pull-based, at-least-once message source: pull leases a batch, and each message is then acked (removed) or nacked (redelivered later). A message that is neither is redelivered when its lease lapses.

QueueIngress connects a source to a DurableRunStore:

StepEffect
GovernanceWhile the GovernanceControl refuses work (frozen, or stale under a replicated mirror), nothing is pulled; a freeze that lands mid-batch nacks the rest
Back-pressureWith max_pending, a batch is never larger than the room left under that many unfinished runs from this source, and nothing is pulled while there is none
MapThe mapper turns the message into a NewRun; a mapping error nacks the message. The run acts for its user as a service (NewRun::with_service_subject)
EnqueueThe run’s idempotency key is queue:{source}:{message id}, so a redelivered or duplicated message returns the existing run instead of creating a second one
AckOnly after the enqueue succeeded (created or existing). A failed enqueue, or one OnConflict::Reject refused, nacks the message for redelivery after retry_after

The run then executes like any other enqueued run: a worker claims it and runs it under the runner’s budget, policy, and kill switch.

§Brokers

InMemoryQueueSource ships here. Broker adapters implement QueueSource in their own crates and prove the contract with queue_source_conformance_tests! (feature conformance):

BrokerpullacknackMessage id
Amazon SQSReceiveMessage (long poll)DeleteMessage with the receipt handleChangeMessageVisibilityMessageId, or the FIFO MessageDeduplicationId
Google Pub/SubPull / streaming pullAcknowledge with the ackIdModifyAckDeadlinemessageId
NATS JetStreampull consumer fetchAckNak with delayNats-Msg-Id header, or stream sequence
Kafkaconsumer pollcommit the offsetseek back, or a retry topictopic/partition/offset or a producer key
Redis StreamsXREADGROUPXACKleave pending; XAUTOCLAIM redeliversthe entry id

§Example

use std::sync::Arc;
use std::time::Duration;
use adk_core::queue_source::{InMemoryQueueSource, QueueIngress};
use adk_core::run_store::{DurableRunStore, InMemoryRunStore, NewRun};

let source = Arc::new(InMemoryQueueSource::new("orders"));
let store = Arc::new(InMemoryRunStore::new());
let ingress = QueueIngress::new(source.clone(), store.clone(), |message| {
    Ok(NewRun::new("default", "shop", "system", "order_agent", message.body_json()?))
});

source.publish("msg-1", br#"{"orderId": 7}"#.to_vec());
source.publish("msg-1", br#"{"orderId": 7}"#.to_vec()); // the broker delivered it twice
let first = ingress.poll_once().await?;
assert_eq!((first.created.len(), first.existing), (1, 1));
assert_eq!(source.unacked(), 0);

Structs§

InMemoryQueueSource
Process-local QueueSource for tests, examples, and single-process deployments.
IngressReport
What one QueueIngress::poll_once did.
QueueIngress
Enqueues each message of a QueueSource into a DurableRunStore; see the module documentation.
QueueMessage
One leased message.

Constants§

QUEUE_UNKNOWN_RECEIPT_CODE
Error code for an ack or nack whose receipt is not (or no longer) leased.

Traits§

QueueSource
A pull-based, at-least-once message source.

Functions§

unknown_receipt_error
Builds the error for an unknown or lapsed receipt.

Type Aliases§

QueueRunMapper
Turns a queue message into the run it wakes.