
AWS Dogwood: Temporal Guardrails for Agent Tool Calls
Summary
Gate agent tool calls on what happened before, not one request at a time.
Every guardrail most teams put on an AI agent answers one question: is this single tool call allowed? Cedar, IAM, an allowlist in your MCP gateway. They all look at the request in front of them and nothing else.
That misses the way agents actually cause damage. No individual call is wrong. The order is wrong. The agent issues a refund it never got approved. It reads a confidential document and then emails an outside address. It fires forty small transfers in a minute because each one passed the per-call check.
On August 6, 2026 AWS open-sourced Dogwood, a policy language built for exactly this. It extends Cedar with when temporal { ... } clauses that can look back over an agent's prior tool calls before deciding on the current one. Apache 2.0, with a reference interpreter and a CLI you can run today. Below we build a refund agent's policy from its MCP tool manifest, replay it against an event trace, and watch a cap that looks correct silently lock the agent out of its own job.
Every command and every output in this guide was run against the reference interpreter at dogwood 1.0.0. Nothing here is illustrative.
Prerequisites
- A Rust toolchain (
rustup, stable). The CLI is the only thing you compile; you write no Rust. - Git, and about two minutes for the first build.
- Rough familiarity with Cedar's
permit/forbidshape. If you have never seen Cedar, the policies below are still readable. - An agent with tools. We use an MCP
tools/listmanifest, but you can hand-write the schema instead.
Step 1: build the Dogwood CLI
The reference interpreter lives in one repo. The binary is called dogwood; the crate that produces it is amzn-dogwood-cli, which trips people up on the first build.
git clone --depth 1 https://github.com/dogwood-policy/dogwood.git
cd dogwood
cargo build --release -p amzn-dogwood-cli
export PATH="$PWD/target/release:$PATH"
dogwood --version
# dogwood 1.0.0
Five subcommands: validate type-checks a policy, replay runs it against an event trace, lower shows the Cedar it compiles to, check-parse does syntax only, and schema checks or generates schemas. Exit codes are worth knowing for CI: 0 success, 1 a usage or I/O error, 2 input the tool rejected. That split lets a pipeline tell "the tool broke" from "the policy is wrong."
Step 2: generate the action schema from your MCP manifest
A Dogwood action schema is, structurally, an MCP tool manifest. Each tool becomes a Cedar action; its inputSchema becomes context.input and its outputSchema becomes context.output. So point Dogwood at what your MCP server already publishes rather than hand-writing entity declarations.
Here is the manifest for a customer-support refund agent. Three tools: look up an order, ask a human to approve a refund, actually move the money.
// tools.json
[
{ "name": "LookupOrder",
"description": "Look up an order by id. Returns the amount paid in USD.",
"inputSchema": { "type": "object",
"properties": { "orderId": {"type":"string"} },
"required": ["orderId"] },
"outputSchema": { "type": "object",
"properties": { "amount": {"type":"integer"} },
"required": ["amount"] } },
{ "name": "ApproveRefund",
"description": "Ask a human reviewer to approve a refund for an order.",
"inputSchema": { "type": "object",
"properties": { "orderId": {"type":"string"}, "amount": {"type":"integer"} },
"required": ["orderId","amount"] },
"outputSchema": { "type": "object",
"properties": { "approved": {"type":"boolean"} },
"required": ["approved"] } },
{ "name": "IssueRefund",
"description": "Move money back to the customer for an order.",
"inputSchema": { "type": "object",
"properties": { "orderId": {"type":"string"}, "amount": {"type":"integer"} },
"required": ["orderId","amount"] },
"outputSchema": { "type": "object",
"properties": { "settled": {"type":"boolean"} },
"required": ["settled"] } }
]
dogwood schema mcp --manifest tools.json -o schema.cedarschema
The generator layers one action per tool onto a template that supplies principals, a gateway resource, and the base action hierarchy. JSON types map straight across: integer to Long, string to String, boolean to Bool, and number with format: decimal to Cedar's decimal. Part of the output:
namespace Drupe {
type IssueRefundInput = { amount: Long, orderId: String };
type IssueRefundOutput = { settled: Bool };
entity Gateway;
entity User;
action "IssueRefund" in [Action::"CallTool"] appliesTo {
principal: [User],
resource: [Gateway],
context: {
input: IssueRefundInput,
output?: IssueRefundOutput,
system: SystemContext
}
};
// ... ApproveRefund, LookupOrder, and the base Mcp/Http/CallTool actions
}
Note output? is optional. A tool request has inputs only; the outputs show up on the matching response event. That distinction turns out to matter more than anything else in this guide.
Step 3: the approval gate
First rule: a refund may only be issued if a human approved this order for this amount, within the last hour.
// policy.dw
@id("refund_needs_fresh_approval")
permit (
principal,
action == Drupe::Action::"IssueRefund",
resource
)
when temporal {
formerly within 1h Drupe::Action::"ApproveRefund"::response{
input.orderId: context.input.orderId,
input.amount: context.input.amount,
output.approved: true
}
};
Read formerly within 1h as "at some point in the last hour." The record after the action name is the correlation, and it is the whole game. input.orderId: context.input.orderId pins the past approval's order to the order being refunded right now. Drop that line and any approval for any order unlocks any refund. Same for input.amount: without it, approving a $5 refund authorizes a $5,000 one.
output.approved: true reads a field off the response event, which is the only place a tool's return value exists. Type-check it:
dogwood validate policy.dw --policy-schema schema.cedarschema
# OK: validation passed with no errors or warnings.
Step 4: replay a trace and watch the verdict move
Validation proves the policy is legal. replay shows what it means. A trace is one event per line: a timestamp in seconds, an optional scope(...) and request_context(...) envelope, then the fully qualified action with its kind and its logged fields.
// trace.log (abridged - full version in the next step)
@0 scope(principal: Drupe::User::"agent", resource: Drupe::Gateway::"gw1")
request_context(input: { orderId: "A-1001", amount: 200 })
Drupe::Action::"IssueRefund"::request(input: { orderId: "A-1001", amount: 200 },
callerPrincipal: Drupe::User::"agent", callerResource: Drupe::Gateway::"gw1",
requestId: "r1")
@60 scope(principal: Drupe::User::"agent", resource: Drupe::Gateway::"gw1")
Drupe::Action::"ApproveRefund"::response(input: { orderId: "A-1001", amount: 200 },
output: { approved: true }, callerPrincipal: Drupe::User::"agent",
callerResource: Drupe::Gateway::"gw1", requestId: "r2")
@120 scope(principal: Drupe::User::"agent", resource: Drupe::Gateway::"gw1")
request_context(input: { orderId: "A-1001", amount: 200 })
Drupe::Action::"IssueRefund"::request(input: { orderId: "A-1001", amount: 200 },
callerPrincipal: Drupe::User::"agent", callerResource: Drupe::Gateway::"gw1",
requestId: "r3")
(Each event is one line in the real file; wrapped here for readability.) Run it:
dogwood replay policy.dw --policy-schema schema.cedarschema --trace trace.log
@0 (time point 0): DENY
@120 (time point 1): ALLOW [rules: 0]
Same request, same agent, same amount, opposite verdicts. At @0 nothing had been approved. At @120 the approval from @60 sits inside the window. [rules: 0] names the policy that decided it, indexed by position in the .dw file. Response events are history-only, so they produce no verdict line.
Step 5: add a daily cap, and get it wrong
Approval gating is not enough. A compromised or confused agent can get many small refunds approved. Add a hard cap: no more than $500 of refunds in 24 hours.
Dogwood ships a small standard library of temporal macros. sum_within adds up a numeric field across matching events in a window; bind gives that total a name so you can threshold it.
// appended to policy.dw
@id("refund_daily_cap")
forbid (
principal,
action == Drupe::Action::"IssueRefund",
resource
)
when temporal {
bind(spent,
sum_within(a, 24h, Drupe::Action::"IssueRefund"::request{ input.amount: a }),
spent > 500)
};
a is bound to each matching event's input.amount, and forbid beats permit, so this caps the agent no matter what got approved. It validates cleanly. Now replay it against a fuller trace where the agent tries five refunds, one of which is a $900 request for an order nobody ever approved:
dogwood replay policy.dw --policy-schema schema.cedarschema --trace trace2.log
@0 (time point 0): DENY
@120 (time point 1): ALLOW [rules: 0]
@180 (time point 2): DENY [rules: 1]
@300 (time point 3): DENY [rules: 1]
@420 (time point 4): DENY [rules: 1]
Look at @300 and @420. Those are legitimate, human-approved refunds of $400 and $100. Total money actually paid out so far: $200. The cap is $500. They should both be allowed. They are denied by rule 1, the cap.
The reason is the @180 event. That $900 refund was denied and no money moved. But it was still a IssueRefund::request, so it landed in the event history, and sum_within over ::request counted it. One rejected call poisoned the agent's entire 24-hour budget.
The fix, and the tradeoff underneath it
Sum over ::response events instead. A response only exists if the call actually completed, and output.settled: true narrows it further to refunds that really settled:
@id("refund_daily_cap_settled")
forbid (
principal,
action == Drupe::Action::"IssueRefund",
resource
)
when temporal {
bind(settled,
sum_within(a, 24h, Drupe::Action::"IssueRefund"::response{
input.amount: a,
output.settled: true
}),
settled > 500)
};
dogwood replay policy_v2.dw --policy-schema schema.cedarschema --trace trace2.log
@0 (time point 0): DENY # no approval on record
@120 (time point 1): ALLOW [rules: 0] # approved; $200 settles
@180 (time point 2): DENY # $900, never approved - no permit matches
@300 (time point 3): ALLOW [rules: 0] # approved; $200 settled so far, under cap
@420 (time point 4): DENY [rules: 1] # $600 settled - cap bites
That is the behaviour you wanted. The rejected $900 no longer counts, real refunds go through, and the cap fires at exactly the right moment.
But this version has a hole the first one did not, and AWS calls it out in the launch post. Agents make parallel tool calls. If the agent fires five $200 refunds at once, none of them has a response yet, so settled is still 0 and all five are permitted. Summing over requests is immune to that, because the in-flight requests count against the total the moment they are made.
There is no free answer here. Requests over-count failures; responses under-count concurrency. Pick based on which risk is worse for the tool, and if the tool moves money, consider both clauses with different windows and thresholds.
The operators you will actually use
Four macros cover most real policies. All are defined in Dogwood's standard macro library on top of a core drawn from Metric First-Order Temporal Logic, so you can drop to the primitives when the macros do not fit.
| Operator | Question it answers | Example |
|---|---|---|
formerly within W P | Did P happen at all in the window? | was this order approved in the last hour |
count_within(W, P) | How many times? | no more than 5 emails per hour |
count_distinct_within(k, W, P) | How many different values? | at most 3 distinct payees per hour |
sum_within(a, W, P) | How much in total? | under $500 refunded per day |
bind(n, agg, cond) | Name an aggregate so you can compare it | bind(spent, sum_within(...), spent > 500) |
Temporal clauses compose with ordinary Cedar. Use when temporal { ... } for a purely historical rule, or drop a temporal { ... } marker inline inside a normal when { ... } to require a point-in-time fact and a historical one together.
Pitfalls that cost real time
1. A missing request_context silently flips ALLOW to DENY
Fields a policy reads have to be in both bags: the logged bag on the event (used by temporal predicates) and the request_context(...) envelope (used to build the Cedar request). Supply only one and the other check quietly weakens. Delete the request_context from the @300 event in our trace and:
@300 (time point 3): DENY # was ALLOW - no error, no warning
Nothing in the output tells you why. This is the single most likely thing to burn an afternoon.
2. Action names must be fully qualified everywhere
Events have to use the same qualified form as the policies: Drupe::Action::"IssueRefund", not IssueRefund. A mismatch makes temporal predicates silently fail to match while Cedar may still authorize the action. Same failure mode as above: wrong answer, no error.
3. You cannot do arithmetic on a bound aggregate
A natural way to write "this refund would push us over" is settled + context.input.amount > 500. The parser rejects it:
× unexpected token `+`, expected comparison operator
╭─[23:5]
27 │ settled + context.input.amount > 500)
· ╰──── unexpected token `+`, expected comparison operator
The comparison in bind takes a bare comparison, not an expression. Either threshold on the total alone, or move the arithmetic into a plain Cedar when clause alongside the temporal one.
4. The reference interpreter is not an enforcement engine
AWS is blunt about this and it deserves repeating. The interpreter takes timestamps on faith, does not authenticate events, keeps its trace purely in memory with no eviction or size cap, and loses everything on restart. It exists so you can test what a policy means. Enforcement goes through AgentCore Policy or your own engine.
5. Temporal conditions give up automated reasoning
Cedar's headline property is that it is analyzable: tools can prove things about a policy set without running it. Temporal conditions do not support that analysis yet, and evaluation cost can scale with the length of the event log. Keep plain Cedar wherever plain Cedar is enough; reach for temporal only when the rule genuinely spans calls. Any valid Cedar policy is already a valid Dogwood policy, so there is no migration to do.
6. Provider scripts with the net feature will fetch anything
Information providers are sandboxed Rhai scripts that compute a fact for a policy to read. With the net feature on, http_get performs no host or IP validation at all, including link-local and RFC-1918 addresses. Never build the URL authority from untrusted event fields.
Quick reference
| Task | Command |
|---|---|
| Build the CLI | cargo build --release -p amzn-dogwood-cli |
| Schema from MCP manifest | dogwood schema mcp --manifest tools.json -o schema.cedarschema |
| Type-check a policy | dogwood validate policy.dw --policy-schema schema.cedarschema |
| Syntax only, no schema | dogwood check-parse policy.dw |
| Replay a trace | dogwood replay policy.dw --policy-schema schema.cedarschema --trace trace.log |
| Machine-readable verdicts | add --format json |
| See the generated Cedar | dogwood lower policy.dw --policy-schema schema.cedarschema --emit cedar-policies |
| Check one schema part | dogwood schema action schema.cedarschema |
One more thing worth seeing once. lower shows what actually reaches the Cedar engine:
@id("refund_needs_fresh_approval")
permit(principal, action == Drupe::Action::"IssueRefund", resource)
when { context.policy_0__temporal_0 };
note: this Cedar is NOT self-contained - temporal/provider fields were
hoisted (2 temporal, 0 provider) and need Dogwood at authorize time.
The temporal condition collapses into a synthetic context.* slot that Dogwood fills at authorize time from the event history. That is how it stays compatible with any Cedar-based policy store, and also why you cannot hand the lowered output to a plain Cedar engine and expect the history checks to survive.
Where to take this next
- Turn your traces into tests. A policy bundle is a
policy.dw, aschema.cedarschema, atrace.log, and an expected verdict stream. Diffreplayoutput against the expected file in CI and a policy change that alters behaviour fails the build. AWS runs its own docs this way. - Write the trace you are afraid of. The read-confidential-then-email sequence, the retry storm, the approval reused across two orders. If the replay allows it, you have a policy bug you would otherwise have found in production.
- Try
count_distinct_withinon egress. Capping distinct recipients per hour catches exfiltration patterns that per-call filters miss entirely. - Watch for absolute-time windows and liveness. Every window today is relative and sliding. AWS has flagged wall-clock windows (quotas that reset at midnight) and liveness rules ("an opened resource must eventually be released") as next up.
The deeper shift is worth naming. Point-in-time authorization asks whether an agent may do a thing. Runtime verification asks whether the agent is behaving. As tool calls chain further from the prompt that started them, the second question is the one that matters.
Sources
- Introducing Dogwood: runtime verification for AI agents - AWS Open Source Blog, Aug 6 2026
- dogwood-policy/dogwood - reference parser, interpreter, CLI and guide (Apache 2.0)
- The Dogwood Guide - language reference, CLI, MCP schema generation
- AWS Open-Sources Dogwood, Extending Cedar to Govern Sequences of Agent Tool Calls - InfoQ
Comments
Be the first to comment
Found this useful?
Get new AI guides for builders by email. Free.
Join 3,605 newsletter subscribers.