Agents are the core building blocks of ADK-TS. They encapsulate the logic for processing user input, making decisions, calling tools, and generating responses using Large Language Models (LLMs).
All agents extend from BaseAgent, which provides the foundation for agent lifecycle management, sub-agent hierarchy, and callback systems.
import type { Content } from "@google/genai";import { BaseAgent } from "@iqai/adk";export abstract class BaseAgent { /** * The agent's name. * Must be a valid identifier and unique within the agent tree. * Cannot be "user" (reserved for end-user input). */ name: string; /** * Description of the agent's capability. * Used by models to determine whether to delegate control. */ description: string; /** * The parent agent of this agent. */ parentAgent?: BaseAgent; /** * The sub-agents of this agent. */ subAgents: BaseAgent[]; /** * Callback invoked before the agent runs. */ beforeAgentCallback?: BeforeAgentCallback; /** * Callback invoked after the agent runs. */ afterAgentCallback?: AfterAgentCallback;}
An agent can only be added as a sub-agent once. To reuse agent logic, create multiple instances with different names.
LlmAgent is the primary implementation most developers will use. It extends BaseAgent with LLM-specific capabilities:
import { LlmAgent } from "@iqai/adk";const agent = new LlmAgent({ name: "customer_support", model: "gpt-4o", description: "Handles customer support inquiries", instruction: "You are a friendly customer support agent. Be helpful and concise.", tools: [searchKnowledgeBase, createTicket], subAgents: [billingAgent, technicalAgent],});
LlmAgent seamlessly integrates with tools, automatically handling function calling:
const agent = new LlmAgent({ name: "assistant", model: "gemini-2.5-flash", tools: [ new HttpRequestTool(), new FileOperationsTool(), customTool, ],});
Memory Services
Enable agents to maintain persistent knowledge across conversations:
import { MemoryService, InMemoryStorageProvider } from "@iqai/adk";const memoryService = new MemoryService({ storage: new InMemoryStorageProvider(),});const agent = new LlmAgent({ name: "smart_assistant", model: "gpt-4o", memoryService, // Automatically retrieves relevant memories});
Session Management
Track conversation state and history:
const sessionService = new InMemorySessionService();const agent = new LlmAgent({ name: "chatbot", model: "gemini-2.5-flash",});// Sessions are managed by the Runnerconst session = await sessionService.createSession("my-app", "user-123");