Expand description
A budget that travels down the delegation chain: a deadline and named meters (ADR 0023).
§The gap this closes
Without it a parent with ten minutes left can start a child that runs for an hour, and a parent allowed 100,000 tokens can give each of ten children 100,000. A budget carries the time left and the amount left of each named meter to the child, whose server holds the turn to them.
§Wire shape
Not part of A2A v1.0. It ships as the declared extension
https://a2a-rust.com/extensions/budget/v1, in the style of
lease:
- The grant rides on the message that starts or continues the task:
{"remainingMs": <ms>, "meters": {"tokens": 50000}}inMessage.metadataundera2a-rust.com/budget, and the URI inMessage.extensions. Either part may be absent, not both. - The status rides on each status update’s
metadataunder the same key:{"remainingMs", "meters", "spent"}, so whoever watches the stream sees what is left and the parent learns what was spent. The stored task does not carry it.
The time is relative, as gRPC’s grpc-timeout is, so clock skew between
agents does not move it. A meter’s unit is whatever the agents agree its
name means; the SDK enforces the arithmetic, not the meaning.
use std::time::Duration;
use a2a_protocol_types::budget::Budget;
use a2a_protocol_types::message::Message;
let budget = Budget::new()
.with_time(Duration::from_secs(60))
.with_meter("tokens", 50_000)
.unwrap();
let mut message = Message::user_text("m1", "summarise these");
budget.attach(&mut message);
assert_eq!(Budget::read(&message).unwrap(), Some(budget));Structs§
- Budget
- A grant: the time and the amount of each named meter the receiver may spend on one turn.
- Budget
Handle - One turn’s budget, started when its message arrived. Cheap to clone; the clones share one account.
- Budget
Status - What is left of a turn’s budget and what it has spent, as the server reports it on the task and on each status update.
- Child
Grant - A child’s budget, reserved out of its parent’s until it is settled.
Enums§
- Exhausted
- A bound that was hit: the deadline, or a meter overdrawn.
Constants§
- BUDGET_
EXTENSION_ URI - The extension URI a card declares and a message names in
extensions. - BUDGET_
METADATA_ KEY - The metadata key a grant (on a message) and a status (on a task or a status update) travel under.
- MAX_
GRANT_ RESERVE - The most time a grant keeps back from a child.
- MAX_
METERS - The most meters one budget may name.
- MAX_
METER_ NAME_ LEN - The longest meter name, in bytes.
- MIN_
GRANT_ RESERVE - The least time a grant keeps back from a child, for transit and the parent’s own wrap-up.
- TOKENS_
METER - The meter a model’s token usage is charged to, by the SDK’s tool loop and by convention: input plus output tokens, as the provider reports them.