Skip to main content

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.
1

Create the agent

from anima import Anima

anima = Anima(api_key="ak_...")

agent = anima.agents.create(name="Procurement Bot")
print(f"Agent: {agent.id}")
2

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"
    ),
)
3

Store vendor credentials in the vault

anima.vault.create_credential(
    agent_id=agent.id,
    name="Acme Vendor Portal",
    type="secure_note",
    notes="s3cr3tP@ssw0rd!",
)
print("Vendor credentials stored.")

Support bot

Handles an inbound email webhook, fetches CRM credentials from the vault, and sends a reply.
1

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}")
2

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.",
    )

Expense agent

Issues a virtual card with MCC controls, monitors spend, and sends an SMS alert when the daily limit is approached.
1

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}")
2

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}")
3

Send an SMS alert when nearing the limit

ALERT_THRESHOLD = 18000  # $180.00 — 90% of daily limit

if total_today >= ALERT_THRESHOLD:
    anima.phone.send_sms(
        agent_id=agent.id,
        to="+15555550100",
        body=f"Expense alert: ${total_today / 100:.2f} 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.
1

Create the delegating agent

from anima import Anima

anima = Anima(api_key="ak_...")

orchestrator = anima.agents.create(name="Orchestrator")
print(f"Orchestrator: {orchestrator.id}")
2

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}")
3

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}")
4

Poll for the result

import time

while True:
    result = anima.a2a.get_task(task_id=task.id)
    if result.status in ("completed", "failed"):
        break
    time.sleep(5)

if result.status == "completed":
    print("Purchase confirmed:", result.output)
else:
    print("Task failed:", result.error)