Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions components/chat-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ export function ChatPanel({ messages, input, setInput }: ChatPanelProps) {
handleClear()
setIsButtonPressed(false)
}
setMessages(currentMessages => [
...currentMessages,
{
id: nanoid(),
component: <UserMessage message={input} />
}
])
const formData = new FormData(e.currentTarget)
// Removed mcp argument from submit call
const responseMessage = await submit(formData)
Expand Down
19 changes: 9 additions & 10 deletions components/copilot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ import {
} from './ui/icons'
import { cn } from '@/lib/utils'

import { StreamableValue } from 'ai/rsc'

export type CopilotProps = {
inquiry: { value: PartialInquiry };
inquiry: StreamableValue<PartialInquiry>
}

export const Copilot: React.FC<CopilotProps> = ({ inquiry }: CopilotProps) => {
const { value } = inquiry;
export const Copilot: React.FC<CopilotProps> = ({ inquiry }) => {
const [data, error, pending] = useStreamableValue<PartialInquiry>(inquiry)
const [completed, setCompleted] = useState(false)
const [query, setQuery] = useState('')
const [skipped, setSkipped] = useState(false)
const [data, error, pending] = useStreamableValue<PartialInquiry>()
const [checkedOptions, setCheckedOptions] = useState<{
[key: string]: boolean
}>({})
Expand Down Expand Up @@ -121,14 +122,12 @@ export const Copilot: React.FC<CopilotProps> = ({ inquiry }: CopilotProps) => {
<Card className="p-4 rounded-lg w-full mx-auto">
<div className="mb-4">
<p className="text-lg text-foreground text-semibold ml-2">
{data?.question || value.question}


{data?.question}
</p>
</div>
<form onSubmit={onFormSubmit}>
<div className="flex flex-wrap justify-start mb-4">
{value.options?.map((option, index) => (
{data?.options?.map((option, index) => (
<div
key={`option-${index}`}
className="flex items-center space-x-1.5 mb-2"
Expand All @@ -152,14 +151,14 @@ export const Copilot: React.FC<CopilotProps> = ({ inquiry }: CopilotProps) => {
{data?.allowsInput && (
<div className="mb-6 flex flex-col space-y-2 text-sm">
<label className="text-muted-foreground" htmlFor="query">
{data?.inputLabel || value.inputLabel}
{data?.inputLabel}
</label>
<Input
type="text"
name="additional_query"
className="w-full"
id="query"
placeholder={data?.inputPlaceholder || value.inputPlaceholder}
placeholder={data?.inputPlaceholder}
value={query}
onChange={handleInputChange}
/>
Expand Down
12 changes: 1 addition & 11 deletions components/followup-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,9 @@ export function FollowupPanel() {
event.preventDefault()
const formData = new FormData(event.currentTarget as HTMLFormElement)

const userMessage = {
id: Date.now(),
isGenerating: false,
component: <UserMessage message={input} />
}

// Removed mcp argument from submit call
const responseMessage = await submit(formData)
setMessages(currentMessages => [
...currentMessages,
userMessage,
responseMessage
])
setMessages(currentMessages => [...currentMessages, responseMessage])

setInput('')
}
Expand Down
11 changes: 1 addition & 10 deletions components/search-related.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,9 @@ export const SearchRelated: React.FC<SearchRelatedProps> = ({
query = submitter.value
}

const userMessage = {
id: Date.now(),
component: <UserMessage message={query} />
}

// Removed mcp argument from submit call
const responseMessage = await submit(formData)
setMessages(currentMessages => [
...currentMessages,
userMessage,
responseMessage
])
setMessages(currentMessages => [...currentMessages, responseMessage])
}

return (
Expand Down
67 changes: 26 additions & 41 deletions lib/agents/inquire.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,36 @@ import { CoreMessage, LanguageModel, streamObject } from 'ai';
import { PartialInquiry, inquirySchema } from '@/lib/schema/inquiry';
import { getModel } from '../utils';

// Define a plain object type for the inquiry prop
interface InquiryProp {
value: PartialInquiry;
}

export async function inquire(
uiStream: ReturnType<typeof createStreamableUI>,
messages: CoreMessage[]
) {
const objectStream = createStreamableValue<PartialInquiry>();
let currentInquiry: PartialInquiry = {};

// Update the UI stream with the Copilot component, passing only the serializable value
uiStream.update(
<Copilot inquiry={{ value: currentInquiry }} />
);

let finalInquiry: PartialInquiry = {};
const result = await streamObject({
model: getModel() as LanguageModel,
system: `...`, // Your system prompt remains unchanged
messages,
schema: inquirySchema,
});

for await (const obj of result.partialObjectStream) {
if (obj) {
// Update the local state
currentInquiry = obj;
// Update the stream with the new serializable value
objectStream.update(obj);
finalInquiry = obj;

// Update the UI stream with the new inquiry value
uiStream.update(
<Copilot inquiry={{ value: currentInquiry }} />
);
): Promise<any> {
const objectStream = createStreamableValue<PartialInquiry>()
uiStream.update(<Copilot inquiry={objectStream.value} />)

let finalInquiry: PartialInquiry = {}
try {
const result = await streamObject({
model: getModel() as LanguageModel,
system: `As a professional writer, your job is to generate a comprehensive and informative, yet concise answer of 400 words or less for the given question based solely on the provided search results (URL and content). You must only use information from the provided search results. Use an unbiased and journalistic tone. Combine search results together into a coherent answer. Do not repeat text. If there are any images relevant to your answer, be sure to include them as well. Aim to directly address the user's question, augmenting your response with insights gleaned from the search results.
Whenever quoting or referencing information from a specific URL, always cite the source URL explicitly. Please match the language of the response to the user's language.
Always answer in Markdown format. Links and images must follow the correct format.
Link format: [link text](url)
Image format: ![alt text](url)
`,
Comment on lines +18 to +23
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

System prompt doesn't match the inquiry context.

The system prompt appears to be copied from a writer/researcher agent and talks about "search results", "URLs", and generating comprehensive answers. However, this inquire function is meant to generate inquiry questions for the Copilot UI to gather more information from the user, not to answer questions based on search results.

The system prompt should be focused on generating clarifying questions or gathering additional context from the user. Consider updating it to something like:

-      system: `As a professional writer, your job is to generate a comprehensive and informative, yet concise answer of 400 words or less for the given question based solely on the provided search results (URL and content). You must only use information from the provided search results. Use an unbiased and journalistic tone. Combine search results together into a coherent answer. Do not repeat text. If there are any images relevant to your answer, be sure to include them as well. Aim to directly address the user's question, augmenting your response with insights gleaned from the search results.
-    Whenever quoting or referencing information from a specific URL, always cite the source URL explicitly. Please match the language of the response to the user's language.
-    Always answer in Markdown format. Links and images must follow the correct format.
-    Link format: [link text](url)
-    Image format: ![alt text](url)
-    `,
+      system: `As an AI assistant, your task is to generate a clarifying inquiry when the user's request needs more specific information. Create a focused question with relevant options that help narrow down what the user is looking for. The inquiry should be clear, concise, and directly related to the user's original request. Match the language of the inquiry to the user's language.`,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
system: `As a professional writer, your job is to generate a comprehensive and informative, yet concise answer of 400 words or less for the given question based solely on the provided search results (URL and content). You must only use information from the provided search results. Use an unbiased and journalistic tone. Combine search results together into a coherent answer. Do not repeat text. If there are any images relevant to your answer, be sure to include them as well. Aim to directly address the user's question, augmenting your response with insights gleaned from the search results.
Whenever quoting or referencing information from a specific URL, always cite the source URL explicitly. Please match the language of the response to the user's language.
Always answer in Markdown format. Links and images must follow the correct format.
Link format: [link text](url)
Image format: ![alt text](url)
`,
system: `As an AI assistant, your task is to generate a clarifying inquiry when the user's request needs more specific information. Create a focused question with relevant options that help narrow down what the user is looking for. The inquiry should be clear, concise, and directly related to the user's original request. Match the language of the inquiry to the user's language.`,
🤖 Prompt for AI Agents
In lib/agents/inquire.tsx around lines 18 to 23 the system prompt is incorrect
for the inquire agent: it instructs the agent to synthesize answers from search
results instead of producing clarifying questions for the Copilot UI. Replace
the prompt with one that instructs the agent to generate concise,
context-gathering clarifying questions (matching the user language), tailored to
the Copilot UI flow, avoid instructing the agent to use search results or
produce final answers, do not force Markdown or strict word counts, and ensure
the prompt emphasizes brevity, optional follow-ups, and that questions are
actionable for the user to provide missing info.

messages,
schema: inquirySchema
})

for await (const obj of result.partialObjectStream) {
if (obj) {
objectStream.update(obj)
finalInquiry = obj
}
}
} finally {
objectStream.done()
}

objectStream.done();
// Final UI update
uiStream.update(
<Copilot inquiry={{ value: finalInquiry }} />
);

return finalInquiry;
return finalInquiry
}
6 changes: 5 additions & 1 deletion lib/agents/researcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ Match the language of your response to the user's language.`;
case 'text-delta':
if (delta.textDelta) {
// If the first text delta is available, add a UI section
if (fullResponse.length === 0 && delta.textDelta.length > 0) {
if (
fullResponse.length === 0 &&
delta.textDelta.length > 0 &&
!useSpecificModel
) {
// Update the UI
uiStream.update(answerSection)
}
Expand Down