1// @ts-ignore
2import { OpenAI } from "https://esm.town/v/std/openai?v=4";
3import { Hono } from "npm:hono@4.4.12";
4
104/**
105 * Executes a call to an AI agent with a specified prompt and user content.
106 * @param openai The OpenAI client instance.
107 * @param systemPrompt The system prompt defining the agent's role.
108 * @param userContent The user-provided content for analysis.
110 */
111async function callAgent<T>(
112 openai: OpenAI,
113 systemPrompt: string,
114 userContent: string,
115): Promise<T> {
116 const completion = await openai.chat.completions.create({
117 model: "gpt-4o",
118 messages: [
134 request: AnalysisRequest,
135): Promise<FullAnalysis> {
136 const openai = new OpenAI();
137 let cumulativeContext = "";
138
141 `Supposed Correct Response: """${request.supposed_correct_response}"""\nFinal Answer: """${request.final_answer}"""`;
142 const accuracy = await callAgent<AccuracyReport>(
143 openai,
144 ACCURACY_AGENT_PROMPT,
145 accuracyContext,
153 `Reasoning Steps to Analyze: """${request.reasoning_steps}"""\n\nContext from previous agent:${cumulativeContext}`;
154 const consistency = await callAgent<ConsistencyReport>(
155 openai,
156 CONSISTENCY_AGENT_PROMPT,
157 consistencyContext,
165 `Reasoning Steps to Analyze: """${request.reasoning_steps}"""\n\nContext from previous agents:${cumulativeContext}`;
166 const faithfulness = await callAgent<FaithfulnessReport>(
167 openai,
168 FAITHFULNESS_AGENT_PROMPT,
169 faithfulnessContext,
177 `Original Prompt: """${request.prompt}"""\nReasoning Steps to Analyze: """${request.reasoning_steps}"""\n\nContext from previous agents:${cumulativeContext}`;
178 const authenticity = await callAgent<AuthenticityReport>(
179 openai,
180 AUTHENTICITY_AGENT_PROMPT,
181 authenticityContext,
189 `Please synthesize the following agent reports:\n${cumulativeContext}`;
190 const final_report = await callAgent<FinalReport>(
191 openai,
192 CONTEXT_AGENT_PROMPT,
193 contextAgentContext,