@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.
Files changed (44) hide show
  1. package/.changeset/grumpy-dolphins-think.md +17 -0
  2. package/.changeset/old-teachers-tap.md +5 -0
  3. package/.changeset/pre.json +4 -1
  4. package/.changeset/smart-yaks-pull.md +23 -0
  5. package/CHANGELOG.md +40 -0
  6. package/dist/index.d.mts +55 -46
  7. package/dist/index.d.ts +55 -46
  8. package/dist/index.js +78 -50
  9. package/dist/index.mjs +81 -53
  10. package/examples/chatbot.ts +2 -2
  11. package/examples/cot.ts +6 -24
  12. package/examples/customer-service-sim.ts +3 -3
  13. package/examples/email.ts +9 -3
  14. package/examples/example.ts +2 -2
  15. package/examples/goal.ts +2 -2
  16. package/examples/joke.ts +2 -2
  17. package/examples/jugs.ts +4 -7
  18. package/examples/learn-from-feedback.ts +100 -0
  19. package/examples/number.ts +2 -2
  20. package/examples/raffle.ts +2 -2
  21. package/examples/river-crossing.ts +4 -7
  22. package/examples/simple.ts +13 -10
  23. package/examples/summary.ts +2 -5
  24. package/examples/support.ts +42 -38
  25. package/examples/ticTacToe.ts +46 -4
  26. package/examples/todo.ts +2 -2
  27. package/examples/tutor.ts +2 -2
  28. package/examples/verify.ts +2 -2
  29. package/examples/weather-agent.ts +141 -0
  30. package/examples/weather.ts +23 -23
  31. package/examples/word.ts +8 -6
  32. package/package.json +2 -1
  33. package/src/agent.test.ts +17 -15
  34. package/src/agent.ts +48 -35
  35. package/src/decide.test.ts +56 -8
  36. package/src/decide.ts +34 -24
  37. package/src/strategies/chainOfThought.ts +48 -0
  38. package/src/{planners → strategies}/shortestPath.test.ts +4 -7
  39. package/src/strategies/shortestPath.ts +173 -0
  40. package/src/{planners → strategies}/simple.ts +28 -18
  41. package/src/types.ts +62 -28
  42. package/src/utils.ts +12 -0
  43. package/src/planners/shortestPath.ts +0 -177
  44. 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
- });