initial message polishing
frdel committed
Jul 21, 2025 at 23:08 UTC
0aa6201d3dca2e66c5f68523b5fb28791a8bd5a2
4 files changed
+18
-9
agent.py
+4
-5
@@ -186,11 +186,6 @@ class AgentContext:
186
# this wrapper ensures that superior agents are called back if the chat was loaded from file and original callstack is gone
187
async def _process_chain(self, agent: "Agent", msg: "UserMessage|str", user=True):
188
try:
189
- # Initialize agent with welcome message only once per session (before first user message)
190
- if user and not agent.get_data("_session_initialized"):
191
- await agent.call_extensions("agent_init")
192
- agent.set_data("_session_initialized", True)
193
-
189
msg_template = (
190
agent.hist_add_user_message(msg) # type: ignore
191
if user
@@ -302,6 +297,10 @@ class Agent:
297
self.data = {} # free data object all the tools can use
298
299
300
+ asyncio.run(self.call_extensions("agent_init"))
301
+
302
+
303
+
304
305
async def monologue(self):
306
while True:
prompts/default/fw.initial_message.md
+1
-1
@@ -8,7 +8,7 @@
8
"headline": "Greeting user and starting conversation",
9
"tool_name": "response",
10
"tool_args": {
11
- "text": "Hello! 👋 Welcome to our conversation. I'm Agent Zero, your AI assistant, and I'm here to help you with any questions, tasks, or problems you might have.\n\nI can assist you with:\n- 💻 Programming and coding tasks\n- 📊 Data analysis and research \n- 🛠️ System administration and troubleshooting\n- 📝 Writing and documentation\n- 🔍 Web searches and information gathering\n- And much more!\n\nJust let me know what you'd like to work on, and I'll do my best to help you! 😊"
11
+ "text": "**Hello! 👋**, I'm **Agent Zero**, your AI assistant. How can I help you today?"
12
}
13
}
14
```
python/extensions/agent_init/_10_initial_message.py
+9
-3
@@ -15,10 +15,14 @@ class InitialMessage(Extension):
15
if self.agent.number != 0:
16
return
17
18
+ # If the context already contains log messages, do not add another initial message
19
+ if self.agent.context.log.logs:
20
+ return
21
+
22
# Construct the initial message from prompt template
23
initial_message = self.agent.read_prompt("fw.initial_message.md")
24
21
- # add loop data to agent
25
+ # add initial loop data to agent (for hist_add_ai_response)
26
self.agent.loop_data = LoopData(user_message=None)
27
28
# Add the message to history as an AI response
@@ -32,5 +36,7 @@ class InitialMessage(Extension):
36
self.agent.context.log.log(
37
type="response",
38
heading=f"{self.agent.agent_name}: Welcome",
35
- content=initial_message_text
36
- ).update(finished=True)
39
+ content=initial_message_text,
40
+ finished=True,
41
+ update_progress="none",
42
+ )
webui/js/messages.js
+4
@@ -54,6 +54,10 @@ export function setMessage(id, type, heading, content, temp, kvps = null) {
54
55
const groupType = groupTypeMap[type] || "left";
56
57
+ // here check if messageGroup is still in DOM, if not, then set it to null (context switch)
58
+ if(messageGroup && !document.getElementById(messageGroup.id))
59
+ messageGroup = null;
60
+
61
if (
62
!messageGroup || // no group yet exists
63
groupStart[type] || // message type forces new group