1
1
import getpass
2
+ import json
2
3
import os
3
4
import platform
4
5
from typing import List
18
19
from langchain_experimental .plan_and_execute .executors .base import ChainExecutor
19
20
from .tools import get_tools
20
21
from .utils import fancier_trim_intermediate_steps
22
+ from .utils import SupabaseDB
21
23
import ai_ta_backend .agents .customcallbacks as customcallbacks
22
24
23
25
HUMAN_MESSAGE_TEMPLATE = """Previous steps: {previous_steps}
30
32
31
33
"""
32
34
35
+ MEMORY_CONTEXT = """
36
+ Memory:
37
+ Tools used in chronological order(1 is oldest) : {tools_used}
38
+ Actions taken in chronological order(1 is oldest) : {agent_action_steps}
39
+ """
40
+
33
41
34
42
35
43
def get_user_info_string ():
@@ -41,6 +49,27 @@ def get_user_info_string():
41
49
return f"[User Info]\n Name: { username } \n CWD: { current_working_directory } \n SHELL: { default_shell } \n OS: { operating_system } "
42
50
43
51
52
+ def get_memory_context (table_name : str , image_name : str ):
53
+ db = SupabaseDB (table_name = table_name , image_name = image_name )
54
+ tools_used , action_data_string = "" , ""
55
+
56
+ if db .is_exists_image ():
57
+ tool_data = db .fetch_field_from_db ("on_tool_start" )
58
+ if tool_data :
59
+ tools_used = [item ['name' ] for item in tool_data ]
60
+ tools_used = ", " .join (tools_used )
61
+
62
+ action_data = db .fetch_field_from_db ("on_agent_action" )
63
+ if action_data :
64
+ action_data_string = [item ['log' ] for item in action_data ]
65
+ action_data_string = ", " .join (action_data_string )
66
+
67
+ return MEMORY_CONTEXT .format (
68
+ tools_used = tools_used ,
69
+ agent_action_steps = action_data_string ,
70
+ )
71
+
72
+
44
73
class WorkflowAgent :
45
74
def __init__ (self , run_id_in_metadata , image_name ):
46
75
self .run_id_in_metadata = run_id_in_metadata
@@ -85,8 +114,11 @@ def custom_load_agent_executor(self,
85
114
Returns:
86
115
ChainExecutor
87
116
"""
117
+ memory_context = get_memory_context (table_name = "docker_images" , image_name = self .image_name )
118
+ print ("Memory Context: " , memory_context )
119
+
88
120
input_variables = ["previous_steps" , "current_step" , "agent_scratchpad" ]
89
- template = HUMAN_MESSAGE_TEMPLATE
121
+ template = HUMAN_MESSAGE_TEMPLATE + memory_context
90
122
91
123
if include_task_in_prompt :
92
124
input_variables .append ("objective" )
0 commit comments