@azowl/agentops-sdk
Version:
AgentOps REST client and local task execution SDK for Node.js
35 lines (31 loc) • 1.59 kB
JavaScript
import { LocalAgent } from '@azowl/agentops-sdk/local';
import { createOllamaModel } from './ollama-model.mjs';
const stock = new Map([['A', 7], ['B', 0]]);
const agent = new LocalAgent({
profileId: 'inventory-readonly',
allowedTools: ['lookup_stock'],
tools: {
lookup_stock(input) {
if (!input || !stock.has(input.sku)) throw new TypeError('Unknown product.');
return { sku: input.sku, quantity: stock.get(input.sku) };
},
},
toolMetadata: {
lookup_stock: {
description: '상품 코드에 해당하는 현재 재고 수량을 조회합니다. 예를 들어 A상품의 코드는 A입니다.',
inputSchema: { type: 'object', properties: { sku: { type: 'string' } }, required: ['sku'] },
},
},
});
// The offline adapter makes this example reproducible. Pass a local Ollama
// model name to run the same agent against a tool-capable model instead.
function offlineInventoryModel({ messages }) {
const last = messages.at(-1);
if (last.role === 'tool') return { type: 'final', text: last.result.sku + '상품 재고는 ' + last.result.quantity + '개입니다.' };
const sku = /([A-Z])상품/u.exec(last.text)?.[1];
return sku ? { type: 'tool_call', name: 'lookup_stock', input: { sku } } : { type: 'final', text: '상품 코드를 알려 주세요.' };
}
const model = process.argv[2] ? createOllamaModel(process.argv[2]) : offlineInventoryModel;
const result = await agent.runWithModel('A상품 재고가 몇 개야?', model);
console.log(JSON.stringify(result, null, 2));
if (result.status !== 'completed') process.exitCode = 1;