diff --git a/services/minecraft/src/agents/openai.ts b/services/minecraft/src/agents/openai.ts index 6db92d857..31265a488 100644 --- a/services/minecraft/src/agents/openai.ts +++ b/services/minecraft/src/agents/openai.ts @@ -1,8 +1,8 @@ -import type { BotContext } from 'src/bot' +import type { Agent, Neuri } from 'neuri' import { useLogg } from '@guiiai/logg' -import { tool } from 'xsai' - -import { createQueryAgentBotContext, queryList } from './queries' +import { agent, neuri } from 'neuri' +import { openaiConfig } from '../composables/config' +import { queryList } from './queries' // Types interface AgentBotContext { @@ -15,60 +15,60 @@ const agents = new Set>() const logger = useLogg('openai').useGlobalConfig() // Agent initialization -// export async function initAgent(): Promise { -// logger.log('Initializing agent') -// let n = neuri() - -// agents.add(initQueryAgent()) - -// agents.forEach(agent => n = n.agent(agent)) - -// return n.build({ -// provider: { -// apiKey: openaiConfig.apiKey, -// baseURL: openaiConfig.baseUrl, -// }, -// }) -// } - -// export async function initQueryAgent(): Promise { -// logger.log('Initializing query agent') -// let queryAgent = agent('query') - -// queryList.forEach((query) => { -// queryAgent = queryAgent.tool( -// query.name, -// query.schema, -// query.perform, -// { description: query.description }, -// ) -// }) - -// return queryAgent.build() -// } - -export async function initAgent(ctx: BotContext) { +export async function initAgent(): Promise { logger.log('Initializing agent') + let n = neuri() - initQueryAgent(ctx) + agents.add(initQueryAgent()) + + agents.forEach(agent => n = n.agent(agent)) + + return n.build({ + provider: { + apiKey: openaiConfig.apiKey, + baseURL: openaiConfig.baseUrl, + }, + }) } -export function initQueryAgent(ctx: BotContext) { +export async function initQueryAgent(): Promise { logger.log('Initializing query agent') - const agentBotContext = createQueryAgentBotContext(ctx.bot) + let queryAgent = agent('query') - const tools = [] - - for (const query of queryList) { - tools.push( - tool({ - name: query.name, - description: query.description, - execute: query.perform(agentBotContext), - parameters: query.schema as never, - }), + queryList.forEach((query) => { + queryAgent = queryAgent.tool( + query.name, + query.schema, + query.perform, + { description: query.description }, ) - } + }) - return tools + return queryAgent.build() } + +// export async function initAgent(ctx: BotContext) { +// logger.log('Initializing agent') + +// initQueryAgent(ctx) +// } + +// export function initQueryAgent(ctx: BotContext) { +// logger.log('Initializing query agent') +// const agentBotContext = createQueryAgentBotContext(ctx.bot) + +// const tools = [] + +// for (const query of queryList) { +// tools.push( +// tool({ +// name: query.name, +// description: query.description, +// execute: query.perform(agentBotContext), +// parameters: query.schema as never, +// }), +// ) +// } + +// return tools +// } diff --git a/services/minecraft/src/main.ts b/services/minecraft/src/main.ts index 9977ea386..b58f327e7 100644 --- a/services/minecraft/src/main.ts +++ b/services/minecraft/src/main.ts @@ -2,6 +2,7 @@ import process from 'node:process' import { Format, LogLevel, setGlobalFormat, setGlobalLogLevel, useLogg } from '@guiiai/logg' +import { initAgent } from './agents/openai' import { createCommandComponent } from './components/command' import { createFollowComponent } from './components/follow' import { createPathFinderComponent } from './components/pathfinder' @@ -28,7 +29,7 @@ async function main() { registerComponent('command', createCommandComponent) }) - // initAgent(ctx) + // initAgent() process.on('SIGINT', () => { cleanup()