Skip to content

Commit d3b4bc6

Browse files
authored
Merge pull request #68 from pattern-tech/feat/heartbeat
feat: Add initial heartbeat event to notify client when processing st…
2 parents fd3acf7 + 18e7c54 commit d3b4bc6

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/agent/services/agent_service.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ async def stream(self, message: str) -> AsyncGenerator[str, None]:
162162
while not self.streaming_handler.queue.empty():
163163
self.streaming_handler.queue.get_nowait()
164164

165+
# Send an initial heartbeat message to inform the client that processing has started
166+
init_heartbeat_event = {
167+
"type": "heartbeat",
168+
"data": "processing_started"
169+
}
170+
yield json.dumps(init_heartbeat_event) + "\n"
171+
165172
# Start the agent task based on memory configuration
166173
if self.memory:
167174
loop = asyncio.get_running_loop()
@@ -213,7 +220,7 @@ async def stream(self, message: str) -> AsyncGenerator[str, None]:
213220
}
214221
yield json.dumps(heartbeat_event) + "\n"
215222
last_activity = current_time # Reset the activity timer
216-
223+
217224
# Wait a bit before checking again
218225
await asyncio.sleep(self.poll_interval)
219226
continue
@@ -263,7 +270,7 @@ async def stream(self, message: str) -> AsyncGenerator[str, None]:
263270
"data": "Stream completed"
264271
}
265272
yield json.dumps(completion_event) + "\n"
266-
273+
267274
# Wait for the task to complete and get the result
268275
await task
269276
except asyncio.CancelledError:

0 commit comments

Comments
 (0)