|
| 1 | +--- |
| 2 | +title: Backend Actions |
| 3 | +icon: "lucide/Server" |
| 4 | +description: Enable AI agents to execute server-side operations, access databases, and integrate with external services. |
| 5 | +--- |
| 6 | +import { RocketIcon } from "lucide-react"; |
| 7 | + |
| 8 | +## What are Backend Actions? |
| 9 | + |
| 10 | +Backend Actions are server-side functions that AI agents can call to perform operations that require backend resources, such as database queries, API calls, file operations, or complex computations. They extend agent capabilities beyond the frontend to access the full power of your server infrastructure. |
| 11 | + |
| 12 | +Unlike frontend actions that modify UI state, backend actions handle data processing, external integrations, and operations that require server-side security or resources. |
| 13 | + |
| 14 | +<Callout> |
| 15 | +**Ready to get started with Backend Actions?** |
| 16 | + |
| 17 | + <div className="flex items-center gap-6"> |
| 18 | + <div className="flex-shrink-0"> |
| 19 | + <a |
| 20 | + href="/direct-to-llm/guides/backend-actions" |
| 21 | + className="flex flex-col items-center gap-1 text-center no-underline group" |
| 22 | + > |
| 23 | + <div className="w-12 h-12 flex items-center justify-center rounded-2xl transition-all duration-200 group-hover:scale-105 bg-gradient-to-b from-green-700 to-green-400 text-green-100"> |
| 24 | + <RocketIcon className="w-8 h-8" /> |
| 25 | + </div> |
| 26 | + <span className="text-sm font-medium text-zinc-700 dark:text-zinc-300 group-hover:text-black dark:group-hover:text-white transition-colors duration-200"> |
| 27 | + Direct to LLM |
| 28 | + </span> |
| 29 | + </a> |
| 30 | + </div> |
| 31 | + <div className="flex-1"> |
| 32 | + <p className="text-base leading-relaxed mb-4"> |
| 33 | + Backend Actions are primarily designed for Direct to LLM applications, where you need explicit server-side functions that the LLM can call. CopilotKit provides multiple implementation approaches. |
| 34 | + </p> |
| 35 | + </div> |
| 36 | + </div> |
| 37 | +</Callout> |
| 38 | + |
| 39 | +<div className="grid grid-cols-1 md:grid-cols-2 gap-8"> |
| 40 | + |
| 41 | +<div> |
| 42 | + |
| 43 | +## Common Backend Action Patterns |
| 44 | + |
| 45 | +### **Database Operations** |
| 46 | +Actions that create, read, update, or delete data from databases, often with complex queries and relationships. |
| 47 | + |
| 48 | +### **API Integrations** |
| 49 | +Actions that call external APIs, process responses, and integrate data from third-party services. |
| 50 | + |
| 51 | +### **File Operations** |
| 52 | +Actions that handle file uploads, downloads, processing, or storage operations on the server. |
| 53 | + |
| 54 | +### **Authentication and Authorization** |
| 55 | +Actions that manage user authentication, permissions, and access control for sensitive operations. |
| 56 | + |
| 57 | +### **Data Processing** |
| 58 | +Actions that perform data transformation, analysis, aggregation, or complex computations. |
| 59 | + |
| 60 | +### **Workflow Orchestration** |
| 61 | +Actions that coordinate multiple backend services or trigger complex business processes. |
| 62 | + |
| 63 | +</div> |
| 64 | + |
| 65 | +<div> |
| 66 | + |
| 67 | +## Types of Backend Actions |
| 68 | + |
| 69 | +### **Synchronous Actions** |
| 70 | +Actions that execute and return results immediately, suitable for quick database queries or simple API calls. |
| 71 | + |
| 72 | +### **Asynchronous Actions** |
| 73 | +Actions that handle long-running operations, often with progress tracking and completion notifications. |
| 74 | + |
| 75 | +### **Streaming Actions** |
| 76 | +Actions that return data progressively, useful for real-time updates or large data sets. |
| 77 | + |
| 78 | +### **Batch Actions** |
| 79 | +Actions that process multiple items or operations together for efficiency. |
| 80 | + |
| 81 | +### **Transactional Actions** |
| 82 | +Actions that ensure data consistency across multiple operations, with rollback capabilities on failure. |
| 83 | + |
| 84 | +</div> |
| 85 | + |
| 86 | +</div> |
| 87 | + |
| 88 | +## When to Use Backend Actions |
| 89 | + |
| 90 | +Consider Backend Actions when agents need to: |
| 91 | + |
| 92 | +- **Access sensitive data** that shouldn't be exposed to the frontend |
| 93 | +- **Perform complex queries** across multiple data sources |
| 94 | +- **Integrate with external services** requiring server-side authentication |
| 95 | +- **Execute business logic** that involves multiple systems |
| 96 | +- **Process large amounts of data** efficiently |
| 97 | +- **Maintain data consistency** across operations |
| 98 | +- **Handle file operations** or media processing |
| 99 | +- **Implement security controls** and access management |
| 100 | + |
| 101 | +### **Agent Framework Applications** |
| 102 | + |
| 103 | +Agent frameworks (LangGraph, CrewAI, LlamaIndex, etc.) typically handle backend operations through their native agent architectures rather than explicit backend actions. These frameworks provide their own mechanisms for: |
| 104 | + |
| 105 | +- Tool calling and external service integration |
| 106 | +- Database access and data manipulation |
| 107 | +- Complex workflow orchestration |
| 108 | +- Multi-step reasoning and planning |
| 109 | + |
| 110 | +For agent-based applications, backend functionality is usually implemented as **agent tools** or **framework-specific integrations** rather than CopilotKit backend actions. |
0 commit comments