tinyagent-ts
Version:
Modern TypeScript framework for building AI agents with pluggable tools and ReAct reasoning
56 lines • 2.83 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
const zod_1 = require("zod");
const agent_1 = require("../src/agent");
const decorators_1 = require("../src/decorators");
const runMultiStep_1 = require("../src/runMultiStep");
describe('runMultiStep', () => {
beforeAll(() => {
var _a;
(_a = process.env).OPENROUTER_API_KEY || (_a.OPENROUTER_API_KEY = 'test');
});
let CalcAgent = class CalcAgent extends agent_1.Agent {
add({ a, b }) {
return String(a + b);
}
multiply({ a, b }) {
return String(a * b);
}
};
__decorate([
(0, decorators_1.tool)('Add numbers', zod_1.z.object({ a: zod_1.z.number(), b: zod_1.z.number() })),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", String)
], CalcAgent.prototype, "add", null);
__decorate([
(0, decorators_1.tool)('Multiply numbers', zod_1.z.object({ a: zod_1.z.number(), b: zod_1.z.number() })),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", String)
], CalcAgent.prototype, "multiply", null);
CalcAgent = __decorate([
(0, decorators_1.model)('test-model')
], CalcAgent);
it('handles two tool calls and final answer', async () => {
const agent = new CalcAgent();
const responses = [
{ choices: [{ message: { content: '{"tool":"add","args":{"a":2,"b":3}}' } }] },
{ choices: [{ message: { content: '{"tool":"multiply","args":{"a":5,"b":6}}' } }] },
{ choices: [{ message: { content: '{"tool":"final_answer","args":{"answer":"30"}}' } }] },
];
jest.spyOn(agent, 'makeOpenRouterRequest').mockImplementation(async () => responses.shift());
const out = await (0, runMultiStep_1.runMultiStep)(agent, 'Add 2+3 then multiply by 6');
expect(out.answer).toContain('30');
});
});
//# sourceMappingURL=runMultiStep.test.js.map