Skip to content

Commit 90ece50

Browse files
committed
docs: Migrates Genkit sample apps, integrating them into the larger Firebase corpus of samples. A companion PR, on branch i1521 in the Genkit repo, deletes them from their location in that repo.
MERGE THIS PR BEFORE THAT OTHER ONE.
1 parent b42afaf commit 90ece50

File tree

11 files changed

+264
-210
lines changed

11 files changed

+264
-210
lines changed

genkit/js-schoolAgent/README.md

Lines changed: 100 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,107 @@
1-
## School Agent sample
1+
# School Agent Sample
22

3-
Get started:
3+
A demonstration of a conversational, multi-agent assistant for a school system using GenKit and Google's Gemini Pro. This agent helps parents with attendance reporting and school information queries.
4+
5+
In this example we have a RoutingAgent which is the main, general-purpose agent.
6+
This agent comes equipped with additional specialized agents, that it can hand-off to as needed.
7+
8+
These specialized agents are represented as prompts and embedded as tools to the original agent.
9+
10+
## Agent Tools & Capabilities
11+
12+
- **Agent Structure**:
13+
- `RoutingAgent`: Main entry point and router, handling general queries and delegating to specialized agents
14+
- `AttendanceAgent`: Specialized agent for absence/tardy reporting
15+
- `GradesAgent`: Manages grade-related inquiries and academic performance
16+
17+
Each specialized agent has its own set of tools that are only accessible to that specific agent:
18+
19+
- **AttendanceAgent**:
20+
- `reportAbsence`: Submit absence notifications
21+
- `reportTardy`: Report late arrivals
22+
- **GradesAgent**:
23+
- `getRecentGrades`: Retrieve latest grade information
24+
25+
The main RoutingAgent cannot directly access these specialized tools - it can only access its own tools and delegate to the specialized agents. This means the specialized agent descriptions need to clearly communicate their capabilities, since the main agent relies on these descriptions for appropriate routing.
26+
27+
For example, when the RoutingAgent sees a grade-related query, it needs to know from the GradesAgent's description that it can handle grade lookups, even though it can't directly see the `getRecentGrades` tool.
28+
29+
This architectural pattern:
30+
31+
- Maintains clear separation of concerns
32+
- Allows specialized agents to evolve independently
33+
- Allows scaling up to a larger number of tools
34+
35+
NOTE: The agent description is how the generalized agent knows what tools the specialized agent has available. An agent description that is too general may cause the routing agent to mess up by not knowing that a certain functionality was actually available.
36+
37+
## Prerequisites
38+
39+
- Node.js and genkit CLI installed
40+
- Google AI API key
41+
42+
## Getting Started
43+
44+
1. Install dependencies:
45+
46+
```bash
47+
npm install
48+
```
49+
50+
2. Set up your Google AI API key:
451

552
```bash
6-
npm i
53+
export GOOGLE_GENAI_API_KEY=your_api_key_here
54+
```
755

8-
export GOOGLE_GENAI_API_KEY=...
56+
3. Start the development server:
957

58+
```bash
1059
npm run genkit:dev
1160
```
61+
62+
In your terminal, a commandline chat interface should show up:
63+
64+
```
65+
Telemetry API running on http://localhost:4033
66+
Genkit Developer UI: http://localhost:4000
67+
68+
> school-agent@1.0.0 dev
69+
> tsx --no-warnings --watch src/terminal.ts
70+
71+
bell> Hi there, my name is Bell and I'm here to help! 👋🎉 I'm your friendly AI assistant for parents of Sparkyville High School. I can answer your questions about the school, events, grades, and more. Just ask me! 😊
72+
73+
prompt> [insert your chats here]
74+
```
75+
76+
You can feel free to tweak the sample. The project builds in watch mode, so any changes will be picked up immediately and should restart the conversation.
77+
78+
## Usage
79+
80+
The agent uses a multi-agent architecture:
81+
82+
- Routing Agent: Acts as the main entry point and router, handling general queries while delegating specialized requests to appropriate agents
83+
- Attendance Agent: Specialized agent focused on absence and tardy reporting
84+
- Grades Agent: Manages academic performance queries, grade reports, and transcript requests
85+
86+
Example queries:
87+
88+
- "Evelyn will be late today"
89+
- "What are the upcoming holidays I should be aware of?"
90+
- "Show me my child's current grades"
91+
92+
## Development
93+
94+
- `npm run dev` - Run in development mode with hot reloading
95+
- `npm run build` - Build the project
96+
- `npm start` - Run the built version
97+
98+
## Project Structure
99+
100+
- `src/`
101+
- `agents/`
102+
- `routingAgent.ts` - Main agent that uses other agents as tools
103+
- `attendanceAgent.ts` - Specialized attendance agent
104+
- `gradesAgent.ts` - Academic performance and grades agent
105+
- `tools.ts` - Tool definitions
106+
- `types.ts` - TypeScript types
107+
- `data.ts` - Sample data

genkit/js-schoolAgent/package.json

Lines changed: 0 additions & 33 deletions
This file was deleted.

genkit/js-schoolAgent/prompts/myPrompt.prompt

Lines changed: 0 additions & 1 deletion
This file was deleted.

genkit/js-schoolAgent/src/attendanceAgent.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,30 @@
1616

1717
import { ai } from './genkit.js';
1818
import { reportAbsence, reportTardy } from './tools.js';
19+
import { agentDescription } from './util.js';
20+
21+
const tools = [reportAbsence, reportTardy, 'routingAgent'];
22+
const specialization = 'attendance';
23+
24+
const toolNames: string[] = tools.map((item) => {
25+
if (typeof item === 'string') {
26+
return item;
27+
} else {
28+
return item.name;
29+
}
30+
});
1931

2032
export const attendanceAgent = ai.definePrompt(
2133
{
22-
name: 'attendanceAgent',
23-
description:
24-
'transfer to this agent when the user asks questions about attendance-related concerns like tardies or absences. do not mention that you are transferring, just do it',
25-
tools: [reportAbsence, reportTardy],
34+
name: `${specialization}Agent`,
35+
description: agentDescription(specialization, toolNames),
36+
tools,
2637
},
2738
` {{ role "system"}}
28-
You are Bell, a helpful attendance assistance agent for Sparkyville High School. A parent has been referred to you to handle an attendance-related concern. Use the tools available to you to assist the parent.
39+
40+
You are Bell, a helpful attendance assistance agent for Sparkyville High School.
41+
A parent has been referred to you to handle a ${specialization}-related concern.
42+
Use the tools available to you to assist the parent.
2943
3044
- Parents may only report absences for their own students.
3145
- If you are unclear about any of the fields required to report an absence or tardy, request clarification before using the tool.

genkit/js-schoolAgent/src/data.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,35 @@ export const EXAMPLE_EVENTS = [
6262
grades: [9, 10, 11, 12],
6363
},
6464
];
65+
66+
export interface GradeEntry {
67+
studentId: number;
68+
subject: string;
69+
grade: string;
70+
date: string;
71+
assignment: string;
72+
}
73+
74+
export const EXAMPLE_GRADES: GradeEntry[] = [
75+
{
76+
studentId: 3734,
77+
subject: 'Mathematics',
78+
grade: 'A-',
79+
date: '2024-03-01',
80+
assignment: 'Quadratic Equations Quiz',
81+
},
82+
{
83+
studentId: 3734,
84+
subject: 'English',
85+
grade: 'B+',
86+
date: '2024-03-05',
87+
assignment: 'Essay: Shakespeare Analysis',
88+
},
89+
{
90+
studentId: 9433,
91+
subject: 'Physics',
92+
grade: 'A',
93+
date: '2024-03-02',
94+
assignment: 'Forces Lab Report',
95+
},
96+
];

genkit/js-schoolAgent/src/genkit.ts

Lines changed: 0 additions & 38 deletions
This file was deleted.

genkit/js-schoolAgent/src/infoAgent.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)