Spaces:
Paused
Paused
frdel commited on
Commit Β·
8e6b633
1
Parent(s): 2048a39
initial message polishing
Browse files
agent.py
CHANGED
|
@@ -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 |
-
|
| 194 |
msg_template = (
|
| 195 |
agent.hist_add_user_message(msg) # type: ignore
|
| 196 |
if user
|
|
@@ -302,6 +297,10 @@ class Agent:
|
|
| 302 |
self.data = {} # free data object all the tools can use
|
| 303 |
|
| 304 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
|
| 306 |
async def monologue(self):
|
| 307 |
while True:
|
|
|
|
| 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 |
msg_template = (
|
| 190 |
agent.hist_add_user_message(msg) # type: ignore
|
| 191 |
if user
|
|
|
|
| 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
CHANGED
|
@@ -8,7 +8,7 @@
|
|
| 8 |
"headline": "Greeting user and starting conversation",
|
| 9 |
"tool_name": "response",
|
| 10 |
"tool_args": {
|
| 11 |
-
"text": "Hello! π
|
| 12 |
}
|
| 13 |
}
|
| 14 |
```
|
|
|
|
| 8 |
"headline": "Greeting user and starting conversation",
|
| 9 |
"tool_name": "response",
|
| 10 |
"tool_args": {
|
| 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
CHANGED
|
@@ -15,10 +15,14 @@ class InitialMessage(Extension):
|
|
| 15 |
if self.agent.number != 0:
|
| 16 |
return
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
# Construct the initial message from prompt template
|
| 19 |
initial_message = self.agent.read_prompt("fw.initial_message.md")
|
| 20 |
|
| 21 |
-
# add loop data to agent
|
| 22 |
self.agent.loop_data = LoopData(user_message=None)
|
| 23 |
|
| 24 |
# Add the message to history as an AI response
|
|
@@ -32,5 +36,7 @@ class InitialMessage(Extension):
|
|
| 32 |
self.agent.context.log.log(
|
| 33 |
type="response",
|
| 34 |
heading=f"{self.agent.agent_name}: Welcome",
|
| 35 |
-
content=initial_message_text
|
| 36 |
-
|
|
|
|
|
|
|
|
|
| 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 |
|
| 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
|
|
|
|
| 36 |
self.agent.context.log.log(
|
| 37 |
type="response",
|
| 38 |
heading=f"{self.agent.agent_name}: Welcome",
|
| 39 |
+
content=initial_message_text,
|
| 40 |
+
finished=True,
|
| 41 |
+
update_progress="none",
|
| 42 |
+
)
|
webui/js/messages.js
CHANGED
|
@@ -54,6 +54,10 @@ export function setMessage(id, type, heading, content, temp, kvps = null) {
|
|
| 54 |
|
| 55 |
const groupType = groupTypeMap[type] || "left";
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
if (
|
| 58 |
!messageGroup || // no group yet exists
|
| 59 |
groupStart[type] || // message type forces new group
|
|
|
|
| 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
|