Skip to content

Commit

Permalink
addHistory -> addMessage + changeset
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkpiano committed Jun 12, 2024
1 parent 2a22df4 commit 537f501
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 12 deletions.
17 changes: 17 additions & 0 deletions .changeset/cuddly-pillows-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
'@statelyai/agent': minor
---

First minor release of `@statelyai/agent`! The API has been simplified from experimental earlier versions. Here are the main methods:

- `createAgent({ … })` creates an agent
- `agent.decide({ … })` decides on a plan to achieve the goal
- `agent.generateText({ … })` generates text based on a prompt
- `agent.streamText({ … })` streams text based on a prompt
- `agent.addObservation(observation)` adds an observation and returns a full observation object
- `agent.addFeedback(feedback)` adds a feedback and returns a full feedback object
- `agent.addMessage(message)` adds a message and returns a full message object
- `agent.addPlan(plan)` adds a plan and returns a full plan object
- `agent.onMessage(cb)` listens to messages
- `agent.select(selector)` selects data from the agent context
- `agent.interact(actorRef, getInput)` interacts with an actor and makes decisions to accomplish a goal
8 changes: 4 additions & 4 deletions src/agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ test('an agent has the expected interface', () => {
expect(agent.streamText).toBeDefined();

expect(agent.addFeedback).toBeDefined();
expect(agent.addHistory).toBeDefined();
expect(agent.addMessage).toBeDefined();
expect(agent.addObservation).toBeDefined();
expect(agent.addPlan).toBeDefined();

expect(agent.interact).toBeDefined();
});

test('agent.addHistory() adds to history', () => {
test('agent.addMessage() adds to message history', () => {
const agent = createAgent({
name: 'test',
events: {},
model: {} as any,
});

agent.addHistory({
agent.addMessage({
content: 'msg 1',
role: 'user',
});

const messageHistory = agent.addHistory({
const messageHistory = agent.addMessage({
content: 'response 1',
role: 'assistant',
});
Expand Down
2 changes: 1 addition & 1 deletion src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export function createAgent<
return agentDecide(agent, opts);
};

agent.addHistory = (messageInput) => {
agent.addMessage = (messageInput) => {
const message = {
...messageInput,
id: messageInput.id ?? randomUUID(),
Expand Down
4 changes: 2 additions & 2 deletions src/strategies/chain-of-note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export const chainOfNote = setup({
// return summary.extract;
// })
// );
// x.agent?.addHistory({
// x.agent?.addMessage({
// content: x.prompt!,
// id: Date.now() + '',
// role: 'user',
Expand All @@ -142,7 +142,7 @@ export const chainOfNote = setup({
// prompt: `${x.prompt!}`,
// });

// x.agent?.addHistory({
// x.agent?.addMessage({
// content: result.text,
// id: Date.now() + '',
// role: 'user',
Expand Down
8 changes: 4 additions & 4 deletions src/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export async function agentGenerateText<T extends Agent<any>>(

const messages = await getMessages(agent, promptWithContext, resolvedOptions);

agent.addHistory({
agent.addMessage({
id,
role: 'user',
content: promptWithContext,
Expand All @@ -88,7 +88,7 @@ export async function agentGenerateText<T extends Agent<any>>(
messages,
});

agent.addHistory({
agent.addMessage({
content: result.toolResults ?? result.text,
id,
role: 'assistant',
Expand Down Expand Up @@ -123,7 +123,7 @@ export async function agentStreamText(

const messages = await getMessages(agent, promptWithContext, resolvedOptions);

agent.addHistory({
agent.addMessage({
role: 'user',
content: promptWithContext,
id,
Expand All @@ -135,7 +135,7 @@ export async function agentStreamText(
prompt: undefined,
messages,
onFinish: async (res) => {
agent.addHistory({
agent.addMessage({
role: 'assistant',
result: {
text: res.text,
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export type Agent<TEvents extends EventObject> = ActorRefFrom<
) => Promise<StreamTextResult<Record<string, CoreTool<any, any>>>>;

addObservation: (observation: AgentObservationInput) => AgentObservation<any>; // TODO
addHistory: (history: AgentMessageHistoryInput) => AgentMessageHistory;
addMessage: (history: AgentMessageHistoryInput) => AgentMessageHistory;
addFeedback: (feedbackItem: AgentFeedbackInput) => AgentFeedback;
addPlan: (plan: AgentPlan<TEvents>) => void;
/**
Expand Down

0 comments on commit 537f501

Please sign in to comment.