feat: add bullish and bearish researcher agents

This commit is contained in:
2026-05-14 07:59:44 +02:00
parent eb66485e76
commit e913b32f34
2 changed files with 117 additions and 0 deletions
+80
View File
@@ -0,0 +1,80 @@
import { OpenRouterClient } from "../lib/openrouter";
import type { AnalystReport, DebateRound } from "../types/agents";
type ChatResponse = {
choices?: Array<{ message?: { content?: string } }>;
};
export class BullishResearcher {
private client: OpenRouterClient;
private model: string;
constructor(client: OpenRouterClient, model?: string) {
this.client = client;
this.model = model ?? "google/gemini-2.0-flash-exp:free";
}
async research(ticker: string, reports: AnalystReport[]): Promise<DebateRound> {
const reportSummaries = reports
.map((r) => `${r.analyst}: ${r.signal.signal} - ${r.report}`)
.join("\n");
const prompt = `Analyze these analyst reports for ${ticker} and synthesize a bullish thesis:
${reportSummaries}
Provide a bullish view based on the positive signals and reasoning.`;
const response = await this.client.createChatCompletion(
[
{ role: "system", content: "You are a bullish equity researcher who finds the positive investment case." },
{ role: "user", content: prompt },
],
this.model
);
const content = ((response as ChatResponse).choices?.[0]?.message?.content) ?? "";
return {
bullishView: content,
bearishView: "",
researcher: "bullish",
};
}
}
export class BearishResearcher {
private client: OpenRouterClient;
private model: string;
constructor(client: OpenRouterClient, model?: string) {
this.client = client;
this.model = model ?? "google/gemini-2.0-flash-exp:free";
}
async research(ticker: string, reports: AnalystReport[]): Promise<DebateRound> {
const reportSummaries = reports
.map((r) => `${r.analyst}: ${r.signal.signal} - ${r.report}`)
.join("\n");
const prompt = `Analyze these analyst reports for ${ticker} and synthesize a bearish thesis:
${reportSummaries}
Provide a bearish view based on the risks and negative signals.`;
const response = await this.client.createChatCompletion(
[
{ role: "system", content: "You are a bearish equity researcher who identifies investment risks." },
{ role: "user", content: prompt },
],
this.model
);
const content = ((response as ChatResponse).choices?.[0]?.message?.content) ?? "";
return {
bullishView: "",
bearishView: content,
researcher: "bearish",
};
}
}