Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix: ai prompt not built well

Louis Beaumontf80f9e66d1d2
diff --git a/screenpipe-app-tauri/components/timeline/agents.tsx b/screenpipe-app-tauri/components/timeline/agents.tsx
index c55921590..c4f9faa0e 100644
--- a/screenpipe-app-tauri/components/timeline/agents.tsx
+++ b/screenpipe-app-tauri/components/timeline/agents.tsx
@@ -2,7 +2,7 @@ import { StreamTimeSeriesResponse } from "@/app/timeline/page";
import OpenAI from "openai";
import { ChatCompletionMessageParam } from "openai/resources/index.mjs";
-interface Agent {
+export interface Agent {
id: string;
name: string;
description: string;
@@ -12,22 +12,31 @@ interface Agent {
options: {
model: string;
onProgress: (chunk: string) => void;
- }
+ },
+ userQuery: string
) => Promise<void>;
}
async function streamCompletion(
openai: OpenAI,
messages: ChatCompletionMessageParam[],
+ userQuery: string,
options: {
model: string;
onProgress: (chunk: string) => void;
}
) {
- console.log("streaming completion", messages);
+ const messagesWithQuery = [
+ ...messages,
+ {
+ role: "user" as const,
+ content: `User question: "${userQuery}"\nPlease analyze the data in context of this question.`,
+ },
+ ];
+
const stream = await openai.chat.completions.create({
model: options.model,
- messages,
+ messages: messagesWithQuery,
stream: true,
});
@@ -67,7 +76,12 @@ export const AGENTS: Agent[] = [
name: "recursive summarizer",
description:
"good at processing long time ranges but quality decreases with shorter time ranges",
- analyze: async (frames, openai, { model, onProgress = () => {} }) => {
+ analyze: async (
+ frames,
+ openai,
+ { model, onProgress = () => {} },
+ userQuery
+ ) => {
if (!frames.length) {
onProgress("no frames to analyze\n\n");
return;
@@ -123,7 +137,7 @@ export const AGENTS: Agent[] = [
role: "system",
content: `create a hierarchical summary with these sections:
### overview
- (one paragraph summary of entire time range)
+ (one paragraph summary of entire time range, focusing on answering the user's question)
### timeline
(list of chunk summaries with timestamps)
@@ -144,6 +158,7 @@ export const AGENTS: Agent[] = [
}),
},
],
+ userQuery,
{ model, onProgress }
);
},
@@ -152,7 +167,7 @@ export const AGENTS: Agent[] = [
id: "context-master",
name: "context master",
description: "analyzes everything: apps, windows, text & audio",
- analyze: async (frames, openai, { model, onProgress }) => {
+ analyze: async (frames, openai, { model, onProgress }, userQuery) => {
const contextData = frames.map((frame) => ({
timestamp: frame.timestamp,
devices: frame.devices.map((device) => ({
@@ -162,8 +177,6 @@ export const AGENTS: Agent[] = [
})),
}));
- console.log("context data", contextData);
-
await streamCompletion(
openai,
[
@@ -177,6 +190,7 @@ export const AGENTS: Agent[] = [
content: JSON.stringify(contextData),
},
],
+ userQuery,
{ model, onProgress }
);
},
@@ -185,7 +199,7 @@ export const AGENTS: Agent[] = [
id: "window-tracker",
name: "window tracker",
description: "focuses on app & window usage data",
- analyze: async (frames, openai, { model, onProgress }) => {
+ analyze: async (frames, openai, { model, onProgress }, userQuery) => {
const windowData = frames.map((frame) => ({
timestamp: frame.timestamp,
windows: frame.devices.map((device) => ({
@@ -207,6 +221,7 @@ export const AGENTS: Agent[] = [
content: JSON.stringify(windowData),
},
],
+ userQuery,
{ model, onProgress }
);
},
@@ -215,7 +230,7 @@ export const AGENTS: Agent[] = [
id: "text-scanner",
name: "text scanner",
description: "analyzes visible text (OCR)",
- analyze: async (frames, openai, { model, onProgress }) => {
+ analyze: async (frames, openai, { model, onProgress }, userQuery) => {
const textData = frames.map((frame) => ({
timestamp: frame.timestamp,
text: frame.devices
@@ -236,6 +251,7 @@ export const AGENTS: Agent[] = [
content: JSON.stringify(textData),
},
],
+ userQuery,
{ model, onProgress }
);
},
@@ -244,7 +260,7 @@ export const AGENTS: Agent[] = [
id: "voice-analyzer",
name: "voice analyzer",
description: "focuses on audio transcriptions",
- analyze: async (frames, openai, { model, onProgress }) => {
+ analyze: async (frames, openai, { model, onProgress }, userQuery) => {
const audioData = frames.map((frame) => ({
timestamp: frame.timestamp,
audio: frame.devices.flatMap((device) => device.audio),
@@ -263,6 +279,7 @@ export const AGENTS: Agent[] = [
content: JSON.stringify(audioData),
},
],
+ userQuery,
{ model, onProgress }
);
},
diff --git a/screenpipe-app-tauri/components/timeline/ai-panel.tsx b/screenpipe-app-tauri/components/timeline/ai-panel.tsx
index 4354eafd4..64aef67ef 100644
--- a/screenpipe-app-tauri/components/timeline/ai-panel.tsx
+++ b/screenpipe-app-tauri/components/timeline/ai-panel.tsx
@@ -10,20 +10,7 @@ import { StreamTimeSeriesResponse } from "@/app/timeline/page";
import { platform } from "@tauri-apps/plugin-os";
import posthog from "posthog-js";
import { useTimelineSelection } from "@/lib/hooks/use-timeline-selection";
-
-interface Agent {
- id: string;
- name: string;
- description: string;
- analyze: (
- frames: StreamTimeSeriesResponse[],
- openai: OpenAI,
- options: {
- model: string;
- onProgress: (chunk: string) => void;
- }
- ) => Promise<void>;
-}
+import { Agent } from "./agents";
interface AIPanelProps {
position: { x: number; y: number };
@@ -199,16 +186,21 @@ export function AIPanel({
{ id: generateId(), role: "assistant", content: "" },
]);
- await selectedAgent.analyze(relevantFrames, openai, {
- model: settings.aiModel,
- onProgress: (chunk) => {
- currentResponse = chunk;
- setChatMessages((prev) => [
- ...prev.slice(0, -1),
- { id: generateId(), role: "assistant", content: currentResponse },
- ]);
+ await selectedAgent.analyze(
+ relevantFrames,
+ openai,
+ {
+ model: settings.aiModel,
+ onProgress: (chunk) => {
+ currentResponse = chunk;
+ setChatMessages((prev) => [
+ ...prev.slice(0, -1),
+ { id: generateId(), role: "assistant", content: currentResponse },
+ ]);
+ },
},
- });
+ aiInput
+ );
} catch (error) {
console.error("Error generating AI response:", error);
toast({
diff --git a/screenpipe-app-tauri/src-tauri/Cargo.lock b/screenpipe-app-tauri/src-tauri/Cargo.lock
index 909f63b86..34152e200 100755
--- a/screenpipe-app-tauri/src-tauri/Cargo.lock
+++ b/screenpipe-app-tauri/src-tauri/Cargo.lock
@@ -3777,7 +3777,7 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "screenpipe-app"
-version = "0.10.7"
+version = "0.10.8"
dependencies = [
"anyhow",
"axum",
diff --git a/screenpipe-app-tauri/src-tauri/Cargo.toml b/screenpipe-app-tauri/src-tauri/Cargo.toml
index d5d8ba463..7ab958317 100644
--- a/screenpipe-app-tauri/src-tauri/Cargo.toml
+++ b/screenpipe-app-tauri/src-tauri/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "screenpipe-app"
-version = "0.10.8"
+version = "0.10.9"
description = ""
authors = ["you"]
license = ""