Skip to content

Commit 391dc38

Browse files
committed
Add tool to run pipeline via chat interface
Addresses #21
1 parent c90fc70 commit 391dc38

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { tool } from 'litlytics';
2+
import { z } from 'zod';
3+
import { ToolDefinition } from '../types';
4+
5+
const description = `Function description: Execute current pipeline with all documents`;
6+
7+
export const runPipeline: ToolDefinition = {
8+
name: 'runPipeline',
9+
description,
10+
create: ({
11+
litlytics,
12+
setPipeline,
13+
agentMessages,
14+
messages,
15+
resolve,
16+
reject,
17+
}) =>
18+
tool({
19+
description,
20+
parameters: z.object({
21+
execute: z.boolean(),
22+
}),
23+
execute: async () => {
24+
try {
25+
// run pipeline
26+
const newPipeline = await litlytics.runPipeline();
27+
setPipeline(newPipeline);
28+
// generate a response
29+
const agentMessagesWithResult = agentMessages.concat([
30+
{
31+
content: `Pipeline executed. Results:
32+
${newPipeline.results?.map((r) => '- ' + r.result)?.join('\n')}
33+
34+
Notify user. Be brief.`,
35+
role: 'system',
36+
},
37+
]);
38+
const result = await litlytics.runPromptFromMessages({
39+
messages: agentMessagesWithResult,
40+
});
41+
resolve(
42+
messages.concat({
43+
id: String(messages.length),
44+
from: 'assistant',
45+
text: result.result,
46+
})
47+
);
48+
} catch (err) {
49+
reject(err as Error);
50+
}
51+
},
52+
}),
53+
};

app/components/agent/logic/tools/tools.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { analyzeDocuments } from './analyzeDocs';
33
import { createSuggestedPipeline } from './createSuggestedPipeline';
44
import { editStep } from './editStep';
55
import { refinePipeline } from './refinePipeline';
6+
import { runPipeline } from './runPipeline';
67
import { suggestPipeline } from './suggestPipeline';
78
import { testStep } from './testStep';
89

@@ -14,4 +15,5 @@ export const agentTools = [
1415
addNewStep,
1516
editStep,
1617
testStep,
18+
runPipeline,
1719
];

0 commit comments

Comments
 (0)