e30e75b5d4
Changesets / Create Version PR (push) Has been cancelled
Deploy Shadcn Registry / Deploy Production (push) Has been cancelled
Template Metrics / LOC + Bundle Size (push) Has been cancelled
Code Quality / Oxlint + Oxfmt (push) Has been cancelled
Code Quality / Template Sync (push) Has been cancelled
Code Quality / Build Changed Packages (push) Has been cancelled
Code Quality / Test Changed Packages (push) Has been cancelled
Deploy Expo Example / Deploy Production (push) Has been cancelled
Deploy Ink Example / Deploy Production (push) Has been cancelled
Python Tests / pytest (assistant-stream, 3.10) (push) Has been cancelled
Python Tests / pytest (assistant-stream, 3.12) (push) Has been cancelled
Python Tests / pytest (assistant-ui-sync-server-api, 3.10) (push) Has been cancelled
Python Tests / pytest (assistant-ui-sync-server-api, 3.12) (push) Has been cancelled
51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
import { createAdkApiRoute } from "@assistant-ui/react-google-adk/server";
|
|
import { InMemoryRunner, LlmAgent, FunctionTool } from "@google/adk";
|
|
import { z } from "zod";
|
|
|
|
const weatherTool = new FunctionTool({
|
|
name: "get_weather",
|
|
description: "Get the current weather for a city.",
|
|
parameters: z.object({
|
|
city: z.string().describe("The city name"),
|
|
}),
|
|
execute: async ({ city }) => {
|
|
return {
|
|
city,
|
|
temperature: Math.round(15 + Math.random() * 20),
|
|
condition: ["sunny", "cloudy", "rainy", "snowy"][
|
|
Math.floor(Math.random() * 4)
|
|
],
|
|
};
|
|
},
|
|
});
|
|
|
|
const agent = new LlmAgent({
|
|
name: "assistant",
|
|
model: "gemini-2.5-flash",
|
|
instruction:
|
|
"You are a helpful assistant. You can check the weather for any city using the get_weather tool.",
|
|
tools: [weatherTool],
|
|
});
|
|
|
|
const runner = new InMemoryRunner({ agent, appName: "adk-example" });
|
|
|
|
const sessions = new Map<string, string>();
|
|
|
|
export const POST = createAdkApiRoute({
|
|
runner,
|
|
userId: "user_1",
|
|
sessionId: async () => {
|
|
const userId = "user_1";
|
|
let sessionId = sessions.get(userId);
|
|
if (!sessionId) {
|
|
const session = await runner.sessionService.createSession({
|
|
appName: "adk-example",
|
|
userId,
|
|
});
|
|
sessionId = session.id;
|
|
sessions.set(userId, sessionId);
|
|
}
|
|
return sessionId;
|
|
},
|
|
});
|