-
Notifications
You must be signed in to change notification settings - Fork 172
Improved agentic chat #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,10 +1,9 @@ | ||||||||||||||||||||||
| import agenticPipeline from "@/lib/agentic"; | ||||||||||||||||||||||
| import { streamAgenticResponse } from "@/lib/agentic"; | ||||||||||||||||||||||
| import { AgentsetApiError } from "@/lib/api/errors"; | ||||||||||||||||||||||
| import { withPublicApiHandler } from "@/lib/api/handler/public"; | ||||||||||||||||||||||
| import { hostingAuth } from "@/lib/api/hosting-auth"; | ||||||||||||||||||||||
| import { parseRequestBody } from "@/lib/api/utils"; | ||||||||||||||||||||||
| import { DEFAULT_SYSTEM_PROMPT } from "@/lib/prompts"; | ||||||||||||||||||||||
| import { extractTextFromParts } from "@/lib/string-utils"; | ||||||||||||||||||||||
| import { waitUntil } from "@vercel/functions"; | ||||||||||||||||||||||
| import { convertToModelMessages } from "ai"; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
@@ -75,13 +74,8 @@ export const POST = withPublicApiHandler( | |||||||||||||||||||||
| ); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const messages = convertToModelMessages(body.messages); | ||||||||||||||||||||||
| const messagesWithoutQuery = messages.slice(0, -1); | ||||||||||||||||||||||
| const lastMessage = | ||||||||||||||||||||||
| messages.length > 0 | ||||||||||||||||||||||
| ? extractTextFromParts(messages[messages.length - 1]!.content) | ||||||||||||||||||||||
| : null; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if (!lastMessage) { | ||||||||||||||||||||||
| if (messages.length === 0) { | ||||||||||||||||||||||
| throw new AgentsetApiError({ | ||||||||||||||||||||||
| code: "bad_request", | ||||||||||||||||||||||
| message: "Messages must contain at least one message", | ||||||||||||||||||||||
|
|
@@ -116,29 +110,24 @@ export const POST = withPublicApiHandler( | |||||||||||||||||||||
| ? new KeywordStore(hosting.namespace.id) | ||||||||||||||||||||||
| : undefined; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const result = agenticPipeline({ | ||||||||||||||||||||||
| const result = streamAgenticResponse({ | ||||||||||||||||||||||
| model: languageModel, | ||||||||||||||||||||||
| keywordStore, | ||||||||||||||||||||||
| queryOptions: { | ||||||||||||||||||||||
| embeddingModel, | ||||||||||||||||||||||
| vectorStore, | ||||||||||||||||||||||
| topK: hosting.topK, | ||||||||||||||||||||||
| rerank: { | ||||||||||||||||||||||
| model: hosting.rerankConfig?.model, | ||||||||||||||||||||||
| limit: hosting.rerankConfig?.limit ?? 15, | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| includeMetadata: true, | ||||||||||||||||||||||
| embeddingModel, | ||||||||||||||||||||||
| vectorStore, | ||||||||||||||||||||||
| topK: hosting.topK, | ||||||||||||||||||||||
| rerank: { | ||||||||||||||||||||||
| model: hosting.rerankConfig?.model, | ||||||||||||||||||||||
| limit: hosting.rerankConfig?.limit, | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
|
Comment on lines
+119
to
122
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possible issue: rerank object with undefined properties may bypass default reranking. When Consider passing 🔎 Proposed fix- rerank: {
- model: hosting.rerankConfig?.model,
- limit: hosting.rerankConfig?.limit,
- },
+ rerank: hosting.rerankConfig
+ ? {
+ model: hosting.rerankConfig.model,
+ limit: hosting.rerankConfig.limit,
+ }
+ : undefined,📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
| systemPrompt: hosting.systemPrompt ?? DEFAULT_SYSTEM_PROMPT.compile(), | ||||||||||||||||||||||
| temperature: 0, | ||||||||||||||||||||||
| messagesWithoutQuery, | ||||||||||||||||||||||
| lastMessage, | ||||||||||||||||||||||
| messages, | ||||||||||||||||||||||
| afterQueries: (totalQueries) => { | ||||||||||||||||||||||
| incrementUsage(hosting.namespace.id, totalQueries); | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| headers, | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| return result; | ||||||||||||||||||||||
| return result.toUIMessageStreamResponse({ headers }); | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| ); | ||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: agentset-ai/agentset
Length of output: 470
🏁 Script executed:
Repository: agentset-ai/agentset
Length of output: 233
🏁 Script executed:
Repository: agentset-ai/agentset
Length of output: 4819
Add explicit return type to generateAgenticResponse or validate searchResults shape.
The cast
as QueryVectorStoreResult["results"]assumesresponse.searchResultsmatches the expected type, butsearchResultsingenerateAgenticResponseis constructed from tool output without explicit type annotations. Consider explicitly typing the return type ofgenerateAgenticResponseto includesearchResults: QueryVectorStoreResult["results"], or add runtime validation before the cast.🤖 Prompt for AI Agents