Checkpoint: Phase 7 complete: Orchestrator Agent добавлен в /agents с меткой CROWN/SYSTEM, кнопками Configure и Open Chat. /chat читает конфиг оркестратора из БД (модель, промпт, инструменты). AgentDetailModal поддерживает isOrchestrator. 24 теста пройдены.

This commit is contained in:
Manus
2026-03-20 17:48:21 -04:00
parent c2fdfdbf72
commit 7aa8eee2ca
11 changed files with 1339 additions and 128 deletions

View File

@@ -443,13 +443,66 @@ Response style:
You are running on a Linux server with Node.js, Docker, and full internet access.`;
/**
* Load orchestrator config from DB.
* Returns { model, systemPrompt, allowedTools } from the agent with isOrchestrator=true.
* Falls back to defaults if not found.
*/
export async function getOrchestratorConfig(): Promise<{
id: number | null;
name: string;
model: string;
systemPrompt: string;
allowedTools: string[];
temperature: number;
maxTokens: number;
}> {
try {
const db = await getDb();
if (!db) throw new Error("DB not available");
const [orch] = await db
.select()
.from(agents)
.where(eq(agents.isOrchestrator, true))
.limit(1);
if (orch) {
return {
id: orch.id,
name: orch.name,
model: orch.model,
systemPrompt: orch.systemPrompt ?? ORCHESTRATOR_SYSTEM_PROMPT,
allowedTools: (orch.allowedTools as string[]) ?? [],
temperature: parseFloat(orch.temperature ?? "0.5"),
maxTokens: orch.maxTokens ?? 8192,
};
}
} catch (err) {
console.error("[Orchestrator] Failed to load config from DB:", err);
}
// Fallback defaults
return {
id: null,
name: "Orchestrator",
model: "qwen2.5:7b",
systemPrompt: ORCHESTRATOR_SYSTEM_PROMPT,
allowedTools: [],
temperature: 0.5,
maxTokens: 8192,
};
}
export async function orchestratorChat(
messages: OrchestratorMessage[],
model: string = "qwen2.5:7b",
model?: string,
maxToolIterations: number = 10
): Promise<OrchestratorResult> {
const toolCalls: ToolCallStep[] = [];
// Load config from DB — model and systemPrompt are configurable
const config = await getOrchestratorConfig();
const activeModel = model ?? config.model;
const activeSystemPrompt = config.systemPrompt;
// Build conversation with system prompt
const conversation: Array<{
role: "system" | "user" | "assistant" | "tool" | "function";
@@ -457,14 +510,14 @@ export async function orchestratorChat(
tool_call_id?: string;
name?: string;
}> = [
{ role: "system", content: ORCHESTRATOR_SYSTEM_PROMPT },
{ role: "system", content: activeSystemPrompt },
...messages.map((m) => ({ role: m.role, content: m.content })),
];
let iterations = 0;
let finalResponse = "";
let lastUsage: any;
let lastModel: string = model;
let lastModel: string = activeModel;
while (iterations < maxToolIterations) {
iterations++;
@@ -480,7 +533,7 @@ export async function orchestratorChat(
} catch (err: any) {
// Fallback: try without tools if LLM doesn't support them
try {
const fallbackResult = await chatCompletion(model, conversation as any, {
const fallbackResult = await chatCompletion(activeModel, conversation as any, {
temperature: 0.7,
max_tokens: 4096,
});