Skip to main content

Overview

This example demonstrates the fundamentals of creating an AI agent with ADK-TS. You’ll learn how to:
  • Structure your agent code in a recommended folder layout
  • Define structured output using Zod schemas
  • Get fully-typed responses from your agent
This is the “Hello World” of ADK-TS, but it showcases best practices you’ll use in production applications.

Complete Example

1
Step 1: Define Your Agent
2
Create an agent with a structured output schema:
3
import { AgentBuilder } from "@iqai/adk";
import z from "zod/v4"; // Ensure its v4!

export function getRootAgent() {
	const outputSchema = z.object({
		capital: z.string().describe("The capital city name"),
		country: z.string().describe("The country name"),
		population: z
			.number()
			.optional()
			.describe("Population of the capital city"),
		funFact: z.string().describe("An interesting fact about the city"),
	});

	return AgentBuilder.withModel(
		process.env.LLM_MODEL || "gemini-3-flash-preview",
	)
		.withOutputSchema(outputSchema)
		.build();
}
4
Always use zod/v4 for schema validation in ADK-TS. The framework is optimized for Zod v4’s features.
5
Step 2: Use Your Agent
6
Consume the agent in your application:
7
import dedent from "dedent";
import { getRootAgent } from "./agents/agent";

async function main() {
	const { runner } = await getRootAgent();

	const question = "Give me stats about France";
	const response = await runner.ask(question);

	console.log(`👤 User: ${question}`);

	console.log(
		dedent`
		🤖 Agent:

		🌍 Country:    ${response.country}
		📍 Capital:    ${response.capital}
		👥 Population: ${response.population ? response.population.toLocaleString() : "N/A"}
		🎉 Fun fact:   ${response.funFact}
		`,
	);
}

main().catch(console.error);
8
Step 3: Run the Example
9
node index.ts

Expected Output

👤 User: Give me stats about France

🤖 Agent:

🌍 Country:    France
📍 Capital:    Paris
👥 Population: 2,165,423
🎉 Fun fact:   Paris is known as the "City of Light" because it was one of the first cities in the world to have street lighting

Key Concepts

Structured Output with Zod

The withOutputSchema() method ensures your agent returns data in a specific format:
  • Type Safety: TypeScript knows exactly what fields are available
  • Validation: Responses are automatically validated against your schema
  • Documentation: Descriptions help the LLM understand what to generate
project/
├── agents/
│   └── agent.ts       # Agent definitions
└── index.ts           # Application entry point
As your application grows, you’ll add tools.ts, plugins.ts, and other files to the agents/ folder. This structure keeps your code organized and maintainable.

Model Selection

You can use any supported LLM provider:
// Google Gemini
AgentBuilder.withModel("gemini-3-flash-preview")

// OpenAI
AgentBuilder.withModel("gpt-4o")

// Anthropic
AgentBuilder.withModel("claude-3-5-sonnet-20241022")

Next Steps

Tools & State

Add custom tools and manage agent state

Multi-Agent Systems

Coordinate multiple agents to handle complex tasks

Source Code

View the complete example in the repository: apps/examples/src/01-getting-started

Build docs developers (and LLMs) love