-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMuseAgentController.ts
More file actions
57 lines (47 loc) · 1.97 KB
/
MuseAgentController.ts
File metadata and controls
57 lines (47 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { AgentController, Inject } from '@eggjs/tegg';
import type { AgentHandler } from '@eggjs/controller-decorator';
import type { AgentStore, AgentStreamMessage, CreateRunInput } from '@eggjs/tegg-types';
import { OSSAgentStore, OSSObjectStorageClient } from '@eggjs/agent-runtime';
import { OSSObject } from 'oss-client';
import { OrchestratorService } from '../service/orchestrator';
@AgentController()
export class MuseAgentController implements AgentHandler {
@Inject()
private readonly orchestratorService!: OrchestratorService;
async createStore(): Promise<AgentStore> {
const endpoint = process.env.OSS_ENDPOINT || `https://${process.env.OSS_REGION || 'oss-cn-hangzhou'}.aliyuncs.com`;
const ossClient = new OSSObject({
endpoint,
accessKeyId: process.env.OSS_ACCESS_KEY_ID || '',
accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET || '',
bucket: process.env.OSS_BUCKET || '',
});
const storageClient = new OSSObjectStorageClient(ossClient);
const store = new OSSAgentStore({
client: storageClient,
prefix: process.env.OSS_PREFIX || 'mini-muse/',
});
if (store.init) await store.init();
return store as AgentStore;
}
async *execRun(input: CreateRunInput, signal?: AbortSignal): AsyncGenerator<AgentStreamMessage> {
const userMessage = input.input.messages[0];
const description = typeof userMessage.content === 'string'
? userMessage.content
: userMessage.content.map((p: { type: string; text: string }) => p.text).join('');
const appName = (input.metadata?.appName as string) || 'my-app';
const threadId = input.threadId || 'unknown';
const maxIterations = input.config?.maxIterations || 50;
const outputDir = `./output/${threadId}`;
const isModification = input.metadata?.type === 'modify';
yield* this.orchestratorService.agentLoop({
description,
appName,
outputDir,
maxIterations,
isModification,
threadId,
signal,
});
}
}