Skip to content

Commit cb82a69

Browse files
committed
Final AI Agent Implementation
1 parent 9cc4ecd commit cb82a69

File tree

7 files changed

+46
-71
lines changed

7 files changed

+46
-71
lines changed
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from google.adk.agents import Agent, LoopAgent
1+
from google.adk.agents import Agent
22

33
quizzes_agent = Agent(
44
name="Quizzes_Agent",
@@ -50,7 +50,7 @@
5050
- Format extracted references clearly and organized
5151
- Include page numbers, dates, and other citation details when available
5252
53-
Provide a comprehensive list of all references related to the content provided to you. Make sure that you include at least 5 references."""
53+
Provide a comprehensive list of all references related to the content provided to you."""
5454
)
5555
)
5656

@@ -73,8 +73,8 @@
7373
)
7474
)
7575

76-
manager_agent = Agent(
77-
name="EduAssistant_Manager_Agent",
76+
root_agent = Agent(
77+
name="Manager_Agent",
7878
model="gemini-2.0-flash",
7979
description=(
8080
"This AI agent functions as an orchestrator and coordinator in a multi-agent system designed to answer queries based on domain-specific content provided to it. Its primary role is to manage the interactions between multiple specialized agents and ensure accurate, context-aware, and efficient responses to user queries."
@@ -101,7 +101,5 @@
101101
102102
When users ask for specific functions, delegate to the appropriate agent and provide the results in a clear, helpful format asked by the user."""
103103
),
104-
sub_agents=[quizzes_agent, reference_agent, flash_card_agent, summarizer_agent],
104+
sub_agents=[quizzes_agent, reference_agent, flash_card_agent, summarizer_agent]
105105
)
106-
107-
root_agent = manager_agent

frontend/src/ai/flows/generate-flashcards.ts

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {genkit} from 'genkit';
1212
import {googleAI} from '@genkit-ai/googleai';
1313
import {z} from 'genkit';
1414
import { extractJsonFromResponse } from './flow_utils';
15+
import { useAuth } from '@/contexts/AuthContext';
1516

1617
const ai = genkit({
1718
plugins: [googleAI()],
@@ -37,31 +38,22 @@ export async function generateFlashcards(input: GenerateFlashcardsInput): Promis
3738
// Use ADK /run endpoint with configurable backend URL
3839
const ADK_URL = process.env.NEXT_PUBLIC_AGENT_API_URL || "http://localhost:8000";
3940
try {
41+
const { user, signOut } = useAuth();
42+
const userId = user || 'u_123'; // TODO: Get from AuthContext
43+
const sessionId = localStorage.getItem('sessionId') || 's_' + Math.random().toString(36).substr(2, 9);
44+
4045
const res = await fetch(`${ADK_URL}/run`, {
4146
method: "POST",
4247
headers: { "Content-Type": "application/json" },
4348
body: JSON.stringify({
44-
input: `Create flashcards for this content: ${input.courseMaterial}`,
45-
metadata: {
46-
request_type: "flashcards",
47-
course_material: input.courseMaterial,
48-
output_schema: {
49-
type: "object",
50-
properties: {
51-
flashcards: {
52-
type: "array",
53-
items: {
54-
type: "object",
55-
properties: {
56-
front: { type: "string" },
57-
back: { type: "string" }
58-
},
59-
required: ["front", "back"]
60-
}
61-
}
62-
},
63-
required: ["flashcards"]
64-
}
49+
appName: "EduAssistant_Agents",
50+
userId: userId,
51+
sessionId: sessionId,
52+
newMessage: {
53+
role: "user",
54+
parts: [{
55+
text: `Create flashcards for this content. Please format your response as a JSON object with a 'flashcards' array. Each flashcard should have a 'front' (string) and 'back' (string) field. Here's the content: ${input.courseMaterial}\n\nFormat your response as: {\"flashcards\": [{\"front\": \"...\", \"back\": \"...\"}]}`
56+
}]
6557
}
6658
})
6759
});

frontend/src/ai/flows/generate-quizzes.ts

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import {ai} from '@/ai/genkit';
1313
import {z} from 'genkit';
1414
import { extractJsonFromResponse } from './flow_utils';
15+
import { useAuth } from '@/contexts/AuthContext';
1516

1617
const GenerateQuizzesInputSchema = z.object({
1718
courseMaterial: z
@@ -41,35 +42,23 @@ export async function generateQuizzes(
4142
// Use ADK /run endpoint with configurable backend URL
4243
const ADK_URL = process.env.NEXT_PUBLIC_AGENT_API_URL || "http://localhost:8000";
4344
try {
45+
const { user, signOut } = useAuth();
46+
47+
const userId = user || 'u_123'; // TODO: Get from AuthContext
48+
const sessionId = localStorage.getItem('sessionId') || 's_' + Math.random().toString(36).substr(2, 9);
49+
4450
const res = await fetch(`${ADK_URL}/run`, {
4551
method: "POST",
4652
headers: { "Content-Type": "application/json" },
4753
body: JSON.stringify({
48-
input: `Generate ${input.numQuestions} quiz questions based on this content: ${input.courseMaterial}`,
49-
metadata: {
50-
request_type: "quizzes",
51-
course_material: input.courseMaterial,
52-
output_schema: {
53-
type: "object",
54-
properties: {
55-
quiz: {
56-
type: "array",
57-
items: {
58-
type: "object",
59-
properties: {
60-
question: { type: "string" },
61-
options: {
62-
type: "array",
63-
items: { type: "string" }
64-
},
65-
correctAnswer: { type: "string" }
66-
},
67-
required: ["question", "options", "correctAnswer"]
68-
}
69-
}
70-
},
71-
required: ["quiz"]
72-
}
54+
appName: "EduAssistant_Agents",
55+
userId: userId,
56+
sessionId: sessionId,
57+
newMessage: {
58+
role: "user",
59+
parts: [{
60+
text: `Generate ${input.numQuestions} quiz questions based on this content. Please format your response as a JSON object with a 'quiz' array. Each quiz item should have: a 'question' (string), an 'options' array (array of 4 strings), and a 'correctAnswer' (string, must match one of the options). Here's the content: ${input.courseMaterial}\n\nPlease ensure each question has 4 distinct options and the correct answer is one of the provided options. Format your response as a JSON object with the structure: {\"quiz\": [{\"question\": \"...\", \"options\": [\"...\", \"...\", \"...\", \"...\"], \"correctAnswer\": \"...\"}]}`
61+
}]
7362
}
7463
})
7564
});

frontend/src/ai/flows/suggest-resources.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import {ai} from '@/ai/genkit';
1212
import {z} from 'genkit';
1313
import { extractJsonFromResponse } from './flow_utils';
14+
import { useAuth } from '@/contexts/AuthContext';
1415

1516
const SuggestResourcesInputSchema = z.object({
1617
courseContent: z
@@ -32,26 +33,22 @@ export async function suggestResources(input: SuggestResourcesInput): Promise<Su
3233
// Use ADK /run endpoint with configurable backend URL
3334
const ADK_URL = process.env.NEXT_PUBLIC_AGENT_API_URL || "http://localhost:8000";
3435
try {
36+
const { user, signOut } = useAuth();
37+
const userId = user || 'u_123'; // TODO: Get from AuthContext
38+
const sessionId = localStorage.getItem('sessionId') || 's_' + Math.random().toString(36).substr(2, 9);
39+
3540
const res = await fetch(`${ADK_URL}/run`, {
3641
method: "POST",
3742
headers: { "Content-Type": "application/json" },
3843
body: JSON.stringify({
39-
input: `Take this content and give me reference links for this content: ${input.courseContent}`,
40-
metadata: {
41-
request_type: "suggest_resources",
42-
course_content: input.courseContent,
43-
output_schema: {
44-
type: "array",
45-
items: {
46-
type: "object",
47-
properties: {
48-
title: { type: "string" },
49-
url: { type: "string", format: "uri" },
50-
reason: { type: "string" }
51-
},
52-
required: ["title", "url", "reason"]
53-
}
54-
}
44+
appName: "EduAssistant_Agents",
45+
userId: userId,
46+
sessionId: sessionId,
47+
newMessage: {
48+
role: "user",
49+
parts: [{
50+
text: `Suggest 3-5 relevant study resources for this content. For each resource, provide a title, URL, and a brief reason why it's relevant. Format your response as a JSON array of objects with 'title' (string), 'url' (string, must be a valid URL), and 'reason' (string) fields. Here's the content: ${input.courseContent}\n\nFormat your response like this: [{\"title\": \"...\", \"url\": \"https://...\", \"reason\": \"...\"}]`
51+
}]
5552
}
5653
})
5754
});

frontend/src/app/dashboard/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default function DashboardPage() {
5050

5151

5252
const makeSession = async () => {
53-
const session = await fetch('http://localhost:8000/apps/EduAssitant_Agents/users/' + userID + '/sessions/s_123', {
53+
const session = await fetch('http://localhost:8000/apps/EduAssistant_Agents/users/' + userID + '/sessions/s_123', {
5454
method: 'POST',
5555
headers: {
5656
'Content-Type': 'application/json',

frontend/src/components/dashboard/FlashcardGenerator.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import type { Flashcard as FlashcardType } from '@/types';
1111
import { Loader2, Copy, RotateCcw, Check, FileText, Lightbulb } from 'lucide-react';
1212
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card';
1313
import { AnimatePresence, motion } from 'framer-motion';
14-
import { cn } from '@/lib/utils';
1514

1615
function Flashcard({ card, isFlipped, onFlip }: { card: FlashcardType; isFlipped: boolean; onFlip: () => void; }) {
1716
return (

0 commit comments

Comments
 (0)