@statelyai/agent 2.0.0-next.1 → 2.0.0-next.2
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/.changeset/grumpy-dolphins-think.md +17 -0
- package/.changeset/old-teachers-tap.md +5 -0
- package/.changeset/pre.json +4 -1
- package/.changeset/smart-yaks-pull.md +23 -0
- package/CHANGELOG.md +40 -0
- package/dist/index.d.mts +55 -46
- package/dist/index.d.ts +55 -46
- package/dist/index.js +78 -50
- package/dist/index.mjs +81 -53
- package/examples/chatbot.ts +2 -2
- package/examples/cot.ts +6 -24
- package/examples/customer-service-sim.ts +3 -3
- package/examples/email.ts +9 -3
- package/examples/example.ts +2 -2
- package/examples/goal.ts +2 -2
- package/examples/joke.ts +2 -2
- package/examples/jugs.ts +4 -7
- package/examples/learn-from-feedback.ts +100 -0
- package/examples/number.ts +2 -2
- package/examples/raffle.ts +2 -2
- package/examples/river-crossing.ts +4 -7
- package/examples/simple.ts +13 -10
- package/examples/summary.ts +2 -5
- package/examples/support.ts +42 -38
- package/examples/ticTacToe.ts +46 -4
- package/examples/todo.ts +2 -2
- package/examples/tutor.ts +2 -2
- package/examples/verify.ts +2 -2
- package/examples/weather-agent.ts +141 -0
- package/examples/weather.ts +23 -23
- package/examples/word.ts +8 -6
- package/package.json +2 -1
- package/src/agent.test.ts +17 -15
- package/src/agent.ts +48 -35
- package/src/decide.test.ts +56 -8
- package/src/decide.ts +34 -24
- package/src/strategies/chainOfThought.ts +48 -0
- package/src/{planners → strategies}/shortestPath.test.ts +4 -7
- package/src/strategies/shortestPath.ts +173 -0
- package/src/{planners → strategies}/simple.ts +28 -18
- package/src/types.ts +62 -28
- package/src/utils.ts +12 -0
- package/src/planners/shortestPath.ts +0 -177
- package/src/strategies/chain-of-note.ts +0 -106
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { GenerateTextResult, LanguageModel } from 'ai';
|
|
2
|
-
import wiki, { wikiSearchResult, wikiSummary } from 'wikipedia';
|
|
3
|
-
import { assign, fromPromise, setup } from 'xstate';
|
|
4
|
-
import { AnyAgent } from '../types';
|
|
5
|
-
|
|
6
|
-
const searchWiki = fromPromise(
|
|
7
|
-
async ({
|
|
8
|
-
input,
|
|
9
|
-
}: {
|
|
10
|
-
input: {
|
|
11
|
-
query: string;
|
|
12
|
-
limit?: number;
|
|
13
|
-
};
|
|
14
|
-
}) => {
|
|
15
|
-
const passages = await wiki.search(input.query, {
|
|
16
|
-
limit: input.limit ?? 5,
|
|
17
|
-
});
|
|
18
|
-
return passages;
|
|
19
|
-
}
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
const extractSummaries = fromPromise(
|
|
23
|
-
async ({
|
|
24
|
-
input,
|
|
25
|
-
}: {
|
|
26
|
-
input: {
|
|
27
|
-
searchResult: wikiSearchResult;
|
|
28
|
-
};
|
|
29
|
-
}) => {
|
|
30
|
-
const summaries = await Promise.all(
|
|
31
|
-
input.searchResult.results.map(async (result) => {
|
|
32
|
-
const summary = await wiki.summary(result.title);
|
|
33
|
-
return {
|
|
34
|
-
title: result.title,
|
|
35
|
-
summary,
|
|
36
|
-
};
|
|
37
|
-
})
|
|
38
|
-
);
|
|
39
|
-
return summaries;
|
|
40
|
-
}
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
export const chainOfNote = setup({
|
|
44
|
-
types: {
|
|
45
|
-
input: {} as {
|
|
46
|
-
model: LanguageModel;
|
|
47
|
-
agent: AnyAgent;
|
|
48
|
-
prompt: string;
|
|
49
|
-
},
|
|
50
|
-
context: {} as {
|
|
51
|
-
searchResults: wikiSearchResult | null;
|
|
52
|
-
summaries:
|
|
53
|
-
| {
|
|
54
|
-
title: any;
|
|
55
|
-
summary: wikiSummary;
|
|
56
|
-
}[]
|
|
57
|
-
| null;
|
|
58
|
-
model: LanguageModel;
|
|
59
|
-
agent: AnyAgent;
|
|
60
|
-
prompt: string;
|
|
61
|
-
},
|
|
62
|
-
output: {} as GenerateTextResult<any>,
|
|
63
|
-
},
|
|
64
|
-
actors: {
|
|
65
|
-
searchWiki,
|
|
66
|
-
extractSummaries,
|
|
67
|
-
},
|
|
68
|
-
}).createMachine({
|
|
69
|
-
initial: 'searching',
|
|
70
|
-
context: ({ input }) => ({
|
|
71
|
-
...input,
|
|
72
|
-
searchResults: null,
|
|
73
|
-
summaries: null,
|
|
74
|
-
}),
|
|
75
|
-
states: {
|
|
76
|
-
searching: {
|
|
77
|
-
invoke: {
|
|
78
|
-
src: 'searchWiki',
|
|
79
|
-
input: ({ context }) => ({
|
|
80
|
-
query: context.prompt,
|
|
81
|
-
}),
|
|
82
|
-
onDone: {
|
|
83
|
-
actions: assign({
|
|
84
|
-
searchResults: ({ event }) => event.output,
|
|
85
|
-
}),
|
|
86
|
-
target: 'extracting',
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
extracting: {
|
|
91
|
-
invoke: {
|
|
92
|
-
src: 'extractSummaries',
|
|
93
|
-
input: ({ context }) => ({
|
|
94
|
-
searchResult: context.searchResults!,
|
|
95
|
-
}),
|
|
96
|
-
onDone: {
|
|
97
|
-
actions: assign({
|
|
98
|
-
summaries: ({ event }) => event.output,
|
|
99
|
-
}),
|
|
100
|
-
target: 'generating',
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
|
-
},
|
|
104
|
-
generating: {},
|
|
105
|
-
},
|
|
106
|
-
});
|