Agent actions¶
These actions address the CRDT doc.agents map. They are distinct from the
legacy Agent convenience class documented in the API section.
| Type | Payload | Result / effect |
|---|---|---|
agent:create |
{ id?, name, meta? } |
Creates and returns an agent |
agent:remove |
{ name } |
Deletes an agent |
agent:setActive |
{ name, active? } |
Sets active state |
agent:giveResource |
{ name, resource, amount? } |
Adds a resource amount |
agent:takeResource |
{ name, resource, amount? } |
Subtracts, clamped at zero |
agent:addToken |
{ name, token } |
Adds a token to inventory |
agent:removeToken |
{ name, tokenId } |
Removes and returns a token |
agent:get |
{ name } |
Returns a materialized agent |
agent:getAll |
none | Returns materialized agents |
agent:transferResource |
{ from, to, resource, amount? } |
Atomic resource transfer |
agent:transferToken |
{ from, to, tokenId } |
Moves a token and records a transaction |
agent:stealResource |
{ from, to, resource, amount? } |
Transfers up to the source balance |
agent:stealToken |
{ from, to, tokenId } |
Moves a token and records a steal |
agent:trade |
{ agent1, agent2, offer1, offer2 } |
Exchanges validated resources/tokens |
agent:drawCards |
{ name, count? } |
Draws from the attached stack into inventory |
agent:setMeta |
{ name, key, value } |
Writes one metadata key |
agent:discardCards |
{ name, tokenIds } |
Removes listed inventory tokens into stack discards |
Unknown agents, missing tokens, and insufficient balances throw. Values crossing the Automerge boundary must be compatible with its JSON-like document model.