Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions apps/docs/config/posthog.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Single source of truth for non-sensitive PostHog config.
// The project key stays in env (NEXT_PUBLIC_POSTHOG_KEY) — it is per-deploy.
// Exported as `posthogConfig` (not `posthog`) to avoid colliding with the
// `posthog` default import from "posthog-js" in instrumentation-client.ts.
export const posthogConfig = {
apiHost: "/ingest", // first-party reverse-proxy base path; also builds the rewrite sources
uiHost: "https://us.posthog.com",
ingestHost: "https://us.i.posthog.com",
assetsHost: "https://us-assets.i.posthog.com",
defaults: /** @type {import("posthog-js").ConfigDefaults} */ ("2025-05-24"), // maps 1:1 to posthog-js init() `defaults` option
};
7 changes: 4 additions & 3 deletions apps/docs/instrumentation-client.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import posthog from "posthog-js";
import { posthogConfig } from "@/config/posthog.mjs";

posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
api_host: "/ingest",
ui_host: "https://us.posthog.com",
defaults: "2025-05-24",
api_host: posthogConfig.apiHost,
ui_host: posthogConfig.uiHost,
defaults: posthogConfig.defaults,
capture_exceptions: true, // This enables capturing exceptions using Error Tracking
debug: process.env.NODE_ENV === "development",
});
13 changes: 7 additions & 6 deletions apps/docs/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createMDX } from "fumadocs-mdx/next";
import { posthogConfig } from "./config/posthog.mjs";

const withMDX = createMDX();

Expand Down Expand Up @@ -30,16 +31,16 @@ const config = {
destination: "/llms.mdx/:path*",
},
{
source: "/ingest/static/:path*",
destination: "https://us-assets.i.posthog.com/static/:path*",
source: `${posthogConfig.apiHost}/static/:path*`,
destination: `${posthogConfig.assetsHost}/static/:path*`,
},
{
source: "/ingest/:path*",
destination: "https://us.i.posthog.com/:path*",
source: `${posthogConfig.apiHost}/:path*`,
destination: `${posthogConfig.ingestHost}/:path*`,
},
{
source: "/ingest/decide",
destination: "https://us.i.posthog.com/decide",
source: `${posthogConfig.apiHost}/decide`,
destination: `${posthogConfig.ingestHost}/decide`,
},
];
},
Expand Down
5 changes: 2 additions & 3 deletions apps/examples/src/01-getting-started/agents/agent.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AgentBuilder } from "@iqai/adk";
import z from "zod/v4"; // Ensure its v4!
import { DEFAULT_MODEL } from "../../config";

export function getRootAgent() {
const outputSchema = z.object({
Expand All @@ -12,9 +13,7 @@ export function getRootAgent() {
funFact: z.string().describe("An interesting fact about the city"),
});

return AgentBuilder.withModel(
process.env.LLM_MODEL || "gemini-3-flash-preview",
)
return AgentBuilder.withModel(process.env.LLM_MODEL || DEFAULT_MODEL)
.withOutputSchema(outputSchema)
.build();
}
3 changes: 2 additions & 1 deletion apps/examples/src/02-tools-and-state/agents/agent.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AgentBuilder } from "@iqai/adk";
import dedent from "dedent";
import { DEFAULT_MODEL } from "../../config";
import { addItemTool, viewCartTool } from "./tools";

export function getRootAgent() {
Expand All @@ -9,7 +10,7 @@ export function getRootAgent() {
};

return AgentBuilder.create("shopping_cart_agent")
.withModel(process.env.LLM_MODEL || "gemini-3-flash-preview")
.withModel(process.env.LLM_MODEL || DEFAULT_MODEL)
.withInstruction(
dedent`
You are a shopping cart assistant. Help users manage their cart.
Expand Down
3 changes: 2 additions & 1 deletion apps/examples/src/03-multi-agent-systems/agents/agent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AgentBuilder } from "@iqai/adk";
import { DEFAULT_MODEL } from "../../config";
import { getCustomerAnalyzerAgent } from "./customer-analyzer/agent";
import { getMenuValidatorAgent } from "./menu-validator/agent";
import { getOrderFinalizerAgent } from "./order-finalizer/agent";
Expand All @@ -14,7 +15,7 @@ export function getRootAgent() {
};

return AgentBuilder.create("restaurant_order_system")
.withModel(process.env.LLM_MODEL || "gemini-3-flash-preview")
.withModel(process.env.LLM_MODEL || DEFAULT_MODEL)
.withSubAgents([customerAnalyzer, menuValidator, orderFinalizer])
.withQuickSession({ state: initialState })
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { LlmAgent } from "@iqai/adk";
import dedent from "dedent";
import { DEFAULT_MODEL } from "../../../config";

export function getCustomerAnalyzerAgent() {
return new LlmAgent({
Expand All @@ -10,6 +11,6 @@ export function getCustomerAnalyzerAgent() {
Return the extracted information in a clear, structured format.
`,
outputKey: "customer_preferences",
model: process.env.LLM_MODEL || "gemini-3-flash-preview",
model: process.env.LLM_MODEL || DEFAULT_MODEL,
});
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { LlmAgent } from "@iqai/adk";
import dedent from "dedent";
import { DEFAULT_MODEL } from "../../../config";

export function getMenuValidatorAgent() {
return new LlmAgent({
Expand All @@ -13,6 +14,6 @@ export function getMenuValidatorAgent() {
Check availability and suggest alternatives if needed.
`,
outputKey: "menu_validation",
model: process.env.LLM_MODEL || "gemini-3-flash-preview",
model: process.env.LLM_MODEL || DEFAULT_MODEL,
});
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { LlmAgent } from "@iqai/adk";
import dedent from "dedent";
import { DEFAULT_MODEL } from "../../../config";

export function getOrderFinalizerAgent() {
return new LlmAgent({
Expand All @@ -12,6 +13,6 @@ export function getOrderFinalizerAgent() {

Create final order summary with items, prices ($8-25 per item), total, and prep time (15-45 min).
`,
model: process.env.LLM_MODEL || "gemini-3-flash-preview",
model: process.env.LLM_MODEL || DEFAULT_MODEL,
});
}
5 changes: 2 additions & 3 deletions apps/examples/src/04-persistence-and-sessions/agents/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
createDatabaseSessionService,
InMemoryArtifactService,
} from "@iqai/adk";
import { DEFAULT_MODEL } from "../../config";
import { counterTool, saveCounterReportTool } from "./tools";

export async function getRootAgent() {
Expand All @@ -19,9 +20,7 @@ export async function getRootAgent() {
);
const artifactService = new InMemoryArtifactService();

return await AgentBuilder.withModel(
process.env.LLM_MODEL || "gemini-3-flash-preview",
)
return await AgentBuilder.withModel(process.env.LLM_MODEL || DEFAULT_MODEL)
.withTools(counterTool, saveCounterReportTool)
.withSessionService(sessionService)
.withArtifactService(artifactService)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AgentBuilder, BuiltInCodeExecutor, PlanReActPlanner } from "@iqai/adk";
import dedent from "dedent";
import { DEFAULT_MODEL_STABLE } from "../../config";

/**
* Creates an agent with planning and code execution capabilities.
Expand All @@ -14,7 +15,7 @@ import dedent from "dedent";
*/
export async function getRootAgent() {
return await AgentBuilder.create("code_planner_agent")
.withModel(process.env.LLM_MODEL || "gemini-2.5-flash")
.withModel(process.env.LLM_MODEL || DEFAULT_MODEL_STABLE)
.withDescription("Agent with planning and code execution capabilities")
.withInstruction(
dedent`
Expand Down
3 changes: 2 additions & 1 deletion apps/examples/src/06-mcp-and-integrations/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AgentBuilder, createSamplingHandler, LlmRequest } from "@iqai/adk";
import { DEFAULT_MODEL_STABLE } from "../config";
import { ask } from "../utils";
import { getCoingeckoTools, getGreetingTools } from "./tools";

Expand All @@ -21,7 +22,7 @@ import { getCoingeckoTools, getGreetingTools } from "./tools";
* This bidirectional flow is powerful for complex integrations.
*/
async function main() {
const modelName = process.env.LLM_MODEL || "gemini-2.5-flash";
const modelName = process.env.LLM_MODEL || DEFAULT_MODEL_STABLE;

// Two specialized agents for the sampling handler to route between
const { runner: creativeRunner } = await AgentBuilder.withModel(modelName)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { AgentBuilder } from "@iqai/adk";
import dedent from "dedent";
import { DEFAULT_MODEL } from "../../config";
import { GuardrailsPlugin } from "./plugins";
import { getWeatherTool } from "./tools";

export function getRootAgent() {
const guardrailsPlugin = new GuardrailsPlugin();

return AgentBuilder.create("weather_guardrails_agent")
.withModel(process.env.LLM_MODEL || "gemini-3-flash-preview")
.withModel(process.env.LLM_MODEL || DEFAULT_MODEL)
.withDescription("A weather assistant with guardrails")
.withInstruction(
dedent`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { AgentBuilder } from "@iqai/adk";
import { DEFAULT_MODEL } from "../../config";
import { getWeatherTool } from "./tools";

export function getRootAgent() {
return AgentBuilder.create("weather_agent")
.withModel(process.env.LLM_MODEL || "gemini-3-flash-preview")
.withModel(process.env.LLM_MODEL || DEFAULT_MODEL)
.withTools(getWeatherTool)
.withInstruction("You help users check the weather.")
.build();
Expand Down
3 changes: 2 additions & 1 deletion apps/examples/src/09-memory-system/agents/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
RecallMemoryTool,
VectorStorageProvider,
} from "@iqai/adk";
import { DEFAULT_MODEL_STABLE } from "../../config";

export async function getRootAgent() {
const sessionService = new InMemorySessionService();
Expand All @@ -32,7 +33,7 @@ export async function getRootAgent() {
}),
});

return AgentBuilder.withModel(process.env.LLM_MODEL || "gemini-2.5-flash")
return AgentBuilder.withModel(process.env.LLM_MODEL || DEFAULT_MODEL_STABLE)
.withInstruction(
"You are a helpful assistant. When asked about previous conversations or user preferences, use the recall_memory tool to search your memory. Only use tools that are provided to you.",
)
Expand Down
3 changes: 2 additions & 1 deletion apps/examples/src/09-scheduling/agents/agent.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { AgentBuilder } from "@iqai/adk";
import { DEFAULT_MODEL_STABLE } from "../../config";

export function getReporterAgent() {
return AgentBuilder.create("scheduled_reporter")
.withModel(process.env.LLM_MODEL || "gemini-2.5-flash")
.withModel(process.env.LLM_MODEL || DEFAULT_MODEL_STABLE)
.withInstruction(
"You are a concise status reporter. When asked, generate a short status update with a random fun fact. Keep it to 2-3 sentences.",
)
Expand Down
3 changes: 3 additions & 0 deletions apps/examples/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/** Default models for examples. Override per-run with the LLM_MODEL env var. */
export const DEFAULT_MODEL = "gemini-3-flash-preview";
export const DEFAULT_MODEL_STABLE = "gemini-2.5-flash";
3 changes: 3 additions & 0 deletions apps/starter-templates/shade-agent/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export const envSchema = z.object({
ADK_DEBUG: z.coerce.boolean().default(false),
GOOGLE_API_KEY: z.string(),
LLM_MODEL: z.string().default("gemini-2.5-flash"),
// Optional, not required: a missing value must stay a graceful runtime
// error (handled in the routes), not a fail-at-boot Zod throw.
NEXT_PUBLIC_contractId: z.string().optional(),
});

/**
Expand Down
6 changes: 5 additions & 1 deletion apps/starter-templates/shade-agent/src/routes/ethAccount.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { Hono } from "hono";
import { env } from "../env";
import { Evm } from "../utils/ethereum";

const app = new Hono();

app.get("/", async (c) => {
// Fetch the environment variable inside the route
const contractId = process.env.NEXT_PUBLIC_contractId;
const contractId = env.NEXT_PUBLIC_contractId;
Comment thread
Aliiiu marked this conversation as resolved.
if (!contractId) {
return c.json({ error: "Contract ID not configured" }, 500);
}
try {
// Derive the price pusher Ethereum address
const { address: senderAddress } = await Evm.deriveAddressAndPublicKey(
Expand Down
3 changes: 2 additions & 1 deletion apps/starter-templates/shade-agent/src/routes/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { utils } from "chainsig.js";
import { Contract, JsonRpcProvider } from "ethers";
import { Hono } from "hono";
import { getRootAgent } from "../agents/agent";
import { env } from "../env";
import {
Evm,
ethContractAbi,
Expand All @@ -17,7 +18,7 @@ const app = new Hono();
app.get("/", async (c) => {
try {
// Fetch the environment variable inside the route
const contractId = process.env.NEXT_PUBLIC_contractId;
const contractId = env.NEXT_PUBLIC_contractId;
if (!contractId) {
return c.json({ error: "Contract ID not configured" }, 500);
}
Expand Down
Loading