Integrating Anima with LLM Frameworks

A guide to exposing Anima identity capabilities as tools for LangChain, CrewAI, and AutoGen agents to perform multi-step workflows.

Anima Team2 min read
#tutorial#llm#integration

LLM frameworks like LangChain, CrewAI, and AutoGen excel at orchestrating complex tasks but often lack native infrastructure for identity-based operations like sending emails, making calls, or handling payments. Anima provides this missing link by exposing identity capabilities as modular tools.

Defining Anima Tools for LangChain#

LangChain's tool abstraction is ideal for wrapping Anima SDK functions. Each tool provides a description that helps the LLM decide when and how to invoke it.

import { Anima } from "@anima/sdk";
import { DynamicTool } from "langchain/tools";
 
const am = new Anima(process.env.AM_API_KEY);
 
const emailTool = new DynamicTool({
  name: "send_email",
  description: "Sends an email from the agent's identity. Parameters: recipient, subject, body.",
  func: async ({ recipient, subject, body }) => {
    const response = await am.email.send({
      identityId: "agent_789",
      to: recipient,
      subject: subject,
      text: body
    });
    return `Email sent: ${response.id}`;
  }
});

Orchestrating Multi-Step Workflows#

With Anima tools, an agent can perform workflows that span multiple identity channels. For example, an agent could check a vault for a database credential, read an email for a user request, and then make a phone call to confirm an action.

import { ChatOpenAI } from "@langchain/openai";
import { initializeAgentExecutorWithOptions } from "langchain/agents";
 
const model = new ChatOpenAI({ temperature: 0 });
const tools = [emailTool, vaultTool, voiceTool];
 
const executor = await initializeAgentExecutorWithOptions(tools, model, {
  agentType: "openai-functions"
});
 
const result = await executor.call({
  input: "Find the AWS credentials in my vault, send a summary email to dev@org.com, and call +15550123456 to confirm completion."
});

Integrating with CrewAI and AutoGen#

For multi-agent systems like CrewAI, Anima capabilities can be assigned to specialized agents. A 'Financial Agent' might have card-issuing tools, while a 'Communication Agent' handles email and voice.

# Example for exposing Anima tools via MCP for AutoGen
npx @anima/mcp install --identity-id agent_abc --capabilities email,vault

Handling Tool Call Results and Failures#

Robust integration requires handling the specific failure modes of identity infrastructure. If a phone call is busy or an email bounces, the agent should receive this feedback as part of its tool execution history.

try {
  const status = await am.voice.calls.get(callId);
  if (status.state === "failed") {
    return "Call failed: line busy. Retrying in 5 minutes.";
  }
} catch (error) {
  return `Error accessing voice infrastructure: ${error.message}`;
}

Security Scoping for Tools#

Always scope your LLM tools to the minimum set of permissions required for the task. Use Anima's API key management to create scoped keys that only have access to specific identities or capabilities, limiting the potential impact of an LLM hallucination or prompt injection.

By providing AI agents with reliable identity infrastructure, you enable them to move beyond simple text generation into autonomous, real-world execution.

Stay Updated

Get the latest on AI agent identity, delivered weekly.