Skip to content

Commit

Permalink
Cleanup and add skipped emit test
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkpiano committed Jun 22, 2024
1 parent 232fa9b commit 90241b3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
23 changes: 20 additions & 3 deletions src/agent.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test, expect } from 'vitest';
import { test, expect, vi } from 'vitest';
import { createAgent, type AIAdapter } from './';
import { createActor, createMachine } from 'xstate';

Expand Down Expand Up @@ -175,13 +175,30 @@ test('Agents can use a custom adapter', async () => {
expect(res.text).toEqual('Response');
});

test.skip('You can listen for emitted agent events', () => {
test.skip('You can listen for emitted agent events', async () => {
const fn = vi.fn();
const agent = createAgent({
name: 'test',
events: {},
adapter: {} as any,
model: {} as any,
});

agent.on('feedback', (x) => {});
const p = new Promise((res) => {
agent.on('feedback', (f) => {
res(f);
});
});

agent.addFeedback({
attributes: {
score: -1,
},
goal: 'Win the game',
observationId: 'obs-1',
});

await p;

expect(fn).toHaveBeenCalled();
});
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { createAgent } from './agent';
export { fromText, fromTextStream, agentGenerateText } from './text';
export { fromDecision, agentDecide } from './decision';
export { fromText, fromTextStream } from './text';
export { fromDecision } from './decision';
export * from './types';
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export type PromptTemplate<TEvents extends EventObject> = (data: {

export type AgentPlanner<T extends Agent<any>> = (
agent: T['eventTypes'],
options: AgentPlanInput<T['eventTypes']>
input: AgentPlanInput<T['eventTypes']>
) => Promise<AgentPlan<T['eventTypes']> | undefined>;

export type AgentDecideOptions = {
Expand Down Expand Up @@ -271,7 +271,7 @@ export type Agent<TEvents extends EventObject> = ActorRefFrom<
*
* - The `goal` for the agent to achieve
* - The observed current `state`
* - The `logic` (e.g. a state machine) that specifies what can happen next
* - The `machine` (e.g. a state machine) that specifies what can happen next
* - Additional `context`
*/
decide: (
Expand Down

0 comments on commit 90241b3

Please sign in to comment.