Examples
Each example below is a complete, realistic scenario you can use as a starting point. Clone the examples repo to run them locally.git clone https://github.com/anima-labs-ai/examples.git
cd examples/<example-name>
# Add your API key, then install dependencies:
pip install -r requirements.txt # Python
# or
npm install # TypeScript
Procurement agent
Creates an agent, sends a purchase order email to a vendor, and stores vendor credentials in the vault for later use.- Python
- TypeScript
Create the agent
from anima import Anima
anima = Anima(api_key="ak_...")
agent = anima.agents.create(name="Procurement Bot")
print(f"Agent: {agent.id}")
Send a purchase order email
anima.messages.send_email(
agent_id=agent.id,
to="vendor@acme-supplies.com",
subject="Purchase Order #1042",
body=(
"Hi,\n\n"
"Please process PO #1042 for 500 units of SKU-9981 at $12.00 each.\n"
"Deliver by 2026-04-15.\n\n"
"Regards,\nProcurement Bot"
),
)
Create the agent
import { Anima } from "@anima-labs/sdk";
const anima = new Anima({ apiKey: "ak_..." });
const agent = await anima.agents.create({ name: "Procurement Bot" });
console.log("Agent:", agent.id);
Send a purchase order email
await anima.messages.sendEmail({
agentId: agent.id,
to: "vendor@acme-supplies.com",
subject: "Purchase Order #1042",
body: [
"Hi,",
"",
"Please process PO #1042 for 500 units of SKU-9981 at $12.00 each.",
"Deliver by 2026-04-15.",
"",
"Regards,",
"Procurement Bot",
].join("\n"),
});
Support bot
Handles an inbound email webhook, fetches CRM credentials from the vault, and sends a reply.- Python
- TypeScript
Register a webhook for inbound email
from anima import Anima
anima = Anima(api_key="ak_...")
webhook = anima.webhooks.create(
url="https://your-app.example.com/webhooks/email",
events=["message.received"],
)
print(f"Webhook: {webhook.id}")
Handle the webhook and retrieve CRM credentials
# In your web framework handler (e.g. FastAPI):
from fastapi import Request
async def handle_webhook(request: Request):
payload = await request.json()
event = payload["event"] # "message.received"
agent_id = payload["data"]["agentId"]
sender = payload["data"]["from"]
body = payload["data"]["body"]
# Search vault for the CRM credential stored earlier
results = anima.vault.search(agent_id=agent_id, query="crm_api_token")
crm_creds = anima.vault.get_credential(
agent_id=agent_id,
credential_id=results[0].id,
)
# ... query your CRM with crm_creds.notes ...
# Reply to the sender
anima.messages.send_email(
agent_id=agent_id,
to=sender,
subject="Re: Your support request",
body=f"Hi, thanks for reaching out! We've logged your request and will follow up shortly.",
)
Register a webhook for inbound email
import { Anima } from "@anima-labs/sdk";
const anima = new Anima({ apiKey: "ak_..." });
const webhook = await anima.webhooks.create({
url: "https://your-app.example.com/webhooks/email",
events: ["message.received"],
});
console.log("Webhook:", webhook.id);
Handle the webhook and retrieve CRM credentials
// Express handler
app.post("/webhooks/email", async (req, res) => {
const { event, data } = req.body;
const { agentId, from: sender, body } = data;
// Search vault for the CRM credential stored earlier
const results = await anima.vault.search({ agentId, query: "crm_api_token" });
const crmCreds = await anima.vault.getCredential({
agentId,
credentialId: results[0].id,
});
// ... query your CRM with crmCreds.notes ...
// Reply to the sender
await anima.messages.sendEmail({
agentId,
to: sender,
subject: "Re: Your support request",
body: "Hi, thanks for reaching out! We've logged your request and will follow up shortly.",
});
res.sendStatus(200);
});
Expense agent
Issues a virtual card with MCC controls, monitors spend, and sends an SMS alert when the daily limit is approached.- Python
- TypeScript
Create an agent and issue a card
from anima import Anima
anima = Anima(api_key="ak_...")
agent = anima.agents.create(name="Expense Bot")
card = anima.cards.create(
agent_id=agent.id,
label="T&E Card — Q2",
currency="usd",
spend_limit_daily=20000, # $200.00
)
print(f"Card issued: {card.id}")
List recent transactions
transactions = anima.cards.list_transactions(
card_id=card.id,
limit=50,
)
total_today = sum(t.amount for t in transactions.data)
print(f"Spent today: ${total_today / 100:.2f}")
Create an agent and issue a card
import { Anima } from "@anima-labs/sdk";
const anima = new Anima({ apiKey: "ak_..." });
const agent = await anima.agents.create({ name: "Expense Bot" });
const card = await anima.cards.create({
agentId: agent.id,
label: "T&E Card — Q2",
currency: "usd",
spendLimitDaily: 20000, // $200.00
});
console.log("Card issued:", card.id);
List recent transactions
const transactions = await anima.cards.listTransactions({
cardId: card.id,
limit: 50,
});
const totalToday = transactions.data.reduce((sum, t) => sum + t.amount, 0);
console.log(`Spent today: $${(totalToday / 100).toFixed(2)}`);
Send an SMS alert when nearing the limit
const ALERT_THRESHOLD = 18000; // $180.00 — 90% of daily limit
if (totalToday >= ALERT_THRESHOLD) {
await anima.phone.sendSms({
agentId: agent.id,
to: "+15555550100",
body: `Expense alert: $${(totalToday / 100).toFixed(2)} of $200.00 daily limit used.`,
});
}
A2A delegation
One agent discovers another via the registry and delegates a purchase task to it.A2A (agent-to-agent) lets autonomous agents collaborate across trust boundaries. The delegating agent resolves the recipient’s DID to verify its identity before sending work.
- Python
- TypeScript
Create the delegating agent
from anima import Anima
anima = Anima(api_key="ak_...")
orchestrator = anima.agents.create(name="Orchestrator")
print(f"Orchestrator: {orchestrator.id}")
Resolve the purchasing agent's DID
# The purchasing agent's DID is known ahead of time or discovered via registry
purchasing_did = "did:anima:ag_purchasing123"
doc = anima.identity.resolve_did(did=purchasing_did)
print(f"Resolved: {doc.id}")
Delegate the purchase task
task = anima.a2a.send_task(
from_agent_id=orchestrator.id,
to_agent_did=purchasing_did,
capability="purchase",
input={
"sku": "SKU-9981",
"quantity": 100,
"max_unit_price_usd": 15.00,
},
timeout_ms=300_000, # 5 minutes
)
print(f"Task sent: {task.id}")
Create the delegating agent
import { Anima } from "@anima-labs/sdk";
const anima = new Anima({ apiKey: "ak_..." });
const orchestrator = await anima.agents.create({ name: "Orchestrator" });
console.log("Orchestrator:", orchestrator.id);
Resolve the purchasing agent's DID
const purchasingDid = "did:anima:ag_purchasing123";
const doc = await anima.identity.resolveDid({ did: purchasingDid });
console.log("Resolved:", doc.id);
Delegate the purchase task
const task = await anima.a2a.sendTask({
fromAgentId: orchestrator.id,
toAgentDid: purchasingDid,
capability: "purchase",
input: {
sku: "SKU-9981",
quantity: 100,
maxUnitPriceUsd: 15.0,
},
timeoutMs: 300_000, // 5 minutes
});
console.log("Task sent:", task.id);
Poll for the result
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
let result = await anima.a2a.getTask({ taskId: task.id });
while (result.status !== "completed" && result.status !== "failed") {
await sleep(5000);
result = await anima.a2a.getTask({ taskId: task.id });
}
if (result.status === "completed") {
console.log("Purchase confirmed:", result.output);
} else {
console.error("Task failed:", result.error);
}
