Skip to content

Commit ce68f4b

Browse files
NiallJoeMaherclaude
andcommitted
Add agentRoutingPrompt for full agent routing support
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 1613f8f commit ce68f4b

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

app/(chat)/api/chat/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import {
77
stepCountIs,
88
streamText,
99
} from "ai";
10+
import { unstable_cache as cache } from "next/cache";
11+
import type { ModelCatalog } from "tokenlens/core";
1012
import {
1113
createAnalystAgent,
1214
createPlannerAgent,
1315
createQuizMasterAgent,
1416
createTutorAgent,
1517
} from "@/lib/ai/agents";
1618
import { getWeather } from "@/lib/ai/tools/get-weather";
17-
import { unstable_cache as cache } from "next/cache";
18-
import type { ModelCatalog } from "tokenlens/core";
1919

2020
// Type definition for resumable stream context (feature currently disabled - requires Redis)
2121
type ResumableStreamContext = {

lib/ai/prompts.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,39 @@ import type { ArtifactKind } from "@/components/artifact";
44
export const regularPrompt =
55
"You are a friendly study buddy assistant! Keep your responses concise and helpful.";
66

7+
export const agentRoutingPrompt = `
8+
You are a Study Buddy with specialized agents available as tools. Choose the right agent based on what the user needs:
9+
10+
**tutor** - Explain concepts with examples and analogies
11+
Use for: "explain", "teach me", "how does X work", "what is X", understanding concepts
12+
13+
**quizMaster** - Create quizzes and practice questions (creates interactive flashcard artifact)
14+
Use for: "quiz me", "test my knowledge", "practice questions", "assessment"
15+
16+
**planner** - Create study plans and learning roadmaps (creates interactive study-plan artifact)
17+
Use for: "study plan", "learning roadmap", "how should I learn", "schedule"
18+
19+
**analyst** - Analyze content and extract key insights
20+
Use for: "summarize", "key points", "analyze this", "what's important"
21+
22+
IMPORTANT ROUTING RULES:
23+
1. Match user intent to the most appropriate agent
24+
2. If the request doesn't clearly match an agent, respond conversationally
25+
3. After using an agent, suggest related follow-ups (e.g., after explaining, offer to quiz)
26+
4. You can chain agents - explain first, then offer to create a study plan
27+
28+
CRITICAL: Agents (quizMaster, planner) create their own artifacts automatically. After using these agents:
29+
- Do NOT call createDocument - the artifact is already created
30+
- Do NOT try to display or reformat the agent's output
31+
- Simply acknowledge the artifact was created and offer follow-up suggestions
32+
33+
Example flows:
34+
- "Explain machine learning" → use tutor
35+
- "Quiz me on what we just discussed" → use quizMaster (creates flashcard artifact automatically)
36+
- "Create a study plan for learning Python" → use planner (creates study-plan artifact automatically)
37+
- "Summarize this article" → use analyst
38+
`;
39+
740
export type RequestHints = {
841
latitude: Geo["latitude"];
942
longitude: Geo["longitude"];
@@ -28,7 +61,11 @@ export const systemPrompt = ({
2861
}) => {
2962
const requestPrompt = getRequestPromptFromHints(requestHints);
3063

31-
return `${regularPrompt}\n\n${requestPrompt}`;
64+
if (selectedChatModel === "chat-model-reasoning") {
65+
return `${regularPrompt}\n\n${requestPrompt}`;
66+
}
67+
68+
return `${regularPrompt}\n\n${agentRoutingPrompt}\n\n${requestPrompt}`;
3269
};
3370

3471
export const codePrompt = `

0 commit comments

Comments
 (0)