Spaces:
Paused
Paused
ehl0wr0ld Rafael Uzarowski commited on
feat: make agentcontexttype background invisible to user (#653)
Browse filesCo-authored-by: Rafael Uzarowski <uzarowski.rafael@proton.me>
python/api/poll.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
from python.helpers.api import ApiHandler, Request, Response
|
| 2 |
|
| 3 |
-
from agent import AgentContext
|
| 4 |
|
| 5 |
from python.helpers.task_scheduler import TaskScheduler
|
| 6 |
from python.helpers.localization import Localization
|
|
@@ -48,6 +48,11 @@ class Poll(ApiHandler):
|
|
| 48 |
if ctx.id in processed_contexts:
|
| 49 |
continue
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
# Create the base context data that will be returned
|
| 52 |
context_data = ctx.serialize()
|
| 53 |
|
|
|
|
| 1 |
from python.helpers.api import ApiHandler, Request, Response
|
| 2 |
|
| 3 |
+
from agent import AgentContext, AgentContextType
|
| 4 |
|
| 5 |
from python.helpers.task_scheduler import TaskScheduler
|
| 6 |
from python.helpers.localization import Localization
|
|
|
|
| 48 |
if ctx.id in processed_contexts:
|
| 49 |
continue
|
| 50 |
|
| 51 |
+
# Skip BACKGROUND contexts as they should be invisible to users
|
| 52 |
+
if ctx.type == AgentContextType.BACKGROUND:
|
| 53 |
+
processed_contexts.add(ctx.id)
|
| 54 |
+
continue
|
| 55 |
+
|
| 56 |
# Create the base context data that will be returned
|
| 57 |
context_data = ctx.serialize()
|
| 58 |
|
python/extensions/message_loop_end/_90_save_chat.py
CHANGED
|
@@ -1,8 +1,12 @@
|
|
| 1 |
from python.helpers.extension import Extension
|
| 2 |
-
from agent import LoopData
|
| 3 |
from python.helpers import persist_chat
|
| 4 |
|
| 5 |
|
| 6 |
class SaveChat(Extension):
|
| 7 |
async def execute(self, loop_data: LoopData = LoopData(), **kwargs):
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from python.helpers.extension import Extension
|
| 2 |
+
from agent import LoopData, AgentContextType
|
| 3 |
from python.helpers import persist_chat
|
| 4 |
|
| 5 |
|
| 6 |
class SaveChat(Extension):
|
| 7 |
async def execute(self, loop_data: LoopData = LoopData(), **kwargs):
|
| 8 |
+
# Skip saving BACKGROUND contexts as they should be ephemeral
|
| 9 |
+
if self.agent.context.type == AgentContextType.BACKGROUND:
|
| 10 |
+
return
|
| 11 |
+
|
| 12 |
+
persist_chat.save_tmp_chat(self.agent.context)
|
python/helpers/persist_chat.py
CHANGED
|
@@ -29,6 +29,10 @@ def get_chat_folder_path(ctxid: str):
|
|
| 29 |
|
| 30 |
def save_tmp_chat(context: AgentContext):
|
| 31 |
"""Save context to the chats folder"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
path = _get_chat_file_path(context.id)
|
| 33 |
files.make_dirs(path)
|
| 34 |
data = _serialize_context(context)
|
|
@@ -39,6 +43,9 @@ def save_tmp_chat(context: AgentContext):
|
|
| 39 |
def save_tmp_chats():
|
| 40 |
"""Save all contexts to the chats folder"""
|
| 41 |
for _, context in AgentContext._contexts.items():
|
|
|
|
|
|
|
|
|
|
| 42 |
save_tmp_chat(context)
|
| 43 |
|
| 44 |
|
|
@@ -180,7 +187,7 @@ def _deserialize_context(data):
|
|
| 180 |
agents = data.get("agents", [])
|
| 181 |
agent0 = _deserialize_agents(agents, config, context)
|
| 182 |
streaming_agent = agent0
|
| 183 |
-
while streaming_agent.number != data.get("streaming_agent", 0):
|
| 184 |
streaming_agent = streaming_agent.data.get(Agent.DATA_NAME_SUBORDINATE, None)
|
| 185 |
|
| 186 |
context.agent0 = agent0
|
|
|
|
| 29 |
|
| 30 |
def save_tmp_chat(context: AgentContext):
|
| 31 |
"""Save context to the chats folder"""
|
| 32 |
+
# Skip saving BACKGROUND contexts as they should be ephemeral
|
| 33 |
+
if context.type == AgentContextType.BACKGROUND:
|
| 34 |
+
return
|
| 35 |
+
|
| 36 |
path = _get_chat_file_path(context.id)
|
| 37 |
files.make_dirs(path)
|
| 38 |
data = _serialize_context(context)
|
|
|
|
| 43 |
def save_tmp_chats():
|
| 44 |
"""Save all contexts to the chats folder"""
|
| 45 |
for _, context in AgentContext._contexts.items():
|
| 46 |
+
# Skip BACKGROUND contexts as they should be ephemeral
|
| 47 |
+
if context.type == AgentContextType.BACKGROUND:
|
| 48 |
+
continue
|
| 49 |
save_tmp_chat(context)
|
| 50 |
|
| 51 |
|
|
|
|
| 187 |
agents = data.get("agents", [])
|
| 188 |
agent0 = _deserialize_agents(agents, config, context)
|
| 189 |
streaming_agent = agent0
|
| 190 |
+
while streaming_agent and streaming_agent.number != data.get("streaming_agent", 0):
|
| 191 |
streaming_agent = streaming_agent.data.get(Agent.DATA_NAME_SUBORDINATE, None)
|
| 192 |
|
| 193 |
context.agent0 = agent0
|