From: aidotengineer
Building AI Agents with Primitives
Building AI agents that are production-ready and scalable often involves using AI primitives rather than frameworks [00:01:01]. Frameworks can be bloated, slow-moving, and filled with unnecessary abstractions [00:01:21]. Primitives, on the other hand, have a native ability to work well in production and scale massively, similar to Amazon S3 as an object storage primitive [00:02:29].
AI agents are considered a new way of writing code, changing how projects and SaaS are built [00:03:32]. Instead of large frameworks, the focus should be on small, composable building blocks that are useful across the stack [00:03:56]. Langbase aims to provide the fastest way to build production-ready AI agents by leveraging predefined, highly scalable, and composable AI primitives [00:04:45].
Key AI primitives include:
- Memory: An autonomous “drag engine” that can scale to store terabytes of data, often with a vector store for similarity search [00:05:24], [00:10:28].
- Workflow Engine: Purpose-built for multi-step agent workflows [00:10:30].
- Threads: For storing and managing context and conversation history for agents [00:04:01], [00:10:35].
- Parser: To extract context from various file types, like converting PDF to text [00:08:14], [00:10:40].
- Chunker: To split extracted text into smaller pieces of context for efficient processing [00:08:20], [00:10:43].
- Tools Infrastructure: For agents to automatically call external APIs or services [00:11:33].
By using these primitives, developers can build serverless AI agents that handle heavy lifting automatically [00:05:37].
Agent Orchestration
Agent orchestration involves a primary agent managing and coordinating the tasks of multiple other agents. This is crucial for complex problems that require a division of labor.
Agent Router Architecture
An “Agent Router” or “LLM Router” is an architectural pattern where an agent or LLM decides which other specialized agent needs to be called next [00:14:00]. This allows for dynamic routing of tasks to agents best suited for the job.
Example Implementation: An example involves three specialized agents:
- Summary Agent: Uses Gemini for summarizing text [00:14:41].
- Reasoning Agent: Uses DeepSeek Llama 70B for analysis and explanations [00:14:43].
- Coding Agent: Uses Claude Sonnet for writing code [00:14:47].
A “routing agent” is instructed on its job, has access to all these specialized agents, and responds with valid JSON, picking the appropriate agent for a given task [00:15:06]. For instance, given the task “Why days are shorter in winter,” the router correctly decides to run the reasoning agent [00:15:56].
Agent Orchestrator Worker Architecture
This is a more sophisticated form of orchestration where a single orchestrator agent plans and creates subtasks for multiple worker agents [00:17:13]. The results from these worker agents are then synthesized by another agent to form a final output [00:17:24]. This architecture is similar to a “deep research agent” [00:17:30].
Example Implementation: To write a blog post on “benefits of remote work” covering productivity, work-life balance, and environmental impact:
- The orchestrator agent generates a list of subtasks: writing the introduction, sections on productivity, work-life balance, environmental impact, and a conclusion [00:18:10].
- These subtasks are distributed among individual worker agents, each completing one part [00:18:44].
- Finally, a synthesizing agent combines all the completed subtasks into the full blog post [00:19:02].
This pattern can be implemented in about 90 lines of code without a complex framework [00:19:08].
Parallel Processing of Agents
Running AI agents in parallel is another common architecture that leverages primitives for simplicity.
Implementation:
In JavaScript, a set of agents (e.g., a sentiment agent, a summary agent, a decision-maker agent) can be run concurrently using Promise.all
[00:16:47]. This allows multiple agents to process different aspects of an input simultaneously, significantly speeding up the overall workflow.
Benefits of Primitives for Advanced Architectures
Using AI primitives for agent orchestration and parallel processing offers significant advantages:
- Flexibility: It avoids being stuck with abstractions from bloated frameworks, which is crucial in a fast-moving space with new LLM paradigms emerging constantly [00:25:51].
- Scalability: Primitives like
langbase.memories
are designed to scale automatically, handling large amounts of data without manual intervention [00:05:33]. - Control: Developers retain full control over their code, as there’s no “magic” or new concepts to learn beyond standard programming practices [00:15:37].
- Debugging: Building on primitives makes debugging much easier compared to navigating obscure abstractions found in frameworks [00:05:05].
By building with primitives, developers can quickly build, deploy, and use production-ready agents that scale, rather than creating “silly demos” that may not [00:26:39].