MCPcopy Create free account
hub / github.com/HKUDS/AutoAgent / ToolMemory

Class ToolMemory

autoagent/memory/tool_memory.py:12–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10Category | Tool_Name | Tool_Description | API_Name | API_Description | Method | API_Details | Required_API_Key | Platform
11"""
12class ToolMemory(Memory):
13 def __init__(
14 self,
15 project_path: str,
16 db_name: str = '.tool_table',
17 platform: str = 'OpenAI',
18 api_key: str = None,
19 embedding_model: str = "text-embedding-3-small",
20 ):
21 super().__init__(
22 project_path=project_path,
23 db_name=db_name,
24 platform=platform,
25 api_key=api_key,
26 embedding_model=embedding_model
27 )
28 self.collection_name = 'tool_memory'
29
30 def add_dataframe(self, df: pd.DataFrame, collection: str = None, batch_size: int = 100):
31 if not collection:
32 collection = self.collection_name
33 queries = []
34 for idx, row in df.iterrows():
35 query = {
36 'query': ' '.join(row[['Tool_Name', 'Tool_Description', 'API_Name', 'API_Description']].astype(str)),
37 'response': row.to_json()
38 }
39 queries.append(query)
40
41 # self.add_query(queries, collection=collection)
42 print(f'Adding {len(queries)} queries to {collection} with batch size {batch_size}')
43 num_batches = math.ceil(len(queries) / batch_size)
44
45 for i in range(num_batches):
46 start_idx = i * batch_size
47 end_idx = min((i + 1) * batch_size, len(queries))
48 batch_queries = queries[start_idx:end_idx]
49
50 # Add the current batch of queries
51 self.add_query(batch_queries, collection=collection)
52
53 print(f"Batch {i+1}/{num_batches} added")
54
55 def query_table(
56 self,
57 query_text: str,
58 collection: str = None,
59 n_results: int = 5
60 ) -> pd.DataFrame:
61 """
62 Query the table and return the results
63 """
64 if not collection:
65 collection = self.collection_name
66 results = self.query([query_text], collection=collection, n_results=n_results)
67
68 metadata_results = results['metadatas'][0]
69

Callers 1

get_api_plugin_tools_docFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected