Skip to content

Agent Zero AI framework

Route nudge as system message and minify message templates

linkliti0a738850a239
diff --git a/agent.py b/agent.py
index 906ceb740..04dcda128 100644
--- a/agent.py
+++ b/agent.py
@@ -250,7 +250,9 @@ class AgentContext:
def nudge(self):
self.kill_process()
self.paused = False
- self.task = self.communicate(UserMessage(self.agent0.read_prompt("fw.msg_nudge.md")))
+ self.task = self.communicate(
+ UserMessage("", system_message=[self.agent0.read_prompt("fw.msg_nudge.md")])
+ )
return self.task
@extension.extensible
diff --git a/prompts/fw.intervention.md b/prompts/fw.intervention.md
index 793dbd3cc..115ce3f2a 100644
--- a/prompts/fw.intervention.md
+++ b/prompts/fw.intervention.md
@@ -1,7 +1,7 @@
```json
{
- "system_message": {{system_message}},
- "user_intervention": {{message}},
- "attachments": {{attachments}}
+ "system_message":{{system_message}},
+ "user_intervention":{{message}},
+ "attachments":{{attachments}}
}
-```
+```
\ No newline at end of file
diff --git a/prompts/fw.msg_nudge.md b/prompts/fw.msg_nudge.md
index f9b1986dd..107fc07fd 100644
--- a/prompts/fw.msg_nudge.md
+++ b/prompts/fw.msg_nudge.md
@@ -1,5 +1 @@
-```json
-{
- "system_message": "Nudged - continue",
-}
-```
\ No newline at end of file
+Nudged - continue
\ No newline at end of file
diff --git a/prompts/fw.user_message.md b/prompts/fw.user_message.md
index 096f71a3f..078eb5749 100644
--- a/prompts/fw.user_message.md
+++ b/prompts/fw.user_message.md
@@ -1,7 +1,7 @@
```json
{
- "system_message": {{system_message}},
- "user_message": {{message}},
- "attachments": {{attachments}}
+ "system_message":{{system_message}},
+ "user_message":{{message}},
+ "attachments":{{attachments}}
}
-```
+```
\ No newline at end of file
diff --git a/tests/test_intervention_llm_abort.py b/tests/test_intervention_llm_abort.py
new file mode 100644
index 000000000..d7ccf3de0
--- /dev/null
+++ b/tests/test_intervention_llm_abort.py
@@ -0,0 +1,58 @@
+from types import SimpleNamespace
+
+from agent import AgentContext, UserMessage
+
+
+def test_nudge_stops_running_context_and_starts_nudge_message():
+ context = AgentContext.__new__(AgentContext)
+ calls = []
+
+ class _Task:
+ def is_alive(self):
+ return False
+
+ def kill(self):
+ calls.append("kill")
+
+ context.task = _Task()
+ context.paused = True
+ context.streaming_agent = None
+ context.agent0 = SimpleNamespace(
+ intervention=None,
+ data={},
+ read_prompt=lambda _name: "nudge text",
+ )
+
+ started = {}
+
+ def fake_run_task(func, *args):
+ started["func"] = func
+ started["args"] = args
+ return "new-task"
+
+ context.run_task = fake_run_task
+
+ result = context.nudge()
+
+ assert calls == ["kill"]
+ assert result == "new-task"
+ assert started["args"][0] is context.agent0
+ assert started["args"][1].system_message == ["nudge text"]
+ assert started["args"][1].message == ""
+
+
+def test_user_message_during_run_sets_intervention():
+ context = AgentContext.__new__(AgentContext)
+
+ current = SimpleNamespace(intervention=None, data={})
+
+ context.task = SimpleNamespace(is_alive=lambda: True)
+ context.paused = True
+ context.streaming_agent = current
+ context.agent0 = current
+
+ message = UserMessage("intervene")
+ context.communicate(message)
+
+ assert current.intervention is message
+ assert context.paused is False