Skip to content

Commit 382e826

Browse files
committed
Send step_error on errors
1 parent 36f92f0 commit 382e826

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

llmstack/client/src/components/apps/AgentRenderer.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,11 @@ export function AgentRenderer({ app, isMobile, embed = false, ws }) {
338338
...existingMessages,
339339
{
340340
role: "bot",
341-
content: response,
342-
error: false,
341+
content:
342+
message.output.agent.type === "step_error"
343+
? message.output.agent.content
344+
: response,
345+
error: message.output.agent.type === "step_error",
343346
type: message.output.agent.type || "output",
344347
id: message.output.agent.id,
345348
from_id: message.output.agent.from_id,

llmstack/play/actors/agent.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,33 @@ def on_receive(self, message: Message) -> Any:
212212
except Exception as e:
213213
logger.error(f'Error getting tool output: {e}')
214214

215+
if message.message_type == MessageType.STREAM_ERROR:
216+
# Log the error and quit for now
217+
async_to_sync(self._output_stream.write)(
218+
AgentOutput(
219+
content=message.message,
220+
from_id=message.message_from,
221+
id=message.message_id or str(uuid.uuid4()),
222+
type='step_error',
223+
)
224+
)
225+
output_response = OutputResponse(
226+
response_content_type='text/markdown',
227+
response_status=400,
228+
response_body=message.message,
229+
response_headers={},
230+
)
231+
bookkeeping_data = BookKeepingData(
232+
run_data={**output_response._asdict()}, input=self._input, config={}, output={'agent_messages': self._agent_messages}, timestamp=time.time(),
233+
)
234+
self._output_stream.bookkeep(bookkeeping_data)
235+
async_to_sync(self._output_stream.write_raw)(
236+
Message(
237+
message_type=MessageType.AGENT_DONE,
238+
message_from='agent',
239+
)
240+
)
241+
215242
def on_stop(self) -> None:
216243
super().on_stop()
217244

0 commit comments

Comments
 (0)