@statelyai/agent 2.0.0-next.1 → 2.0.0-next.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/.changeset/grumpy-dolphins-think.md +17 -0
- package/.changeset/old-teachers-tap.md +5 -0
- package/.changeset/pink-eagles-deliver.md +13 -0
- package/.changeset/pre.json +9 -1
- package/.changeset/quiet-turtles-do.md +7 -0
- package/.changeset/smart-yaks-pull.md +23 -0
- package/.changeset/sweet-clouds-mix.md +16 -0
- package/.changeset/swift-mangos-rush.md +5 -0
- package/.changeset/tough-ways-rhyme.md +5 -0
- package/CHANGELOG.md +79 -0
- package/dist/index.d.mts +116 -100
- package/dist/index.d.ts +116 -100
- package/dist/index.js +102 -72
- package/dist/index.mjs +105 -75
- package/examples/chatbot.ts +2 -2
- package/examples/cot.ts +21 -73
- package/examples/customer-service-sim.ts +3 -3
- package/examples/email.ts +3 -5
- package/examples/example.ts +2 -2
- package/examples/goal.ts +2 -2
- package/examples/joke.ts +12 -12
- package/examples/jugs.ts +4 -7
- package/examples/learn-from-feedback.ts +123 -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 +38 -38
- package/examples/ticTacToe.ts +46 -4
- package/examples/todo.ts +3 -3
- package/examples/tutor.ts +2 -2
- package/examples/verify.ts +2 -2
- package/examples/weather-agent.ts +139 -0
- package/examples/weather.ts +26 -23
- package/examples/word.ts +8 -6
- package/package.json +2 -1
- package/src/agent.test.ts +37 -52
- package/src/agent.ts +93 -60
- package/src/decide.test.ts +56 -8
- package/src/decide.ts +42 -32
- package/src/strategies/chainOfThought.ts +50 -0
- package/src/{planners → strategies}/shortestPath.test.ts +4 -7
- package/src/strategies/shortestPath.ts +178 -0
- package/src/{planners → strategies}/simple.ts +25 -26
- package/src/templates/defaultText.ts +3 -0
- package/src/text.ts +13 -13
- package/src/types.ts +124 -83
- package/src/utils.ts +13 -1
- 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
|
-
});
|