Skip to content

Agent Zero AI framework

nudge + move queue extension

frdel3d8cc2a6201b
diff --git a/agent.py b/agent.py
index 62b98e954..815d75b75 100644
--- a/agent.py
+++ b/agent.py
@@ -225,7 +225,7 @@ class AgentContext:
def nudge(self):
self.kill_process()
self.paused = False
- self.task = self.run_task(self.get_agent().monologue)
+ self.task = self.communicate(UserMessage(self.agent0.read_prompt("fw.msg_nudge.md")))
return self.task
def get_agent(self):
@@ -277,6 +277,10 @@ class AgentContext:
superior = agent.data.get(Agent.DATA_NAME_SUPERIOR, None)
if superior:
response = await self._process_chain(superior, response, False) # type: ignore
+
+ # call end of process extensions
+ await self.get_agent().call_extensions("process_chain_end", data={})
+
return response
except Exception as e:
agent.handle_critical_exception(e)
diff --git a/prompts/fw.msg_nudge.md b/prompts/fw.msg_nudge.md
new file mode 100644
index 000000000..f9b1986dd
--- /dev/null
+++ b/prompts/fw.msg_nudge.md
@@ -0,0 +1,5 @@
+```json
+{
+ "system_message": "Nudged - continue",
+}
+```
\ No newline at end of file
diff --git a/python/extensions/monologue_end/_95_process_queue.py b/python/extensions/process_chain_end/_50_process_queue.py
similarity index 64%
rename from python/extensions/monologue_end/_95_process_queue.py
rename to python/extensions/process_chain_end/_50_process_queue.py
index 51315ee4b..239419487 100644
--- a/python/extensions/monologue_end/_95_process_queue.py
+++ b/python/extensions/process_chain_end/_50_process_queue.py
@@ -1,7 +1,7 @@
import asyncio
from python.helpers.extension import Extension
from python.helpers import message_queue as mq
-from agent import LoopData
+from agent import AgentContext, Agent, LoopData
class ProcessQueue(Extension):
@@ -20,14 +20,15 @@ class ProcessQueue(Extension):
# This allows current monologue to fully complete first
asyncio.create_task(self._delayed_send(context))
- async def _delayed_send(self, context):
+ async def _delayed_send(self, context: AgentContext):
"""Wait for task to complete, then send next queued message."""
- # Small delay to ensure monologue fully completes
- await asyncio.sleep(0.1)
- # Wait for current task to finish
- while context.task and context.task.is_alive():
+ # Wait for current task to finish, but no more than 1 minute to prevent hanging tasks
+ total_wait = 0
+ while context.is_running() and total_wait < 60:
await asyncio.sleep(0.1)
+ total_wait += 0.1
- # Send next queued message
- mq.send_next(context)
+ # Send next queued message if task is not running
+ if not context.is_running():
+ mq.send_next(context)