Skip to content

Commit 13a34d7

Browse files
authored
Feat: inject sys.date into canvas (#13567)
### What problem does this PR solve? Inject sys.date into canvas. ### Type of change - [x] New Feature (non-breaking change which adds functionality)
1 parent eda7835 commit 13a34d7

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

agent/canvas.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#
1616
import asyncio
1717
import base64
18+
import datetime
1819
import inspect
1920
import binascii
2021
import json
@@ -287,7 +288,8 @@ def __init__(self, dsl: str, tenant_id=None, task_id=None, canvas_id=None, custo
287288
"sys.user_id": tenant_id,
288289
"sys.conversation_turns": 0,
289290
"sys.files": [],
290-
"sys.history": []
291+
"sys.history": [],
292+
"sys.date": datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%d %H:%M:%S")
291293
}
292294
self.variables = {}
293295
super().__init__(dsl, tenant_id, task_id, custom_header=custom_header)
@@ -300,13 +302,16 @@ def load(self):
300302
self.globals = self.dsl["globals"]
301303
if "sys.history" not in self.globals:
302304
self.globals["sys.history"] = []
305+
if "sys.date" not in self.globals:
306+
self.globals["sys.date"] = datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%d %H:%M:%S")
303307
else:
304308
self.globals = {
305309
"sys.query": "",
306310
"sys.user_id": "",
307311
"sys.conversation_turns": 0,
308312
"sys.files": [],
309-
"sys.history": []
313+
"sys.history": [],
314+
"sys.date": datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%d %H:%M:%S")
310315
}
311316
if "variables" in self.dsl:
312317
self.variables = self.dsl["variables"]
@@ -368,6 +373,7 @@ def reset(self, mem=False):
368373
self.globals[k] = ""
369374

370375
async def run(self, **kwargs):
376+
self.globals["sys.date"] = datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%d %H:%M:%S")
371377
st = time.perf_counter()
372378
self._loop = asyncio.get_running_loop()
373379
self.message_id = get_uuid()

web/src/constants/agent.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export enum AgentGlobals {
3333
SysConversationTurns = 'sys.conversation_turns',
3434
SysFiles = 'sys.files',
3535
SysHistory = 'sys.history',
36+
SysDate = 'sys.date',
3637
}
3738

3839
export const AgentGlobalsSysQueryWithBrace = `{${AgentGlobals.SysQuery}}`;
@@ -272,5 +273,6 @@ export const EmptyDsl = {
272273
[AgentGlobals.SysConversationTurns]: 0,
273274
[AgentGlobals.SysFiles]: [],
274275
[AgentGlobals.SysHistory]: [],
276+
[AgentGlobals.SysDate]: '',
275277
},
276278
};

0 commit comments

Comments
 (0)