(fix) actions.ts: restored handleAssistantMessage handling order (#4074)

This commit is contained in:
tobitege 2024-09-26 21:56:12 +02:00 committed by GitHub
parent c919086e25
commit 29c34e0b6a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 29 additions and 16 deletions

View File

@ -94,13 +94,13 @@ function AgentStatusBar() {
const [statusMessage, setStatusMessage] = React.useState<string>("");
React.useEffect(() => {
const trimmedCustomMessage = curStatusMessage.message.trim();
const trimmedCustomMessage = curStatusMessage.status.trim();
if (trimmedCustomMessage) {
setStatusMessage(t(trimmedCustomMessage));
} else {
setStatusMessage(AgentStatusMap[curAgentState].message);
}
}, [curAgentState, curStatusMessage.message]);
}, [curAgentState, curStatusMessage.status]);
return (
<div className="flex flex-col items-center">

View File

@ -140,11 +140,11 @@ export function handleActionMessage(message: ActionMessage) {
}
export function handleStatusMessage(message: StatusMessage) {
const msg = message.message == null ? "" : message.message.trim();
const msg = message.status == null ? "" : message.status.trim();
store.dispatch(
setCurStatusMessage({
...message,
message: msg,
status: msg,
}),
);
}
@ -160,9 +160,9 @@ export function handleAssistantMessage(data: string | SocketMessage) {
if ("action" in socketMessage) {
handleActionMessage(socketMessage);
} else if ("observation" in socketMessage) {
handleObservationMessage(socketMessage);
} else if ("message" in socketMessage) {
} else if ("status" in socketMessage) {
handleStatusMessage(socketMessage);
} else {
handleObservationMessage(socketMessage);
}
}

View File

@ -2,7 +2,7 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { StatusMessage } from "#/types/Message";
const initialStatusMessage: StatusMessage = {
message: "",
status: "",
is_error: false,
};

View File

@ -38,5 +38,5 @@ export interface StatusMessage {
is_error: boolean;
// A status message to display to the user
message: string;
status: string;
}

View File

@ -1,5 +1,4 @@
import asyncio
from threading import Thread
from typing import Callable, Optional
@ -76,10 +75,20 @@ class AgentSession:
self.thread = Thread(target=self._run, daemon=True)
self.thread.start()
coro = self._start(runtime_name, config, agent, max_iterations, max_budget_per_task, agent_to_llm_config, agent_configs, status_message_callback)
asyncio.run_coroutine_threadsafe(coro, self.loop) # type: ignore
coro = self._start(
runtime_name,
config,
agent,
max_iterations,
max_budget_per_task,
agent_to_llm_config,
agent_configs,
status_message_callback,
)
asyncio.run_coroutine_threadsafe(coro, self.loop) # type: ignore
async def _start(self,
async def _start(
self,
runtime_name: str,
config: AppConfig,
agent: Agent,
@ -103,8 +112,8 @@ class AgentSession:
ChangeAgentStateAction(AgentState.INIT), EventSource.USER
)
if self.controller:
self.controller.agent_task = self.controller.start_step_loop()
await self.controller.agent_task # type: ignore
self.controller.agent_task = self.controller.start_step_loop()
await self.controller.agent_task # type: ignore
def _run(self):
asyncio.set_event_loop(self.loop)

View File

@ -187,6 +187,10 @@ class Session:
"""Sends a message to the client."""
return await self.send({'message': message})
async def send_status_message(self, message: str) -> bool:
"""Sends a status message to the client."""
return await self.send({'status': message})
def update_connection(self, ws: WebSocket):
self.websocket = ws
self.is_alive = True
@ -202,4 +206,4 @@ class Session:
def queue_status_message(self, message: str):
"""Queues a status message to be sent asynchronously."""
# Ensure the coroutine runs in the main event loop
asyncio.run_coroutine_threadsafe(self.send_message(message), self.loop)
asyncio.run_coroutine_threadsafe(self.send_status_message(message), self.loop)