This demo showcases how action context can provide useful "priming" for a prompt as well as help you secure tool calls and avoid security issues when calling the LLM. When you choose a user above, information about the user is added to the action context which is included in the system prompt that drives the chat as well as the tools that are called.
Each user is in one or more groups. There is an upcomingEvents tool that will list upcoming events that the user can see (only public events and those of their group):
mammals: sloth, koala, and panda are membersslowpokes: sloth and turtle are membersbearish: koala and panda are members// api/route.ts
import { z } from "genkit";
// this example requires beta features
import { genkit } from "genkit/beta";
import { googleAI } from "@genkit-ai/google-genai";
const ai = genkit({
plugins: [googleAI()], // set the GOOGLE_API_KEY env variable
model: googleAI.model('gemini-flash-latest'),
});
import genkitEndpoint from "@/lib/genkit-endpoint";
import { GROUPS, UPCOMING_EVENTS } from "../data";
const upcomingEvents = ai.defineTool(
{
name: "upcomingEvents",
description:
"list upcoming events available for the current user. groupId is optional -- the tool will return all available events if it is not provided",
inputSchema: z.object({
groupId: z
.string()
.optional()
.describe(
'restrict event lookup only to a specific group. use "*" to search for all groups'
),
}),
},
async ({ groupId }, { context }) => {
if (groupId && !context.auth)
return { error: "The user needs to authenticate to see group events." };