Download agentExecutorService.ts from VoidBreach/Chancellor: direct link, hf CLI and curl.
- Browser
- Download file 1.91 kB
-
https://huggingface.co/VoidBreach/Chancellor/resolve/main/agentExecutorService.ts
- Command line
-
hf download hf://VoidBreach/Chancellor/agentExecutorService.ts
-
curl -L -o agentExecutorService.ts https://huggingface.co/VoidBreach/Chancellor/resolve/main/agentExecutorService.ts
1.91 kB
| import { GoogleGenAI } from "@google/genai"; | |
| const ai = new GoogleGenAI({ | |
| apiKey: process.env.GEMINI_API_KEY!, | |
| httpOptions: { | |
| headers: { | |
| 'User-Agent': 'aistudio-build', | |
| } | |
| } | |
| }); | |
| export interface AgentTask { | |
| id: string; | |
| inquiry: string; | |
| context: object; | |
| } | |
| export interface AgentResult { | |
| taskId: string; | |
| synthesis: string; | |
| status: 'success' | 'failure'; | |
| } | |
| export async function dispatchAgentTask(task: AgentTask): Promise<AgentResult> { | |
| const MAX_RETRIES = 3; | |
| for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) { | |
| try { | |
| console.warn(`[AGENT_RUNTIME] Dispatching task ${task.id} (Attempt ${attempt}): ${task.inquiry}`); | |
| // Simulate high-fidelity synthesis using Gemini | |
| const systemInstruction = "You are a distributed agent runtime executor. Synthesize information accurately."; | |
| const response = await ai.models.generateContent({ | |
| model: "gemini-3.5-flash", | |
| contents: `Perform task ${task.id}: ${task.inquiry}. Context: ${JSON.stringify(task.context)}`, | |
| config: { | |
| systemInstruction, | |
| }, | |
| }); | |
| return { | |
| taskId: task.id, | |
| synthesis: response.candidates?.[0]?.content?.parts?.[0]?.text || "No synthesis returned.", | |
| status: 'success', | |
| }; | |
| } catch (error) { | |
| if (attempt === MAX_RETRIES) { | |
| console.error(`[AGENT_RUNTIME] Execution error in task ${task.id}:`, error); | |
| return { | |
| taskId: task.id, | |
| synthesis: error instanceof Error ? error.message : String(error), | |
| status: 'failure', | |
| }; | |
| } | |
| console.warn(`[AGENT_RUNTIME] Retrying task ${task.id} (Attempt ${attempt}) due to error: ${error}`); | |
| await new Promise(resolve => setTimeout(resolve, attempt * 1000)); // Simple linear backoff | |
| } | |
| } | |
| return { taskId: task.id, synthesis: 'Failed after retries', status: 'failure' }; | |
| } | |