Expand description
Core traits and types.
Always available regardless of feature flags. Includes:
Agent- The fundamental trait for all agentsTool/Toolset- For extending agents with capabilitiesSession/State- For managing conversation contextEvent- For streaming agent responsesAdkError/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:
| Step | Effect |
|---|---|
| Governance | While the GovernanceControl refuses work (frozen, or stale under a replicated mirror), nothing is pulled; a freeze that lands mid-batch nacks the rest |
| Back-pressure | With 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 |
| Map | The 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) |
| Enqueue | The 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 |
| Ack | Only 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):
| Broker | pull | ack | nack | Message id |
|---|---|---|---|---|
| Amazon SQS | ReceiveMessage (long poll) | DeleteMessage with the receipt handle | ChangeMessageVisibility | MessageId, or the FIFO MessageDeduplicationId |
| Google Pub/Sub | Pull / streaming pull | Acknowledge with the ackId | ModifyAckDeadline | messageId |
| NATS JetStream | pull consumer fetch | Ack | Nak with delay | Nats-Msg-Id header, or stream sequence |
| Kafka | consumer poll | commit the offset | seek back, or a retry topic | topic/partition/offset or a producer key |
| Redis Streams | XREADGROUP | XACK | leave pending; XAUTOCLAIM redelivers | the 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§
- InMemory
Queue Source - Process-local
QueueSourcefor tests, examples, and single-process deployments. - Ingress
Report - What one
QueueIngress::poll_oncedid. - Queue
Ingress - Enqueues each message of a
QueueSourceinto aDurableRunStore; see the module documentation. - Queue
Message - One leased message.
Constants§
- QUEUE_
UNKNOWN_ RECEIPT_ CODE - Error code for an ack or nack whose receipt is not (or no longer) leased.
Traits§
- Queue
Source - A pull-based, at-least-once message source.
Functions§
- unknown_
receipt_ error - Builds the error for an unknown or lapsed receipt.
Type Aliases§
- Queue
RunMapper - Turns a queue message into the run it wakes.