Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix system message rounds logic and show agent names in whisper #200

Merged
merged 2 commits into from
Aug 1, 2023
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
16 changes: 11 additions & 5 deletions skyagi-web/src/lib/stores/chat-messages.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StoreMessageRole, type StoreMessageType } from '$lib/types';
import { StoreMessageRole, type StoreMessageType, type AgentDataTypeInConversation } from '$lib/types';
import { SSE } from 'sse.js';
import { get, writable } from 'svelte/store';
import modelTokenDataStore from '$lib/room-store.js';
Expand Down Expand Up @@ -211,6 +211,8 @@ const agentsSystemMessagingProcess = async (biDirection = false) => {
// After that we can use conversation message to let A talk to B with the content returned by system message endpoint
// the conversation keeps going until if_continue is false
// .... repeat above for other pairs.
let idToAgentInfoMapDict: { [key: string]: AgentDataTypeInConversation } = get(idToAgentInfoMap);
console.log('idToAgentInfoMapDict', idToAgentInfoMapDict);
console.log("inside of agentsSystemMessagingProcess");
console.log('get(agentIds)', get(agentIds));
const nonUserAgentIds = get(agentIds).filter(id => id !== get(userAgentId));
Expand All @@ -225,25 +227,28 @@ const agentsSystemMessagingProcess = async (biDirection = false) => {
console.log(`${pair[0]} to ${pair[1]} going to send system message`);
const systemMessageResult = await getSendSystemMessageContentResult(get(conversationId), pair[0], pair[1]);
if (!systemMessageResult.success) {
handleError(`${pair[0]} ${pair[1]} failed to whisper`);
handleError(`${idToAgentInfoMapDict[pair[0]].name} ${idToAgentInfoMapDict[pair[1]].name} failed to whisper`);
} else if (systemMessageResult.is_valid && systemMessageResult.message) {
console.log("has systemMessageResult");
console.log(`${pair[0]} is whispering to ${pair[1]}`);
handleSystemMessage(`${pair[0]} is whispering to ${pair[1]}`);
handleSystemMessage(`${idToAgentInfoMapDict[pair[0]].name} is whispering to ${idToAgentInfoMapDict[pair[1]].name}`);
const initialConversationMessage = systemMessageResult.message;
console.log('initialConversationMessage', initialConversationMessage);
// Send conversation messages between pair[0] and pair[1], until one of them doesn't want to continue
let shouldContinue = true; // TODO: change to True
let conversationContent = initialConversationMessage;
let arrowDirection = true; // true means pair0 -> pair1, false means pair1 -> pair0
while (shouldContinue) {
const resp = await sendConversationMessage(get(conversationId), pair[0], pair[1], conversationContent);
let resp = await (arrowDirection ? sendConversationMessage(get(conversationId), pair[0], pair[1], conversationContent) : sendConversationMessage(get(conversationId), pair[1], pair[0], conversationContent));
// Parse result
console.log('!!!sendConversationMessage', resp);
shouldContinue = resp.if_continue;
conversationContent = resp.message;
arrowDirection = !arrowDirection;
}
} else { // System tells us that there's nothing to conversate between the two agents.
console.log(`${pair[0]} has nothing to whisper to ${pair[1]}`);
handleSystemMessage(`${pair[0]} has nothing to whisper to ${pair[1]}`);
handleSystemMessage(`${idToAgentInfoMapDict[pair[0]].name} has nothing to whisper to ${idToAgentInfoMapDict[pair[1]].name}`);
}
resolve();
});
Expand Down Expand Up @@ -316,6 +321,7 @@ export const currentAgentId = writable<string>('');
export const conversationId = writable<string>('');
export const userAgentId = writable<string>('');
export const agentIds = writable<string[]>([]);
export const idToAgentInfoMap = writable<{}>({}); // key is agent id, value is agent info including user name, avatar...

// This is sentence level variable, will reset for each conversation response.
export const ifContinue = writable<boolean>(true);
5 changes: 5 additions & 0 deletions skyagi-web/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ export enum StoreMessageRole {
AGENT = "agent",
};

export interface AgentDataTypeInConversation {
name: string;
avatarPath: string;
}

export interface StoreMessageType {
// Both role and name are for the side who delivers this message
role: StoreMessageRole;
Expand Down
14 changes: 12 additions & 2 deletions skyagi-web/src/routes/room/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@
currentAgentName,
conversationId,
userAgentId,
agentIds
agentIds,
idToAgentInfoMap
} from '$lib/stores/chat-messages';
import type { PageData } from './$types';
import {
StoreMessageRole,
type ConversationDataType,
type MessageDataType,
type StoreMessageType,
type AgentDataType
type AgentDataType,
type AgentDataTypeInConversation
} from '$lib/types';
import { onMount } from 'svelte';
import { loadHistoryToLocalStorage, getLocalHistoryKey } from '$lib/stores/chat-history';
Expand Down Expand Up @@ -65,6 +67,14 @@
conversationId.set(conversationData.id);
userAgentId.set(conversationData.userAgents[0].id);
agentIds.set(conversationData.agents.map(agent => agent.id));
let idToAgentInfoMapDict: { [key: string]: AgentDataTypeInConversation } = {};
conversationData.agents.forEach(agent => {
idToAgentInfoMapDict[agent.id] = {
name: agent.name,
avatarPath: agent.avatarPath
};
});
idToAgentInfoMap.set(idToAgentInfoMapDict);
console.log('conversationData', conversationData);
console.log('Start loading conversation history');
if (conversationData.messages && conversationData.messages.length > 0) {
Expand Down
Loading