@loopstack/agent-examples 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -0
- package/dist/tools/calculator.tool.d.ts +2 -0
- package/dist/tools/calculator.tool.d.ts.map +1 -1
- package/dist/tools/calculator.tool.js +4 -1
- package/dist/tools/calculator.tool.js.map +1 -1
- package/dist/tools/weather-lookup.tool.d.ts +2 -0
- package/dist/tools/weather-lookup.tool.d.ts.map +1 -1
- package/dist/tools/weather-lookup.tool.js +4 -1
- package/dist/tools/weather-lookup.tool.js.map +1 -1
- package/dist/workflows/agent/agent-example.workflow.d.ts.map +1 -1
- package/dist/workflows/agent/agent-example.workflow.js +1 -0
- package/dist/workflows/agent/agent-example.workflow.js.map +1 -1
- package/dist/workflows/code-agent/code-agent-example.workflow.d.ts +2 -2
- package/dist/workflows/code-agent/code-agent-example.workflow.d.ts.map +1 -1
- package/dist/workflows/code-agent/code-agent-example.workflow.js +4 -4
- package/dist/workflows/code-agent/code-agent-example.workflow.js.map +1 -1
- package/dist/workflows/custom-agent/custom-agent-example.workflow.d.ts +6 -6
- package/dist/workflows/custom-agent/custom-agent-example.workflow.d.ts.map +1 -1
- package/dist/workflows/custom-agent/custom-agent-example.workflow.js +12 -12
- package/dist/workflows/custom-agent/custom-agent-example.workflow.js.map +1 -1
- package/package.json +2 -2
- package/src/tools/calculator.tool.ts +4 -0
- package/src/tools/weather-lookup.tool.ts +4 -0
- package/src/workflows/agent/__tests__/agent-example.spec.ts +60 -0
- package/src/workflows/agent/agent-example.workflow.ts +1 -0
- package/src/workflows/code-agent/code-agent-example.workflow.ts +2 -2
- package/src/workflows/custom-agent/__tests__/custom-agent-example.spec.ts +69 -0
- package/src/workflows/custom-agent/custom-agent-example.workflow.ts +7 -7
package/README.md
CHANGED
|
@@ -38,6 +38,26 @@ npm install @loopstack/agent-examples
|
|
|
38
38
|
import { AgentExamplesModule } from '@loopstack/agent-examples';
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
+
## Required app-module configuration
|
|
42
|
+
|
|
43
|
+
All four examples use LLM tools (`LlmGenerateTextTool`, `LlmDelegateToolCallsTool`, etc.) from `@loopstack/llm-provider-module`. That module is `@Global` and must be configured once in your root module to set the default model:
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import { Module } from '@nestjs/common';
|
|
47
|
+
import { AgentExamplesModule } from '@loopstack/agent-examples';
|
|
48
|
+
import { LlmProviderModule } from '@loopstack/llm-provider-module';
|
|
49
|
+
import { LoopstackModule } from '@loopstack/loopstack-module';
|
|
50
|
+
|
|
51
|
+
@Module({
|
|
52
|
+
imports: [LoopstackModule.forRoot(), LlmProviderModule.forRoot({ model: 'claude-sonnet-4-6' }), AgentExamplesModule],
|
|
53
|
+
})
|
|
54
|
+
export class AppModule {}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`AgentExamplesModule` re-imports `ClaudeModule` (provider), `AgentModule` (the `AgentWorkflow` / `ChatAgentWorkflow` classes), `CodeAgentModule`, `McpModule`, and `RemoteClientModule.forFeature({ type: 'sandbox' })`. `LlmProviderModule.forRoot(...)` sets the default model the tools dispatch to.
|
|
58
|
+
|
|
59
|
+
The Code Agent example additionally requires `RemoteClientModule.forRoot({ environments })` — see [Code Agent → Setup](#code-agent) below.
|
|
60
|
+
|
|
41
61
|
## Environment
|
|
42
62
|
|
|
43
63
|
```bash
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
1
2
|
import { BaseTool, ToolEnvelope } from '@loopstack/common';
|
|
2
3
|
import type { RunContext } from '@loopstack/common';
|
|
3
4
|
export type CalculatorResult = string;
|
|
5
|
+
export declare const CalculatorResultSchema: z.ZodString;
|
|
4
6
|
export declare class CalculatorTool extends BaseTool<{
|
|
5
7
|
operation: string;
|
|
6
8
|
a: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculator.tool.d.ts","sourceRoot":"","sources":["../../src/tools/calculator.tool.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"calculator.tool.d.ts","sourceRoot":"","sources":["../../src/tools/calculator.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAQ,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEtC,eAAO,MAAM,sBAAsB,aAAa,CAAC;AAEjD,qBAWa,cAAe,SAAQ,QAAQ,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,MAAM,EAAE,gBAAgB,CAAC;cACjG,MAAM,CACpB,IAAI,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,EACjD,IAAI,EAAE,UAAU,GACf,OAAO,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC;CA2B3C"}
|
|
@@ -6,9 +6,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.CalculatorTool = void 0;
|
|
9
|
+
exports.CalculatorTool = exports.CalculatorResultSchema = void 0;
|
|
10
10
|
const zod_1 = require("zod");
|
|
11
11
|
const common_1 = require("@loopstack/common");
|
|
12
|
+
exports.CalculatorResultSchema = zod_1.z.string();
|
|
12
13
|
let CalculatorTool = class CalculatorTool extends common_1.BaseTool {
|
|
13
14
|
async handle(args, _ctx) {
|
|
14
15
|
let result;
|
|
@@ -46,6 +47,8 @@ exports.CalculatorTool = CalculatorTool = __decorate([
|
|
|
46
47
|
a: zod_1.z.number().describe('First operand.'),
|
|
47
48
|
b: zod_1.z.number().describe('Second operand.'),
|
|
48
49
|
}),
|
|
50
|
+
resultSchema: exports.CalculatorResultSchema,
|
|
51
|
+
effects: 'none',
|
|
49
52
|
})
|
|
50
53
|
], CalculatorTool);
|
|
51
54
|
//# sourceMappingURL=calculator.tool.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculator.tool.js","sourceRoot":"","sources":["../../src/tools/calculator.tool.ts"],"names":[],"mappings":";;;;;;;;;AAAA,6BAAwB;AACxB,8CAAiE;
|
|
1
|
+
{"version":3,"file":"calculator.tool.js","sourceRoot":"","sources":["../../src/tools/calculator.tool.ts"],"names":[],"mappings":";;;;;;;;;AAAA,6BAAwB;AACxB,8CAAiE;AAKpD,QAAA,sBAAsB,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC;AAa1C,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,iBAA+E;IACvG,KAAK,CAAC,MAAM,CACpB,IAAiD,EACjD,IAAgB;QAEhB,IAAI,MAAc,CAAC;QAEnB,QAAQ,IAAI,CAAC,SAAS,EAAE,CAAC;YACvB,KAAK,KAAK;gBACR,MAAM,GAAG,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;gBACzB,MAAM;YACR,KAAK,UAAU;gBACb,MAAM,GAAG,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;gBACzB,MAAM;YACR,KAAK,UAAU;gBACb,MAAM,GAAG,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;gBACzB,MAAM;YACR,KAAK,QAAQ;gBACX,IAAI,IAAI,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;oBACjB,OAAO,EAAE,IAAI,EAAE,yBAAyB,EAAE,KAAK,EAAE,uBAAuB,EAAE,CAAC;gBAC7E,CAAC;gBACD,MAAM,GAAG,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;gBACzB,MAAM;YACR;gBACE,OAAO,EAAE,IAAI,EAAE,sBAAsB,IAAI,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,uBAAuB,EAAE,CAAC;QAC5F,CAAC;QAED,OAAO;YACL,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,CAAC,MAAM,MAAM,EAAE;SAC1D,CAAC;IACJ,CAAC;CACF,CAAA;AA/BY,wCAAc;yBAAd,cAAc;IAX1B,IAAA,aAAI,EAAC;QACJ,IAAI,EAAE,YAAY;QAClB,WAAW,EAAE,mFAAmF;QAChG,MAAM,EAAE,OAAC,CAAC,MAAM,CAAC;YACf,SAAS,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,2BAA2B,CAAC;YAClG,CAAC,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,gBAAgB,CAAC;YACxC,CAAC,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,iBAAiB,CAAC;SAC1C,CAAC;QACF,YAAY,EAAE,8BAAsB;QACpC,OAAO,EAAE,MAAM;KAChB,CAAC;GACW,cAAc,CA+B1B"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
1
2
|
import { BaseTool, ToolEnvelope } from '@loopstack/common';
|
|
2
3
|
export type WeatherLookupResult = string;
|
|
4
|
+
export declare const WeatherLookupResultSchema: z.ZodString;
|
|
3
5
|
export declare class WeatherLookupTool extends BaseTool<{
|
|
4
6
|
city: string;
|
|
5
7
|
}, object, WeatherLookupResult> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"weather-lookup.tool.d.ts","sourceRoot":"","sources":["../../src/tools/weather-lookup.tool.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"weather-lookup.tool.d.ts","sourceRoot":"","sources":["../../src/tools/weather-lookup.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAQ,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjE,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC;AAEzC,eAAO,MAAM,yBAAyB,aAAa,CAAC;AAEpD,qBASa,iBAAkB,SAAQ,QAAQ,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,MAAM,EAAE,mBAAmB,CAAC;cAC5E,MAAM,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,YAAY,CAAC,mBAAmB,CAAC,CAAC;CAe3F"}
|
|
@@ -6,9 +6,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.WeatherLookupTool = void 0;
|
|
9
|
+
exports.WeatherLookupTool = exports.WeatherLookupResultSchema = void 0;
|
|
10
10
|
const zod_1 = require("zod");
|
|
11
11
|
const common_1 = require("@loopstack/common");
|
|
12
|
+
exports.WeatherLookupResultSchema = zod_1.z.string();
|
|
12
13
|
let WeatherLookupTool = class WeatherLookupTool extends common_1.BaseTool {
|
|
13
14
|
async handle(args) {
|
|
14
15
|
const forecasts = {
|
|
@@ -31,6 +32,8 @@ exports.WeatherLookupTool = WeatherLookupTool = __decorate([
|
|
|
31
32
|
schema: zod_1.z.object({
|
|
32
33
|
city: zod_1.z.string().describe('The city name to look up weather for.'),
|
|
33
34
|
}),
|
|
35
|
+
resultSchema: exports.WeatherLookupResultSchema,
|
|
36
|
+
effects: 'none',
|
|
34
37
|
})
|
|
35
38
|
], WeatherLookupTool);
|
|
36
39
|
//# sourceMappingURL=weather-lookup.tool.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"weather-lookup.tool.js","sourceRoot":"","sources":["../../src/tools/weather-lookup.tool.ts"],"names":[],"mappings":";;;;;;;;;AAAA,6BAAwB;AACxB,8CAAiE;
|
|
1
|
+
{"version":3,"file":"weather-lookup.tool.js","sourceRoot":"","sources":["../../src/tools/weather-lookup.tool.ts"],"names":[],"mappings":";;;;;;;;;AAAA,6BAAwB;AACxB,8CAAiE;AAIpD,QAAA,yBAAyB,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC;AAW7C,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,iBAAuD;IAClF,KAAK,CAAC,MAAM,CAAC,IAAsB;QAE3C,MAAM,SAAS,GAA2B;YACxC,MAAM,EAAE,8BAA8B;YACtC,KAAK,EAAE,8BAA8B;YACrC,UAAU,EAAE,qBAAqB;SAClC,CAAC;QAEF,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;QACpC,MAAM,OAAO,GAAG,SAAS,CAAC,GAAG,CAAC,IAAI,2BAA2B,CAAC;QAE9D,OAAO,OAAO,CAAC,OAAO,CAAC;YACrB,IAAI,EAAE,cAAc,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE;SAC5C,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAhBY,8CAAiB;4BAAjB,iBAAiB;IAT7B,IAAA,aAAI,EAAC;QACJ,IAAI,EAAE,gBAAgB;QACtB,WAAW,EAAE,6EAA6E;QAC1F,MAAM,EAAE,OAAC,CAAC,MAAM,CAAC;YACf,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,uCAAuC,CAAC;SACnE,CAAC;QACF,YAAY,EAAE,iCAAyB;QACvC,OAAO,EAAE,MAAM;KAChB,CAAC;GACW,iBAAiB,CAgB7B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-example.workflow.d.ts","sourceRoot":"","sources":["../../../src/workflows/agent/agent-example.workflow.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,WAAW,EAAqB,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtF,OAAO,EAAE,YAAY,EAAc,KAAK,eAAe,EAAY,MAAM,mBAAmB,CAAC;AAG7F,qBAKa,oBAAqB,SAAQ,YAAY;IACxC,OAAO,CAAC,QAAQ,CAAC,aAAa;gBAAb,aAAa,EAAE,aAAa;IAKnD,KAAK;IAiBL,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"agent-example.workflow.d.ts","sourceRoot":"","sources":["../../../src/workflows/agent/agent-example.workflow.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,WAAW,EAAqB,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtF,OAAO,EAAE,YAAY,EAAc,KAAK,eAAe,EAAY,MAAM,mBAAmB,CAAC;AAG7F,qBAKa,oBAAqB,SAAQ,YAAY;IACxC,OAAO,CAAC,QAAQ,CAAC,aAAa;gBAAb,aAAa,EAAE,aAAa;IAKnD,KAAK;IAiBL,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,WAAW,CAAC;CAOzF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-example.workflow.js","sourceRoot":"","sources":["../../../src/workflows/agent/agent-example.workflow.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAiC;AACjC,4CAAsF;AACtF,8CAA6F;AAC7F,wEAAoE;AAO7D,IAAM,oBAAoB,GAA1B,MAAM,oBAAqB,SAAQ,qBAAY;IACvB;IAA7B,YAA6B,aAA4B;QACvD,KAAK,EAAE,CAAC;QADmB,kBAAa,G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,EAAE,QAAQ,EAAE,EAAE,UAAU,EAAE,eAAe,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,CACjF,CAAC;IACJ,CAAC;IAQK,AAAN,KAAK,CAAC,aAAa,CAAC,MAA+B,EAAE,KAAmC;QACtF,MAAM,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,wCAAkB,EAAE;YAChD,IAAI,EAAE,WAAW;YACjB,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,QAAQ;SAC1B,CAAC,CAAC;QACH,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;CACF,CAAA;AA9BY,oDAAoB;AAMzB;IADL,IAAA,mBAAU,EAAC,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC;;;;iDAU7B;AAQK;IANL,IAAA,mBAAU,EAAC;QACV,IAAI,EAAE,SAAS;QACf,EAAE,EAAE,KAAK;QACT,IAAI,EAAE,IAAI;QACV,MAAM,EAAE,yBAAiB;KAC1B,CAAC;;;;yDAOD;+BA7BU,oBAAoB;IALhC,IAAA,iBAAQ,EAAC;QACR,KAAK,EAAE,6BAA6B;QACpC,WAAW,EACT,mHAAmH;KACtH,CAAC;qCAE4C,qBAAa;GAD9C,oBAAoB,CA8BhC"}
|
|
@@ -5,8 +5,8 @@ export declare class CodeAgentExampleWorkflow extends BaseWorkflow {
|
|
|
5
5
|
private readonly agentWorkflow;
|
|
6
6
|
private readonly environments;
|
|
7
7
|
constructor(agentWorkflow: AgentWorkflow, environments: EnvironmentService);
|
|
8
|
-
verifyEnvironment(
|
|
9
|
-
startExploration(
|
|
8
|
+
verifyEnvironment(): Promise<void>;
|
|
9
|
+
startExploration(): Promise<void>;
|
|
10
10
|
exploreComplete(_state: Record<string, unknown>, input: TransitionInput<AgentResult>): Promise<void>;
|
|
11
11
|
}
|
|
12
12
|
//# sourceMappingURL=code-agent-example.workflow.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-agent-example.workflow.d.ts","sourceRoot":"","sources":["../../../src/workflows/code-agent/code-agent-example.workflow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAqB,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtF,OAAO,EAAE,YAAY,EAA+B,KAAK,eAAe,EAAY,MAAM,mBAAmB,CAAC;AAC9G,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAY9D,qBAIa,wBAAyB,SAAQ,YAAY;IAEtD,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,YAAY;gBADZ,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,kBAAkB;IAM7C,iBAAiB
|
|
1
|
+
{"version":3,"file":"code-agent-example.workflow.d.ts","sourceRoot":"","sources":["../../../src/workflows/code-agent/code-agent-example.workflow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAqB,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtF,OAAO,EAAE,YAAY,EAA+B,KAAK,eAAe,EAAY,MAAM,mBAAmB,CAAC;AAC9G,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAY9D,qBAIa,wBAAyB,SAAQ,YAAY;IAEtD,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,YAAY;gBADZ,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,kBAAkB;IAM7C,iBAAiB;IAKjB,gBAAgB;IAiBhB,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,WAAW,CAAC;CAM3F"}
|
|
@@ -23,10 +23,10 @@ let CodeAgentExampleWorkflow = class CodeAgentExampleWorkflow extends common_1.B
|
|
|
23
23
|
this.agentWorkflow = agentWorkflow;
|
|
24
24
|
this.environments = environments;
|
|
25
25
|
}
|
|
26
|
-
async verifyEnvironment(
|
|
26
|
+
async verifyEnvironment() {
|
|
27
27
|
await this.environments.assertReachable('sandbox');
|
|
28
28
|
}
|
|
29
|
-
async startExploration(
|
|
29
|
+
async startExploration() {
|
|
30
30
|
await this.agentWorkflow.run({
|
|
31
31
|
system: 'You are a codebase exploration agent. Search and read source code to answer the question thoroughly.',
|
|
32
32
|
tools: ['glob', 'grep', 'read'],
|
|
@@ -44,13 +44,13 @@ exports.CodeAgentExampleWorkflow = CodeAgentExampleWorkflow;
|
|
|
44
44
|
__decorate([
|
|
45
45
|
(0, common_1.Transition)({ to: 'verified' }),
|
|
46
46
|
__metadata("design:type", Function),
|
|
47
|
-
__metadata("design:paramtypes", [
|
|
47
|
+
__metadata("design:paramtypes", []),
|
|
48
48
|
__metadata("design:returntype", Promise)
|
|
49
49
|
], CodeAgentExampleWorkflow.prototype, "verifyEnvironment", null);
|
|
50
50
|
__decorate([
|
|
51
51
|
(0, common_1.Transition)({ from: 'verified', to: 'exploring' }),
|
|
52
52
|
__metadata("design:type", Function),
|
|
53
|
-
__metadata("design:paramtypes", [
|
|
53
|
+
__metadata("design:paramtypes", []),
|
|
54
54
|
__metadata("design:returntype", Promise)
|
|
55
55
|
], CodeAgentExampleWorkflow.prototype, "startExploration", null);
|
|
56
56
|
__decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-agent-example.workflow.js","sourceRoot":"","sources":["../../../src/workflows/code-agent/code-agent-example.workflow.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAAsF;AACtF,8CAA8G;AAC9G,4DAA8D;AAE9D,MAAM,oBAAoB,GAAG;mEACsC,CAAC;AAa7D,IAAM,wBAAwB,GAA9B,MAAM,wBAAyB,SAAQ,qBAAY;IAErC;IACA;IAFnB,YACmB,aAA4B,EAC5B,YAAgC;QAEjD,KAAK,EAAE,CAAC;QAHS,kBAAa,GAAb,aAAa,CAAe;QAC5B,iBAAY,GAAZ,YAAY,CAAoB;IAGnD,CAAC;IAGK,AAAN,KAAK,CAAC,iBAAiB
|
|
1
|
+
{"version":3,"file":"code-agent-example.workflow.js","sourceRoot":"","sources":["../../../src/workflows/code-agent/code-agent-example.workflow.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAAsF;AACtF,8CAA8G;AAC9G,4DAA8D;AAE9D,MAAM,oBAAoB,GAAG;mEACsC,CAAC;AAa7D,IAAM,wBAAwB,GAA9B,MAAM,wBAAyB,SAAQ,qBAAY;IAErC;IACA;IAFnB,YACmB,aAA4B,EAC5B,YAAgC;QAEjD,KAAK,EAAE,CAAC;QAHS,kBAAa,GAAb,aAAa,CAAe;QAC5B,iBAAY,GAAZ,YAAY,CAAoB;IAGnD,CAAC;IAGK,AAAN,KAAK,CAAC,iBAAiB;QACrB,MAAM,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;IACrD,CAAC;IAGK,AAAN,KAAK,CAAC,gBAAgB;QACpB,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CAC1B;YACE,MAAM,EAAE,sGAAsG;YAC9G,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;YAC/B,WAAW,EAAE,oBAAoB;SAClC,EACD,EAAE,QAAQ,EAAE,EAAE,UAAU,EAAE,iBAAiB,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,uBAAuB,EAAE,CAChG,CAAC;IACJ,CAAC;IAQK,AAAN,KAAK,CAAC,eAAe,CAAC,MAA+B,EAAE,KAAmC;QACxF,MAAM,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,wBAAe,EAAE;YAC7C,IAAI,EAAE,WAAW;YACjB,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,QAAQ;SAC1B,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AArCY,4DAAwB;AAS7B;IADL,IAAA,mBAAU,EAAC,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC;;;;iEAG9B;AAGK;IADL,IAAA,mBAAU,EAAC,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,WAAW,EAAE,CAAC;;;;gEAUjD;AAQK;IANL,IAAA,mBAAU,EAAC;QACV,IAAI,EAAE,WAAW;QACjB,EAAE,EAAE,KAAK;QACT,IAAI,EAAE,IAAI;QACV,MAAM,EAAE,yBAAiB;KAC1B,CAAC;;;;+DAMD;mCApCU,wBAAwB;IAJpC,IAAA,iBAAQ,EAAC;QACR,KAAK,EAAE,4BAA4B;QACnC,WAAW,EAAE,yFAAyF;KACvG,CAAC;qCAGkC,qBAAa;QACd,kCAAkB;GAHxC,wBAAwB,CAqCpC"}
|
|
@@ -12,19 +12,19 @@ export declare class CustomAgentExampleWorkflow extends BaseWorkflow {
|
|
|
12
12
|
private readonly llmDelegateToolCalls;
|
|
13
13
|
private readonly llmUpdateToolResult;
|
|
14
14
|
constructor(llmGenerateText: LlmGenerateTextTool, llmDelegateToolCalls: LlmDelegateToolCallsTool, llmUpdateToolResult: LlmUpdateToolResultTool);
|
|
15
|
-
setup(
|
|
15
|
+
setup(): Promise<void>;
|
|
16
16
|
llmTurn(state: CustomAgentState): Promise<void>;
|
|
17
|
-
notifyOverBudget(
|
|
18
|
-
wrapUp(
|
|
17
|
+
notifyOverBudget(): Promise<void>;
|
|
18
|
+
wrapUp(): Promise<void>;
|
|
19
19
|
executeToolCalls(state: CustomAgentState): Promise<void>;
|
|
20
20
|
toolResultReceived(state: CustomAgentState, input: TransitionInput): Promise<void>;
|
|
21
|
-
toolsComplete(
|
|
22
|
-
respond(
|
|
21
|
+
toolsComplete(): void;
|
|
22
|
+
respond(): void;
|
|
23
23
|
private hasBudget;
|
|
24
24
|
private isOverBudget;
|
|
25
25
|
private hasToolCalls;
|
|
26
26
|
private allToolsComplete;
|
|
27
|
-
private
|
|
27
|
+
private isDone;
|
|
28
28
|
}
|
|
29
29
|
export {};
|
|
30
30
|
//# sourceMappingURL=custom-agent-example.workflow.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-agent-example.workflow.d.ts","sourceRoot":"","sources":["../../../src/workflows/custom-agent/custom-agent-example.workflow.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAiD,MAAM,mBAAmB,CAAC;AAChG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAC/F,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EAEnB,uBAAuB,EACxB,MAAM,gCAAgC,CAAC;AAIxC,UAAU,gBAAgB;IACxB,SAAS,CAAC,EAAE,qBAAqB,CAAC;IAClC,cAAc,CAAC,EAAE,iBAAiB,CAAC;IACnC,SAAS,EAAE,MAAM,CAAC;CACnB;AAcD,qBAKa,0BAA2B,SAAQ,YAAY;IAExD,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,oBAAoB;IACrC,OAAO,CAAC,QAAQ,CAAC,mBAAmB;gBAFnB,eAAe,EAAE,mBAAmB,EACpC,oBAAoB,EAAE,wBAAwB,EAC9C,mBAAmB,EAAE,uBAAuB;IAUzD,KAAK
|
|
1
|
+
{"version":3,"file":"custom-agent-example.workflow.d.ts","sourceRoot":"","sources":["../../../src/workflows/custom-agent/custom-agent-example.workflow.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAiD,MAAM,mBAAmB,CAAC;AAChG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAC/F,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EAEnB,uBAAuB,EACxB,MAAM,gCAAgC,CAAC;AAIxC,UAAU,gBAAgB;IACxB,SAAS,CAAC,EAAE,qBAAqB,CAAC;IAClC,cAAc,CAAC,EAAE,iBAAiB,CAAC;IACnC,SAAS,EAAE,MAAM,CAAC;CACnB;AAcD,qBAKa,0BAA2B,SAAQ,YAAY;IAExD,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,oBAAoB;IACrC,OAAO,CAAC,QAAQ,CAAC,mBAAmB;gBAFnB,eAAe,EAAE,mBAAmB,EACpC,oBAAoB,EAAE,wBAAwB,EAC9C,mBAAmB,EAAE,uBAAuB;IAUzD,KAAK;IA0BL,OAAO,CAAC,KAAK,EAAE,gBAAgB;IA2B/B,gBAAgB;IAehB,MAAM;IAoBN,gBAAgB,CAAC,KAAK,EAAE,gBAAgB;IAcxC,kBAAkB,CAAC,KAAK,EAAE,gBAAgB,EAAE,KAAK,EAAE,eAAe;IAcxE,aAAa;IASb,OAAO;IAGP,OAAO,CAAC,SAAS;IAKjB,OAAO,CAAC,YAAY;IAKpB,OAAO,CAAC,YAAY;IAKpB,OAAO,CAAC,gBAAgB;IAKxB,OAAO,CAAC,MAAM;CAGf"}
|
|
@@ -24,7 +24,7 @@ let CustomAgentExampleWorkflow = class CustomAgentExampleWorkflow extends common
|
|
|
24
24
|
this.llmDelegateToolCalls = llmDelegateToolCalls;
|
|
25
25
|
this.llmUpdateToolResult = llmUpdateToolResult;
|
|
26
26
|
}
|
|
27
|
-
async setup(
|
|
27
|
+
async setup() {
|
|
28
28
|
await this.documentStore.save(common_1.MarkdownDocument, {
|
|
29
29
|
markdown: '# Custom Agent Example\n\n' +
|
|
30
30
|
`This agent has a budget of **${MAX_TURNS} tool-using turns**. ` +
|
|
@@ -51,14 +51,14 @@ let CustomAgentExampleWorkflow = class CustomAgentExampleWorkflow extends common
|
|
|
51
51
|
llmResult: result.data,
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
|
-
async notifyOverBudget(
|
|
54
|
+
async notifyOverBudget() {
|
|
55
55
|
await this.documentStore.save(llm_provider_module_1.LlmMessageDocument, {
|
|
56
56
|
role: 'user',
|
|
57
57
|
text: `You have used your full turn budget of ${MAX_TURNS} tool-using turns and can no longer call tools. ` +
|
|
58
58
|
'Summarise what you found so far in plain text and answer based on that.',
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
|
-
async wrapUp(
|
|
61
|
+
async wrapUp() {
|
|
62
62
|
await this.llmGenerateText.call({}, {
|
|
63
63
|
config: {
|
|
64
64
|
provider: 'claude',
|
|
@@ -81,8 +81,8 @@ let CustomAgentExampleWorkflow = class CustomAgentExampleWorkflow extends common
|
|
|
81
81
|
});
|
|
82
82
|
this.assignState({ delegateResult: result.data });
|
|
83
83
|
}
|
|
84
|
-
toolsComplete(
|
|
85
|
-
respond(
|
|
84
|
+
toolsComplete() { }
|
|
85
|
+
respond() { }
|
|
86
86
|
hasBudget(state) {
|
|
87
87
|
return state.turnCount < MAX_TURNS;
|
|
88
88
|
}
|
|
@@ -95,7 +95,7 @@ let CustomAgentExampleWorkflow = class CustomAgentExampleWorkflow extends common
|
|
|
95
95
|
allToolsComplete(state) {
|
|
96
96
|
return !!state.delegateResult?.allCompleted;
|
|
97
97
|
}
|
|
98
|
-
|
|
98
|
+
isDone(state) {
|
|
99
99
|
return state.llmResult?.message.stopReason === 'end_turn';
|
|
100
100
|
}
|
|
101
101
|
};
|
|
@@ -103,7 +103,7 @@ exports.CustomAgentExampleWorkflow = CustomAgentExampleWorkflow;
|
|
|
103
103
|
__decorate([
|
|
104
104
|
(0, common_1.Transition)({ to: 'ready' }),
|
|
105
105
|
__metadata("design:type", Function),
|
|
106
|
-
__metadata("design:paramtypes", [
|
|
106
|
+
__metadata("design:paramtypes", []),
|
|
107
107
|
__metadata("design:returntype", Promise)
|
|
108
108
|
], CustomAgentExampleWorkflow.prototype, "setup", null);
|
|
109
109
|
__decorate([
|
|
@@ -117,13 +117,13 @@ __decorate([
|
|
|
117
117
|
(0, common_1.Transition)({ from: 'ready', to: 'over_budget' }),
|
|
118
118
|
(0, common_1.Guard)('isOverBudget'),
|
|
119
119
|
__metadata("design:type", Function),
|
|
120
|
-
__metadata("design:paramtypes", [
|
|
120
|
+
__metadata("design:paramtypes", []),
|
|
121
121
|
__metadata("design:returntype", Promise)
|
|
122
122
|
], CustomAgentExampleWorkflow.prototype, "notifyOverBudget", null);
|
|
123
123
|
__decorate([
|
|
124
124
|
(0, common_1.Transition)({ from: 'over_budget', to: 'end' }),
|
|
125
125
|
__metadata("design:type", Function),
|
|
126
|
-
__metadata("design:paramtypes", [
|
|
126
|
+
__metadata("design:paramtypes", []),
|
|
127
127
|
__metadata("design:returntype", Promise)
|
|
128
128
|
], CustomAgentExampleWorkflow.prototype, "wrapUp", null);
|
|
129
129
|
__decorate([
|
|
@@ -143,14 +143,14 @@ __decorate([
|
|
|
143
143
|
(0, common_1.Transition)({ from: 'awaiting_tools', to: 'ready' }),
|
|
144
144
|
(0, common_1.Guard)('allToolsComplete'),
|
|
145
145
|
__metadata("design:type", Function),
|
|
146
|
-
__metadata("design:paramtypes", [
|
|
146
|
+
__metadata("design:paramtypes", []),
|
|
147
147
|
__metadata("design:returntype", void 0)
|
|
148
148
|
], CustomAgentExampleWorkflow.prototype, "toolsComplete", null);
|
|
149
149
|
__decorate([
|
|
150
150
|
(0, common_1.Transition)({ from: 'prompt_executed', to: 'end' }),
|
|
151
|
-
(0, common_1.Guard)('
|
|
151
|
+
(0, common_1.Guard)('isDone'),
|
|
152
152
|
__metadata("design:type", Function),
|
|
153
|
-
__metadata("design:paramtypes", [
|
|
153
|
+
__metadata("design:paramtypes", []),
|
|
154
154
|
__metadata("design:returntype", void 0)
|
|
155
155
|
], CustomAgentExampleWorkflow.prototype, "respond", null);
|
|
156
156
|
exports.CustomAgentExampleWorkflow = CustomAgentExampleWorkflow = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-agent-example.workflow.js","sourceRoot":"","sources":["../../../src/workflows/custom-agent/custom-agent-example.workflow.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAiC;AACjC,8CAAgG;AAGhG,wEAKwC;AAExC,MAAM,SAAS,GAAG,CAAC,CAAC;AAyBb,IAAM,0BAA0B,GAAhC,MAAM,0BAA2B,SAAQ,qBAAY;IAEvC;IACA;IACA;IAHnB,YACmB,eAAoC,EACpC,oBAA8C,EAC9C,mBAA4C;QAE7D,KAAK,EAAE,CAAC;QAJS,oBAAe,GAAf,eAAe,CAAqB;QACpC,yBAAoB,GAApB,oBAAoB,CAA0B;QAC9C,wBAAmB,GAAnB,mBAAmB,CAAyB;IAG/D,CAAC;IAOK,AAAN,KAAK,CAAC,KAAK
|
|
1
|
+
{"version":3,"file":"custom-agent-example.workflow.js","sourceRoot":"","sources":["../../../src/workflows/custom-agent/custom-agent-example.workflow.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAiC;AACjC,8CAAgG;AAGhG,wEAKwC;AAExC,MAAM,SAAS,GAAG,CAAC,CAAC;AAyBb,IAAM,0BAA0B,GAAhC,MAAM,0BAA2B,SAAQ,qBAAY;IAEvC;IACA;IACA;IAHnB,YACmB,eAAoC,EACpC,oBAA8C,EAC9C,mBAA4C;QAE7D,KAAK,EAAE,CAAC;QAJS,oBAAe,GAAf,eAAe,CAAqB;QACpC,yBAAoB,GAApB,oBAAoB,CAA0B;QAC9C,wBAAmB,GAAnB,mBAAmB,CAAyB;IAG/D,CAAC;IAOK,AAAN,KAAK,CAAC,KAAK;QACT,MAAM,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,yBAAgB,EAAE;YAC9C,QAAQ,EACN,4BAA4B;gBAC5B,gCAAgC,SAAS,uBAAuB;gBAChE,2FAA2F;SAC9F,CAAC,CAAC;QAEH,MAAM,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,wCAAkB,EAAE;YAChD,IAAI,EAAE,MAAM;YACZ,IAAI,EACF,2FAA2F;gBAC3F,8EAA8E;gBAC9E,+EAA+E;SAClF,CAAC,CAAC;QAEH,IAAI,CAAC,WAAW,CAAC,EAAE,SAAS,EAAE,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-39,7 +39,7 @@
|
|
|
39
39
|
"@loopstack/llm-provider-module": "*",
|
|
40
40
|
"@loopstack/mcp-module": "*",
|
|
41
41
|
"@loopstack/remote-client": "*",
|
|
42
|
-
"@nestjs/common": "^
|
|
42
|
+
"@nestjs/common": "^12.0.1",
|
|
43
43
|
"zod": "^4.3.6"
|
|
44
44
|
},
|
|
45
45
|
"files": [
|
|
@@ -4,6 +4,8 @@ import type { RunContext } from '@loopstack/common';
|
|
|
4
4
|
|
|
5
5
|
export type CalculatorResult = string;
|
|
6
6
|
|
|
7
|
+
export const CalculatorResultSchema = z.string();
|
|
8
|
+
|
|
7
9
|
@Tool({
|
|
8
10
|
name: 'calculator',
|
|
9
11
|
description: 'Perform a basic arithmetic calculation. Supports add, subtract, multiply, divide.',
|
|
@@ -12,6 +14,8 @@ export type CalculatorResult = string;
|
|
|
12
14
|
a: z.number().describe('First operand.'),
|
|
13
15
|
b: z.number().describe('Second operand.'),
|
|
14
16
|
}),
|
|
17
|
+
resultSchema: CalculatorResultSchema,
|
|
18
|
+
effects: 'none',
|
|
15
19
|
})
|
|
16
20
|
export class CalculatorTool extends BaseTool<{ operation: string; a: number; b: number }, object, CalculatorResult> {
|
|
17
21
|
protected async handle(
|
|
@@ -3,12 +3,16 @@ import { BaseTool, Tool, ToolEnvelope } from '@loopstack/common';
|
|
|
3
3
|
|
|
4
4
|
export type WeatherLookupResult = string;
|
|
5
5
|
|
|
6
|
+
export const WeatherLookupResultSchema = z.string();
|
|
7
|
+
|
|
6
8
|
@Tool({
|
|
7
9
|
name: 'weather_lookup',
|
|
8
10
|
description: 'Look up the current weather for a given city. Returns a simulated forecast.',
|
|
9
11
|
schema: z.object({
|
|
10
12
|
city: z.string().describe('The city name to look up weather for.'),
|
|
11
13
|
}),
|
|
14
|
+
resultSchema: WeatherLookupResultSchema,
|
|
15
|
+
effects: 'none',
|
|
12
16
|
})
|
|
13
17
|
export class WeatherLookupTool extends BaseTool<{ city: string }, object, WeatherLookupResult> {
|
|
14
18
|
protected async handle(args: { city: string }): Promise<ToolEnvelope<WeatherLookupResult>> {
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { AgentModule } from '@loopstack/agent';
|
|
3
|
+
import { LlmGenerateTextTool, LlmProviderModule } from '@loopstack/llm-provider-module';
|
|
4
|
+
import { replay, runWorkflow } from '@loopstack/testing';
|
|
5
|
+
import { CalculatorTool } from '../../../tools/calculator.tool';
|
|
6
|
+
import { WeatherLookupTool } from '../../../tools/weather-lookup.tool';
|
|
7
|
+
import { AgentExampleWorkflow } from '../agent-example.workflow';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The canonical agent test: replay only the LLM (`replayTools: [LlmGenerateTextTool]`) so the
|
|
11
|
+
* model turns are scripted, while the delegation machinery and the real `weather_lookup` /
|
|
12
|
+
* `calculator` tools run live. The scripted turns drive one tool-use round then a final answer.
|
|
13
|
+
*/
|
|
14
|
+
const llmTurn = (message: { id: string; role: string; text: string; blocks: unknown[]; stopReason: string }) => ({
|
|
15
|
+
tool: 'llm_generate_text',
|
|
16
|
+
envelope: {
|
|
17
|
+
data: { message, response: {} },
|
|
18
|
+
metadata: { provider: 'claude', model: 'claude-sonnet-4-6' },
|
|
19
|
+
documents: [{ documentName: 'llm_message', content: message, options: { meta: { provider: 'claude' } } }],
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const TOOL_TURN = llmTurn({
|
|
24
|
+
id: 'msg_1',
|
|
25
|
+
role: 'assistant',
|
|
26
|
+
text: '',
|
|
27
|
+
blocks: [
|
|
28
|
+
{ type: 'tool_call', id: 'w1', name: 'weather_lookup', args: { city: 'Tokyo' } },
|
|
29
|
+
{ type: 'tool_call', id: 'c1', name: 'calculator', args: { operation: 'multiply', a: 42, b: 17 } },
|
|
30
|
+
],
|
|
31
|
+
stopReason: 'tool_use',
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const FINAL_TURN = llmTurn({
|
|
35
|
+
id: 'msg_2',
|
|
36
|
+
role: 'assistant',
|
|
37
|
+
text: 'Tokyo is sunny, and 42 * 17 = 714.',
|
|
38
|
+
blocks: [{ type: 'text', text: 'Tokyo is sunny, and 42 * 17 = 714.' }],
|
|
39
|
+
stopReason: 'end_turn',
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe('AgentExampleWorkflow', () => {
|
|
43
|
+
it('replays the LLM while the real tools run in the live delegation', async () => {
|
|
44
|
+
const run = await runWorkflow(AgentExampleWorkflow, undefined, {
|
|
45
|
+
imports: [LlmProviderModule, AgentModule],
|
|
46
|
+
providers: [WeatherLookupTool, CalculatorTool],
|
|
47
|
+
replayTools: [LlmGenerateTextTool],
|
|
48
|
+
replay: replay({ version: 3, recordings: [TOOL_TURN, FINAL_TURN] }),
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
expect(run.error).toBeUndefined();
|
|
52
|
+
expect(run.status).toBe('completed');
|
|
53
|
+
expect(run.path).toEqual(['start', 'agentComplete']);
|
|
54
|
+
expect(run.result).toEqual({ response: 'Tokyo is sunny, and 42 * 17 = 714.' });
|
|
55
|
+
|
|
56
|
+
// The agent sub-workflow ran the loop to completion (outcome, not internals).
|
|
57
|
+
expect(run.children[0].workflowName).toBe('agent');
|
|
58
|
+
expect(run.children[0].status).toBe('completed');
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -25,12 +25,12 @@ export class CodeAgentExampleWorkflow extends BaseWorkflow {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
@Transition({ to: 'verified' })
|
|
28
|
-
async verifyEnvironment(
|
|
28
|
+
async verifyEnvironment() {
|
|
29
29
|
await this.environments.assertReachable('sandbox');
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
@Transition({ from: 'verified', to: 'exploring' })
|
|
33
|
-
async startExploration(
|
|
33
|
+
async startExploration() {
|
|
34
34
|
await this.agentWorkflow.run(
|
|
35
35
|
{
|
|
36
36
|
system: 'You are a codebase exploration agent. Search and read source code to answer the question thoroughly.',
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { LlmGenerateTextTool, LlmProviderModule } from '@loopstack/llm-provider-module';
|
|
3
|
+
import { replay, runWorkflow } from '@loopstack/testing';
|
|
4
|
+
import { CalculatorTool } from '../../../tools/calculator.tool';
|
|
5
|
+
import { WeatherLookupTool } from '../../../tools/weather-lookup.tool';
|
|
6
|
+
import { CustomAgentExampleWorkflow } from '../custom-agent-example.workflow';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A hand-rolled agent loop with a deterministic turn budget. Scripting the LLM turns lets a
|
|
10
|
+
* test drive the loop *past* its budget and assert the control flow the generic AgentWorkflow
|
|
11
|
+
* can't express: after MAX_TURNS tool-using turns the workflow forces a no-tools wrap-up turn.
|
|
12
|
+
* The LLM is replayed; the delegation and the real weather tool run live.
|
|
13
|
+
*/
|
|
14
|
+
const toolUse = (id: string, city: string) => ({
|
|
15
|
+
tool: 'llm_generate_text',
|
|
16
|
+
envelope: {
|
|
17
|
+
data: {
|
|
18
|
+
message: {
|
|
19
|
+
id,
|
|
20
|
+
role: 'assistant',
|
|
21
|
+
text: '',
|
|
22
|
+
blocks: [{ type: 'tool_call', id: `w_${id}`, name: 'weather_lookup', args: { city } }],
|
|
23
|
+
stopReason: 'tool_use',
|
|
24
|
+
},
|
|
25
|
+
response: {},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const wrapUp = () => ({
|
|
31
|
+
tool: 'llm_generate_text',
|
|
32
|
+
envelope: {
|
|
33
|
+
data: {
|
|
34
|
+
message: {
|
|
35
|
+
id: 'final',
|
|
36
|
+
role: 'assistant',
|
|
37
|
+
text: 'Budget reached — none of the cities I checked were warm enough.',
|
|
38
|
+
blocks: [{ type: 'text', text: 'Budget reached — none of the cities I checked were warm enough.' }],
|
|
39
|
+
stopReason: 'end_turn',
|
|
40
|
+
},
|
|
41
|
+
response: {},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe('CustomAgentExampleWorkflow', () => {
|
|
47
|
+
it('runs two tool-using turns then forces a no-tools wrap-up when the budget is spent', async () => {
|
|
48
|
+
const run = await runWorkflow(CustomAgentExampleWorkflow, undefined, {
|
|
49
|
+
imports: [LlmProviderModule],
|
|
50
|
+
providers: [WeatherLookupTool, CalculatorTool],
|
|
51
|
+
replayTools: [LlmGenerateTextTool],
|
|
52
|
+
// Two tool-using turns exhaust the 2-turn budget, then the wrap-up turn (no tools).
|
|
53
|
+
replay: replay({ version: 3, recordings: [toolUse('t1', 'London'), toolUse('t2', 'New York'), wrapUp()] }),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
expect(run.error).toBeUndefined();
|
|
57
|
+
expect(run.status).toBe('completed');
|
|
58
|
+
expect(run.place).toBe('end');
|
|
59
|
+
|
|
60
|
+
// The budget guard fired: exactly two tool-using turns, then the forced wrap-up path.
|
|
61
|
+
expect(run.path.filter((t) => t === 'llmTurn')).toHaveLength(2);
|
|
62
|
+
expect(run.path).toContain('notifyOverBudget');
|
|
63
|
+
expect(run.path).toContain('wrapUp');
|
|
64
|
+
|
|
65
|
+
// The over-budget notice was shown to the model before the wrap-up turn.
|
|
66
|
+
const texts = run.documents.map((d) => (d.content as { text?: string }).text ?? '');
|
|
67
|
+
expect(texts.some((t) => t.includes('used your full turn budget'))).toBe(true);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -48,7 +48,7 @@ export class CustomAgentExampleWorkflow extends BaseWorkflow {
|
|
|
48
48
|
* conversation with the user's request, and initialises the turn counter.
|
|
49
49
|
*/
|
|
50
50
|
@Transition({ to: 'ready' })
|
|
51
|
-
async setup(
|
|
51
|
+
async setup() {
|
|
52
52
|
await this.documentStore.save(MarkdownDocument, {
|
|
53
53
|
markdown:
|
|
54
54
|
'# Custom Agent Example\n\n' +
|
|
@@ -101,7 +101,7 @@ export class CustomAgentExampleWorkflow extends BaseWorkflow {
|
|
|
101
101
|
*/
|
|
102
102
|
@Transition({ from: 'ready', to: 'over_budget' })
|
|
103
103
|
@Guard('isOverBudget')
|
|
104
|
-
async notifyOverBudget(
|
|
104
|
+
async notifyOverBudget() {
|
|
105
105
|
await this.documentStore.save(LlmMessageDocument, {
|
|
106
106
|
role: 'user',
|
|
107
107
|
text:
|
|
@@ -116,7 +116,7 @@ export class CustomAgentExampleWorkflow extends BaseWorkflow {
|
|
|
116
116
|
* summary based on whatever results were gathered before the budget hit.
|
|
117
117
|
*/
|
|
118
118
|
@Transition({ from: 'over_budget', to: 'end' })
|
|
119
|
-
async wrapUp(
|
|
119
|
+
async wrapUp() {
|
|
120
120
|
await this.llmGenerateText.call(
|
|
121
121
|
{},
|
|
122
122
|
{
|
|
@@ -164,7 +164,7 @@ export class CustomAgentExampleWorkflow extends BaseWorkflow {
|
|
|
164
164
|
*/
|
|
165
165
|
@Transition({ from: 'awaiting_tools', to: 'ready' })
|
|
166
166
|
@Guard('allToolsComplete')
|
|
167
|
-
toolsComplete(
|
|
167
|
+
toolsComplete() {}
|
|
168
168
|
|
|
169
169
|
/**
|
|
170
170
|
* The LLM emitted `end_turn` instead of more tool calls — it considers the
|
|
@@ -172,8 +172,8 @@ export class CustomAgentExampleWorkflow extends BaseWorkflow {
|
|
|
172
172
|
* just close the workflow.
|
|
173
173
|
*/
|
|
174
174
|
@Transition({ from: 'prompt_executed', to: 'end' })
|
|
175
|
-
@Guard('
|
|
176
|
-
respond(
|
|
175
|
+
@Guard('isDone')
|
|
176
|
+
respond() {}
|
|
177
177
|
|
|
178
178
|
/** True while the model is still allowed to take another tool-using turn. */
|
|
179
179
|
private hasBudget(state: CustomAgentState): boolean {
|
|
@@ -196,7 +196,7 @@ export class CustomAgentExampleWorkflow extends BaseWorkflow {
|
|
|
196
196
|
}
|
|
197
197
|
|
|
198
198
|
/** True when the last LLM response was a final plain-text answer (no tools). */
|
|
199
|
-
private
|
|
199
|
+
private isDone(state: CustomAgentState): boolean {
|
|
200
200
|
return state.llmResult?.message.stopReason === 'end_turn';
|
|
201
201
|
}
|
|
202
202
|
}
|