@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.
Files changed (51) hide show
  1. package/.changeset/grumpy-dolphins-think.md +17 -0
  2. package/.changeset/old-teachers-tap.md +5 -0
  3. package/.changeset/pink-eagles-deliver.md +13 -0
  4. package/.changeset/pre.json +9 -1
  5. package/.changeset/quiet-turtles-do.md +7 -0
  6. package/.changeset/smart-yaks-pull.md +23 -0
  7. package/.changeset/sweet-clouds-mix.md +16 -0
  8. package/.changeset/swift-mangos-rush.md +5 -0
  9. package/.changeset/tough-ways-rhyme.md +5 -0
  10. package/CHANGELOG.md +79 -0
  11. package/dist/index.d.mts +116 -100
  12. package/dist/index.d.ts +116 -100
  13. package/dist/index.js +102 -72
  14. package/dist/index.mjs +105 -75
  15. package/examples/chatbot.ts +2 -2
  16. package/examples/cot.ts +21 -73
  17. package/examples/customer-service-sim.ts +3 -3
  18. package/examples/email.ts +3 -5
  19. package/examples/example.ts +2 -2
  20. package/examples/goal.ts +2 -2
  21. package/examples/joke.ts +12 -12
  22. package/examples/jugs.ts +4 -7
  23. package/examples/learn-from-feedback.ts +123 -0
  24. package/examples/number.ts +2 -2
  25. package/examples/raffle.ts +2 -2
  26. package/examples/river-crossing.ts +4 -7
  27. package/examples/simple.ts +13 -10
  28. package/examples/summary.ts +2 -5
  29. package/examples/support.ts +38 -38
  30. package/examples/ticTacToe.ts +46 -4
  31. package/examples/todo.ts +3 -3
  32. package/examples/tutor.ts +2 -2
  33. package/examples/verify.ts +2 -2
  34. package/examples/weather-agent.ts +139 -0
  35. package/examples/weather.ts +26 -23
  36. package/examples/word.ts +8 -6
  37. package/package.json +2 -1
  38. package/src/agent.test.ts +37 -52
  39. package/src/agent.ts +93 -60
  40. package/src/decide.test.ts +56 -8
  41. package/src/decide.ts +42 -32
  42. package/src/strategies/chainOfThought.ts +50 -0
  43. package/src/{planners → strategies}/shortestPath.test.ts +4 -7
  44. package/src/strategies/shortestPath.ts +178 -0
  45. package/src/{planners → strategies}/simple.ts +25 -26
  46. package/src/templates/defaultText.ts +3 -0
  47. package/src/text.ts +13 -13
  48. package/src/types.ts +124 -83
  49. package/src/utils.ts +13 -1
  50. package/src/planners/shortestPath.ts +0 -177
  51. package/src/strategies/chain-of-note.ts +0 -106
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as ai from 'ai';
2
2
  import { generateText, streamText, LanguageModel, CoreMessage, GenerateTextResult, LanguageModelV1, CoreTool } from 'ai';
3
- import { EventObject, AnyStateMachine, AnyEventObject, ActorRefLike, SnapshotFrom, EventFrom, PromiseActorLogic, ActorLogic, TransitionSnapshot, Values, StateValue, Actor, Subscription, ObservableActorLogic } from 'xstate';
3
+ import { AnyStateMachine, AnyEventObject, ActorRefLike, SnapshotFrom, EventFrom, PromiseActorLogic, ActorLogic, TransitionSnapshot, Values, StateValue, EventObject, Actor, Subscription, ObservableActorLogic } from 'xstate';
4
4
  import { SomeZodObject, ZodType, TypeOf } from 'zod';
5
5
 
6
6
  type ZodEventMapping = {
@@ -12,15 +12,19 @@ type ZodContextMapping = {
12
12
 
13
13
  type GenerateTextOptions = Parameters<typeof generateText>[0];
14
14
  type StreamTextOptions = Parameters<typeof streamText>[0];
15
- type CostFunction<TEvent extends EventObject> = (path: AgentPath<TEvent>) => number;
16
- type AgentPlanInput<TEvent extends EventObject> = Omit<AgentGenerateTextOptions, 'prompt' | 'tools'> & {
15
+ type CostFunction<TAgent extends AnyAgent> = (path: AgentPath<TAgent>) => number;
16
+ type AgentDecideInput<TAgent extends AnyAgent> = Omit<AgentGenerateTextOptions<TAgent>, 'prompt' | 'tools'> & {
17
17
  /**
18
18
  * The currently observed state.
19
19
  */
20
- state: ObservedState;
20
+ state: ObservedState<TAgent>;
21
+ /**
22
+ * The context to provide in the prompt to the agent. This overrides the `state.context`.
23
+ */
24
+ context?: Record<string, any>;
21
25
  /**
22
26
  * The goal for the agent to accomplish.
23
- * The agent will create a plan based on this goal.
27
+ * The agent will make a decision based on this goal.
24
28
  */
25
29
  goal: string;
26
30
  /**
@@ -33,53 +37,50 @@ type AgentPlanInput<TEvent extends EventObject> = Omit<AgentGenerateTextOptions,
33
37
  * is interacting with.
34
38
  */
35
39
  machine?: AnyStateMachine;
36
- /**
37
- * The previous plan.
38
- */
39
- previousPlan?: AgentPlan<TEvent>;
40
40
  /**
41
41
  * The total cost of the path to the goal state.
42
42
  */
43
- costFunction?: CostFunction<TEvent>;
43
+ costFunction?: CostFunction<TAgent>;
44
44
  /**
45
- * The maximum number of attempts to generate a plan.
45
+ * The maximum number of attempts to make a decision.
46
46
  * Defaults to 2.
47
47
  */
48
48
  maxAttempts?: number;
49
49
  };
50
- type AgentStep<TEvent extends EventObject> = {
50
+ type AgentStep<TAgent extends AnyAgent> = {
51
51
  /** The event to take */
52
- event: TEvent;
52
+ event: EventFromAgent<TAgent>;
53
53
  /** The next expected state after taking the event */
54
- state: ObservedState | undefined;
54
+ state: ObservedState<TAgent> | undefined;
55
55
  };
56
- type AgentPath<TEvent extends EventObject> = {
56
+ type AgentPath<TAgent extends AnyAgent> = {
57
57
  /** The expected ending state of the path */
58
- state: ObservedState | undefined;
58
+ state: ObservedState<TAgent> | undefined;
59
59
  /** The steps to reach the ending state */
60
- steps: Array<AgentStep<TEvent>>;
60
+ steps: Array<AgentStep<TAgent>>;
61
61
  weight?: number;
62
62
  };
63
- type AgentPlan<TEvent extends EventObject> = {
63
+ type AgentDecision<TAgent extends AnyAgent> = {
64
+ id: string;
64
65
  /**
65
- * The planner used to generate the plan
66
+ * The strategy used to generate the decision
66
67
  */
67
- planner: string;
68
+ strategy: string;
68
69
  goal: string;
69
70
  /**
70
- * The ending state of the plan.
71
+ * The ending state of the decision.
71
72
  */
72
- goalState: ObservedState | undefined;
73
+ goalState: ObservedState<TAgent> | undefined;
73
74
  /**
74
75
  * The next event that the agent decided needs to occur to achieve the `goal`.
75
76
  *
76
77
  * This next event is chosen from the
77
78
  */
78
- nextEvent: TEvent | undefined;
79
+ nextEvent: EventFromAgent<TAgent> | undefined;
79
80
  /**
80
81
  * The paths that the agent can take to achieve the goal.
81
82
  */
82
- paths: AgentPath<TEvent>[];
83
+ paths: AgentPath<TAgent>[];
83
84
  episodeId: string;
84
85
  timestamp: number;
85
86
  };
@@ -91,17 +92,13 @@ interface TransitionData {
91
92
  };
92
93
  target?: any;
93
94
  }
94
- type PromptTemplate<TEvents extends EventObject> = (data: {
95
+ type PromptTemplate<TAgent extends AnyAgent> = (data: {
95
96
  goal: string;
96
97
  /**
97
98
  * The observed state
98
99
  */
99
- state?: ObservedState;
100
- /**
101
- * The context to provide.
102
- * This overrides the observed state.context, if provided.
103
- */
104
- context?: any;
100
+ stateValue?: any;
101
+ context?: Record<string, any>;
105
102
  /**
106
103
  * The state machine model of the observed environment
107
104
  */
@@ -117,17 +114,25 @@ type PromptTemplate<TEvents extends EventObject> = (data: {
117
114
  observations?: AgentObservation<any>[];
118
115
  feedback?: AgentFeedback[];
119
116
  messages?: AgentMessage[];
120
- plans?: AgentPlan<TEvents>[];
117
+ decisions?: AgentDecision<TAgent>[];
121
118
  }) => string;
122
- type AgentPlanner<T extends AnyAgent> = (agent: T, input: AgentPlanInput<T['types']['events']>) => Promise<AgentPlan<T['types']['events']> | undefined>;
123
- type AgentDecideOptions<T extends AnyAgent> = {
119
+ type AgentStrategy<TAgent extends AnyAgent> = (agent: TAgent, input: AgentDecideInput<EventFromAgent<TAgent>>) => Promise<AgentDecision<TAgent> | undefined>;
120
+ type AgentInteractInput<T extends AnyAgent> = Omit<AgentDecideOptions<T>, 'state'> & {
121
+ state?: never;
122
+ };
123
+ type AgentDecideOptions<TAgent extends AnyAgent> = {
124
124
  goal: string;
125
- model?: LanguageModel;
126
- state: ObservedState;
125
+ state: ObservedState<TAgent>;
126
+ /**
127
+ * The context to provide in the prompt to the agent. This overrides the `state.context`.
128
+ */
129
+ context?: Record<string, any>;
127
130
  machine?: AnyStateMachine;
131
+ model?: LanguageModel;
128
132
  execute?: (event: AnyEventObject) => Promise<void>;
129
- planner?: AgentPlanner<T>;
133
+ strategy?: AgentStrategy<TAgent>;
130
134
  events?: ZodEventMapping;
135
+ allowedEvents?: Array<EventFromAgent<TAgent>['type']>;
131
136
  /**
132
137
  * The maximum number of times the agent will attempt to make a decision.
133
138
  * Defaults to 2.
@@ -135,22 +140,22 @@ type AgentDecideOptions<T extends AnyAgent> = {
135
140
  maxAttempts?: number;
136
141
  } & Omit<Parameters<typeof generateText>[0], 'model' | 'tools' | 'prompt'>;
137
142
  interface AgentFeedback {
138
- goal?: string;
139
- observationId?: string;
143
+ observationId: string;
144
+ score: number;
145
+ comment: string | undefined;
140
146
  /**
141
147
  * The message correlation that the feedback is relevant for
142
148
  */
143
149
  attributes: Record<string, any>;
144
- reward: number;
145
150
  timestamp: number;
146
151
  episodeId: string;
147
152
  }
148
153
  interface AgentFeedbackInput {
149
- goal?: string;
150
- observationId?: string;
154
+ observationId: string;
155
+ score: number;
156
+ comment?: string;
151
157
  attributes?: Record<string, any>;
152
158
  timestamp?: number;
153
- reward?: number;
154
159
  }
155
160
  type AgentMessage = CoreMessage & {
156
161
  timestamp: number;
@@ -215,6 +220,7 @@ type AgentMessageInput = CoreMessage & {
215
220
  };
216
221
  interface AgentObservation<TActor extends ActorRefLike> {
217
222
  id: string;
223
+ goal?: string;
218
224
  prevState: SnapshotFrom<TActor> | undefined;
219
225
  event: EventFrom<TActor> | undefined;
220
226
  state: SnapshotFrom<TActor>;
@@ -222,21 +228,22 @@ interface AgentObservation<TActor extends ActorRefLike> {
222
228
  episodeId: string;
223
229
  timestamp: number;
224
230
  }
225
- interface AgentObservationInput {
231
+ interface AgentObservationInput<TAgent extends AnyAgent> {
226
232
  id?: string;
227
- prevState?: ObservedState;
233
+ prevState?: ObservedState<TAgent>;
228
234
  event?: AnyEventObject;
229
- state: ObservedState;
235
+ state: ObservedState<TAgent>;
230
236
  machine?: AnyStateMachine;
231
237
  timestamp?: number;
238
+ goal: string | undefined;
232
239
  }
233
240
  type AgentDecisionInput = {
234
241
  goal: string;
235
242
  model?: LanguageModel;
236
243
  context?: Record<string, any>;
237
244
  } & Omit<Parameters<typeof generateText>[0], 'model' | 'tools' | 'prompt'>;
238
- type AgentDecisionLogic<TEvents extends EventObject> = PromiseActorLogic<AgentPlan<TEvents> | undefined, AgentDecisionInput | string>;
239
- type AgentEmitted<TEvents extends EventObject> = {
245
+ type AgentDecisionLogic<TAgent extends AnyAgent> = PromiseActorLogic<AgentDecision<TAgent> | undefined, AgentDecisionInput | string>;
246
+ type AgentEmitted<TAgent extends AnyAgent> = {
240
247
  type: 'feedback';
241
248
  feedback: AgentFeedback;
242
249
  } | {
@@ -246,10 +253,10 @@ type AgentEmitted<TEvents extends EventObject> = {
246
253
  type: 'message';
247
254
  message: AgentMessage;
248
255
  } | {
249
- type: 'plan';
250
- plan: AgentPlan<TEvents>;
256
+ type: 'decision';
257
+ decision: AgentDecision<TAgent>;
251
258
  };
252
- type AgentLogic<TEvents extends EventObject> = ActorLogic<TransitionSnapshot<AgentMemoryContext>, {
259
+ type AgentLogic<TAgent extends AnyAgent> = ActorLogic<TransitionSnapshot<AgentMemoryContext<TAgent>>, {
253
260
  type: 'agent.feedback';
254
261
  feedback: AgentFeedback;
255
262
  } | {
@@ -259,30 +266,30 @@ type AgentLogic<TEvents extends EventObject> = ActorLogic<TransitionSnapshot<Age
259
266
  type: 'agent.message';
260
267
  message: AgentMessage;
261
268
  } | {
262
- type: 'agent.plan';
263
- plan: AgentPlan<TEvents>;
269
+ type: 'agent.decision';
270
+ decision: AgentDecision<TAgent>;
264
271
  }, any, // TODO: input
265
- any, AgentEmitted<TEvents>>;
266
- type EventsFromZodEventMapping<TEventSchemas extends ZodEventMapping> = Values<{
272
+ any, AgentEmitted<TAgent>>;
273
+ type EventsFromZodEventMapping<TEventSchemas extends ZodEventMapping> = Compute<Values<{
267
274
  [K in keyof TEventSchemas & string]: {
268
275
  type: K;
269
276
  } & TypeOf<TEventSchemas[K]>;
270
- }>;
277
+ }>>;
271
278
  type ContextFromZodContextMapping<TContextSchema extends ZodContextMapping> = {
272
279
  [K in keyof TContextSchema & string]: TypeOf<TContextSchema[K]>;
273
280
  };
274
281
  type AnyAgent = Agent<any, any, any, any>;
275
282
  type FromAgent<T> = T | ((agent: AnyAgent) => T | Promise<T>);
276
- type CommonTextOptions = {
283
+ type CommonTextOptions<TAgent extends AnyAgent> = {
277
284
  prompt: FromAgent<string>;
278
285
  model?: LanguageModel;
279
- context?: Record<string, any>;
280
286
  messages?: FromAgent<CoreMessage[]>;
281
287
  template?: PromptTemplate<any>;
288
+ context?: Record<string, any>;
282
289
  };
283
- type AgentGenerateTextOptions = Omit<GenerateTextOptions, 'model' | 'prompt' | 'messages'> & CommonTextOptions;
284
- type AgentStreamTextOptions = Omit<StreamTextOptions, 'model' | 'prompt' | 'messages'> & CommonTextOptions;
285
- interface ObservedState {
290
+ type AgentGenerateTextOptions<TAgent extends AnyAgent> = Omit<GenerateTextOptions, 'model' | 'prompt' | 'messages'> & CommonTextOptions<TAgent>;
291
+ type AgentStreamTextOptions<TAgent extends AnyAgent> = Omit<StreamTextOptions, 'model' | 'prompt' | 'messages'> & CommonTextOptions<TAgent>;
292
+ interface ObservedState<TAgent extends AnyAgent> {
286
293
  /**
287
294
  * The current state value of the state machine, e.g.
288
295
  * `"loading"` or `"processing"` or `"ready"`
@@ -291,25 +298,32 @@ interface ObservedState {
291
298
  /**
292
299
  * Additional contextual data related to the current state
293
300
  */
294
- context?: Record<string, unknown>;
301
+ context?: ContextFromAgent<TAgent>;
295
302
  }
296
303
  type ObservedStateFrom<TActor extends ActorRefLike> = Pick<SnapshotFrom<TActor>, 'value' | 'context'>;
297
- type AgentMemoryContext = {
298
- observations: AgentObservation<any>[];
304
+ type AgentMemoryContext<TAgent extends AnyAgent> = {
305
+ observations: AgentObservation<TAgent>[];
299
306
  messages: AgentMessage[];
300
- plans: AgentPlan<any>[];
307
+ decisions: AgentDecision<TAgent>[];
301
308
  feedback: AgentFeedback[];
302
309
  };
303
- interface AgentLongTermMemory {
304
- get<K extends keyof AgentMemoryContext>(key: K): Promise<AgentMemoryContext[K]>;
305
- append<K extends keyof AgentMemoryContext>(key: K, item: AgentMemoryContext[K][0]): Promise<void>;
306
- set<K extends keyof AgentMemoryContext>(key: K, items: AgentMemoryContext[K]): Promise<void>;
310
+ interface AgentLongTermMemory<TAgent extends AnyAgent> {
311
+ get<K extends keyof AgentMemoryContext<TAgent>>(key: K): Promise<AgentMemoryContext<TAgent>[K]>;
312
+ append<K extends keyof AgentMemoryContext<TAgent>>(key: K, item: AgentMemoryContext<TAgent>[K][0]): Promise<void>;
313
+ set<K extends keyof AgentMemoryContext<TAgent>>(key: K, items: AgentMemoryContext<TAgent>[K]): Promise<void>;
307
314
  }
308
315
  type Compute<A extends any> = {
309
316
  [K in keyof A]: A[K];
310
317
  } & unknown;
318
+ type MaybePromise<T> = T | Promise<T>;
319
+ type EventFromAgent<T extends AnyAgent> = T extends Agent<infer _, infer __, infer TEvents, infer ___> ? TEvents : never;
320
+ type TypesFromAgent<T extends AnyAgent> = T extends Agent<infer TContextSchema, infer TEventSchema> ? {
321
+ context: ContextFromZodContextMapping<TContextSchema>;
322
+ events: EventsFromZodEventMapping<TEventSchema>;
323
+ } : never;
324
+ type ContextFromAgent<T extends AnyAgent> = T extends Agent<infer TContextSchema, infer _TEventSchema> ? ContextFromZodContextMapping<TContextSchema> : never;
311
325
 
312
- declare function createAgent<const TContextSchema extends ZodContextMapping, const TEventSchemas extends ZodEventMapping, TEvents extends EventObject = EventsFromZodEventMapping<TEventSchemas>, TContext = ContextFromZodContextMapping<TContextSchema>>({ id, description: description, model, events, context, planner, logic, }: {
326
+ declare function createAgent<const TContextSchema extends ZodContextMapping, const TEventSchemas extends ZodEventMapping, TEvents extends EventObject = EventsFromZodEventMapping<TEventSchemas>, TContext = ContextFromZodContextMapping<TContextSchema>, TAgent extends AnyAgent = Agent<TContextSchema, TEventSchemas>>({ id, description: description, model, events, context, episodeId, strategy, logic, }: {
313
327
  /**
314
328
  * The unique identifier for the agent.
315
329
  *
@@ -335,19 +349,20 @@ declare function createAgent<const TContextSchema extends ZodContextMapping, con
335
349
  */
336
350
  events: TEventSchemas;
337
351
  context?: TContextSchema;
338
- planner?: AgentPlanner<Agent<TContextSchema, TEventSchemas>>;
352
+ strategy?: AgentStrategy<Agent<TContextSchema, TEventSchemas>>;
339
353
  stringify?: typeof JSON.stringify;
340
354
  /**
341
355
  * A function that retrieves the agent's long term memory
342
356
  */
343
- getMemory?: (agent: Agent<TContextSchema, TEventSchemas>) => AgentLongTermMemory;
357
+ getMemory?: (agent: Agent<TContextSchema, TEventSchemas>) => AgentLongTermMemory<TAgent>;
344
358
  /**
345
359
  * Agent logic
346
360
  */
347
- logic?: AgentLogic<TEvents>;
361
+ logic?: AgentLogic<TAgent>;
348
362
  model: LanguageModel;
349
- } & GenerateTextOptions): Agent<TContextSchema, TEventSchemas>;
350
- declare class Agent<const TContextSchema extends ZodContextMapping, const TEventSchemas extends ZodEventMapping, TEvents extends EventObject = EventsFromZodEventMapping<TEventSchemas>, TContext = ContextFromZodContextMapping<TContextSchema>> extends Actor<AgentLogic<TEvents>> {
363
+ episodeId?: string;
364
+ }): Agent<TContextSchema, TEventSchemas>;
365
+ declare class Agent<const TContextSchema extends ZodContextMapping, const TEventSchemas extends ZodEventMapping, TEvents extends EventObject = EventsFromZodEventMapping<TEventSchemas>, TContext = ContextFromZodContextMapping<TContextSchema>> extends Actor<AgentLogic<any>> {
351
366
  /**
352
367
  * The name of the agent. All agents with the same name are related and
353
368
  * able to share experiences (observations, feedback) with each other.
@@ -360,28 +375,29 @@ declare class Agent<const TContextSchema extends ZodContextMapping, const TEvent
360
375
  description?: string;
361
376
  events: TEventSchemas;
362
377
  context?: TContextSchema;
363
- planner?: AgentPlanner<Agent<TContextSchema, TEventSchemas>>;
364
- types: {
365
- events: TEvents;
366
- context: Compute<TContext>;
367
- };
378
+ strategy: AgentStrategy<Agent<TContextSchema, TEventSchemas>>;
368
379
  model: LanguageModel;
369
- memory: AgentLongTermMemory | undefined;
380
+ memory: AgentLongTermMemory<this> | undefined;
370
381
  defaultOptions: AgentDecideOptions<AnyAgent> | undefined;
371
- constructor({ logic, id, name, description, model, events, context, planner, }: {
372
- logic: AgentLogic<TEvents>;
382
+ constructor({ logic, id, name, description, model, events, context, episodeId, strategy, }: {
383
+ logic: AgentLogic<any>;
373
384
  id?: string;
374
385
  name?: string;
375
386
  description?: string;
376
387
  model: GenerateTextOptions['model'];
377
388
  events: TEventSchemas;
378
389
  context?: TContextSchema;
379
- planner?: AgentPlanner<Agent<TContextSchema, TEventSchemas>>;
390
+ strategy?: AgentStrategy<Agent<TContextSchema, TEventSchemas>>;
391
+ episodeId?: string;
380
392
  });
381
393
  /**
382
394
  * Called whenever the agent (LLM assistant) receives or sends a message.
383
395
  */
384
396
  onMessage(fn: (message: AgentMessage) => void): Subscription;
397
+ /**
398
+ * Called whenever the agent (LLM assistant) receives some feedback.
399
+ */
400
+ onFeedback(fn: (feedback: AgentFeedback) => void): Subscription;
385
401
  /**
386
402
  * Retrieves messages from the agent's short-term (local) memory.
387
403
  */
@@ -424,29 +440,29 @@ declare class Agent<const TContextSchema extends ZodContextMapping, const TEvent
424
440
  };
425
441
  getMessages(): AgentMessage[];
426
442
  addFeedback(feedbackInput: AgentFeedbackInput): {
443
+ comment: string | undefined;
427
444
  attributes: {
428
445
  [x: string]: any;
429
446
  };
430
- reward: number;
431
447
  timestamp: number;
432
448
  episodeId: string;
433
- goal?: string;
434
- observationId?: string;
449
+ observationId: string;
450
+ score: number;
435
451
  };
436
452
  /**
437
453
  * Retrieves feedback from the agent's short-term (local) memory.
438
454
  */
439
455
  getFeedback(): AgentFeedback[];
440
- addObservation(observationInput: AgentObservationInput): AgentObservation<any>;
456
+ addObservation(observationInput: AgentObservationInput<this>): AgentObservation<any>;
441
457
  /**
442
458
  * Retrieves observations from the agent's short-term (local) memory.
443
459
  */
444
460
  getObservations(): AgentObservation<any>[];
445
- addPlan(plan: AgentPlan<TEvents>): void;
461
+ addDecision(decision: AgentDecision<this>): void;
446
462
  /**
447
463
  * Retrieves strategies from the agent's short-term (local) memory.
448
464
  */
449
- getPlans(): AgentPlan<any>[];
465
+ getDecisions(): AgentDecision<any>[];
450
466
  /**
451
467
  * Interacts with this state machine actor by inspecting state transitions and storing them as observations.
452
468
  *
@@ -491,29 +507,29 @@ declare class Agent<const TContextSchema extends ZodContextMapping, const TEvent
491
507
  * actor.start();
492
508
  * ```
493
509
  */
494
- interact<TActor extends ActorRefLike>(actorRef: TActor, getInput: (observation: AgentObservation<TActor>) => AgentDecisionInput | undefined): Subscription;
510
+ interact<TActor extends ActorRefLike>(actorRef: TActor, getInput: (observation: AgentObservation<TActor>) => AgentInteractInput<this> | void): Subscription;
495
511
  observe<TActor extends ActorRefLike>(actorRef: TActor): Subscription;
496
512
  wrap(modelToWrap: LanguageModelV1): LanguageModelV1;
497
513
  /**
498
- * Resolves with an `AgentPlan` based on the information provided in the `options`, including:
514
+ * Resolves with an `AgentDecision` based on the information provided in the `options`, including:
499
515
  *
500
516
  * - The `goal` for the agent to achieve
501
517
  * - The observed current `state`
502
518
  * - The `machine` (e.g. a state machine) that specifies what can happen next
503
519
  * - Additional `context`
504
520
  */
505
- decide(opts: AgentDecideOptions<this>): Promise<AgentPlan<EventsFromZodEventMapping<this["events"]>> | undefined>;
521
+ decide(opts: AgentDecideOptions<this>): Promise<AgentDecision<this> | undefined>;
506
522
  }
507
523
 
508
- declare function fromTextStream<T extends AnyAgent>(agent: T, options?: AgentStreamTextOptions): ObservableActorLogic<{
524
+ declare function fromTextStream<TAgent extends AnyAgent>(agent: TAgent, options?: AgentStreamTextOptions<TAgent>): ObservableActorLogic<{
509
525
  textDelta: string;
510
- }, Omit<AgentStreamTextOptions, 'context'> & {
511
- context?: AgentStreamTextOptions['context'];
526
+ }, Omit<AgentStreamTextOptions<TAgent>, 'context'> & {
527
+ context?: Record<string, any>;
512
528
  }>;
513
- declare function fromText<T extends AnyAgent>(agent: T, options?: AgentGenerateTextOptions): PromiseActorLogic<GenerateTextResult<Record<string, CoreTool<any, any>>>, Omit<AgentGenerateTextOptions, 'context'> & {
514
- context?: AgentGenerateTextOptions['context'];
529
+ declare function fromText<TAgent extends AnyAgent>(agent: TAgent, options?: AgentGenerateTextOptions<TAgent>): PromiseActorLogic<GenerateTextResult<Record<string, CoreTool<any, any>>>, Omit<AgentGenerateTextOptions<TAgent>, 'context'> & {
530
+ context?: Record<string, any>;
515
531
  }>;
516
532
 
517
- declare function fromDecision(agent: AnyAgent, defaultInput?: AgentDecisionInput): AgentDecisionLogic<any>;
533
+ declare function fromDecision<T extends AnyAgent>(agent: T, defaultInput?: AgentDecideInput<EventFromAgent<T>>): AgentDecisionLogic<any>;
518
534
 
519
- export { type AgentDecideOptions, type AgentDecisionInput, type AgentDecisionLogic, type AgentEmitted, type AgentFeedback, type AgentFeedbackInput, type AgentGenerateTextOptions, type AgentLogic, type AgentLongTermMemory, type AgentMemoryContext, type AgentMessage, type AgentMessageInput, type AgentObservation, type AgentObservationInput, type AgentPath, type AgentPlan, type AgentPlanInput, type AgentPlanner, type AgentStep, type AgentStreamTextOptions, type AnyAgent, type CommonTextOptions, type Compute, type ContextFromZodContextMapping, type CostFunction, type EventsFromZodEventMapping, type FromAgent, type GenerateTextOptions, type LanguageModelV1TextPart, type LanguageModelV1ToolCallPart, type ObservedState, type ObservedStateFrom, type PromptTemplate, type StreamTextOptions, type TransitionData, createAgent, fromDecision, fromText, fromTextStream };
535
+ export { type AgentDecideInput, type AgentDecideOptions, type AgentDecision, type AgentDecisionInput, type AgentDecisionLogic, type AgentEmitted, type AgentFeedback, type AgentFeedbackInput, type AgentGenerateTextOptions, type AgentInteractInput, type AgentLogic, type AgentLongTermMemory, type AgentMemoryContext, type AgentMessage, type AgentMessageInput, type AgentObservation, type AgentObservationInput, type AgentPath, type AgentStep, type AgentStrategy, type AgentStreamTextOptions, type AnyAgent, type CommonTextOptions, type Compute, type ContextFromAgent, type ContextFromZodContextMapping, type CostFunction, type EventFromAgent, type EventsFromZodEventMapping, type FromAgent, type GenerateTextOptions, type LanguageModelV1TextPart, type LanguageModelV1ToolCallPart, type MaybePromise, type ObservedState, type ObservedStateFrom, type PromptTemplate, type StreamTextOptions, type TransitionData, type TypesFromAgent, createAgent, fromDecision, fromText, fromTextStream };