Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified agent_chat/chat_put.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion agent_chat/eventWorkflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async function eventWorkflow(input: EventInput) {
await client.sendWorkflowEvent({
event: {
name: "message",
input: { content: "Telle ma another one" },
input: { content: "Tell me a joke" },
},
workflow: {
workflowId: input.workflowId,
Expand Down
2 changes: 1 addition & 1 deletion agent_chat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"event-workflow": "tsx eventWorkflow.ts"
},
"dependencies": {
"@restackio/ai": "^0.0.97",
"@restackio/ai": "^0.0.99",
"@temporalio/workflow": "1.11.3",
"openai": "^4.80.1"
},
Expand Down
10 changes: 5 additions & 5 deletions agent_chat/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 3 additions & 15 deletions agent_chat/src/workflows/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,14 @@ export type EndEvent = {
end: boolean;
};

export const messageEvent = defineEvent<functions.Message>("message");

export const messageEvent = defineEvent<functions.Message[]>("message");
export const endEvent = defineEvent("end");

type AgentChatInput = {
message: string;
};

type AgentChatOutput = {
messages: functions.Message[];
};

export async function agentChat({
message = "Hello, can you tell me a joke?",
}: AgentChatInput): Promise<AgentChatOutput> {
export async function agentChat(): Promise<AgentChatOutput> {
let endReceived = false;
let messages: functions.Message[] = [];

Expand All @@ -30,18 +23,13 @@ export async function agentChat({
messages,
});
messages.push(result);
return result;
return messages;
});

onEvent(endEvent, async () => {
endReceived = true;
});

const result = await step<typeof functions>({}).llmChat({
messages: [{ role: "user", content: message }],
});
messages.push(result);

// We use the `condition` function to wait for the event goodbyeReceived to return `True`.
await condition(() => endReceived);

Expand Down