forked from emrgnt-cmplxty/automata
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request emrgnt-cmplxty#26 from EmergentAGI/feature/refacto…
…r-tool-layout Refactor agent tool layout
- Loading branch information
Showing
28 changed files
with
257 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
OPENAI_API_KEY=your_openai_api_key | ||
TASK_DB_PATH=your_task_db_path | ||
CONVERSATION_DB_PATH=your_conversation_db_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,16 +6,14 @@ This project is inspired by the theory that code is essentially a form of memory | |
|
||
## Installation and Usage | ||
|
||
--- | ||
|
||
### Initial Setup | ||
|
||
Follow these steps to setup the Automata environment | ||
|
||
```bash | ||
# Clone the repository | ||
git clone [email protected]:EmergentAGI/AutomataDocs.git | ||
cd AutomataDocs | ||
git clone [email protected]:EmergentAGI/Automata.git | ||
cd Automata | ||
|
||
# Create the local environment | ||
python3 -m venv local_env | ||
|
@@ -31,7 +29,6 @@ pre-commit install | |
cp .env.example .env | ||
MY_API_KEY=your_openai_api_key_here | ||
sed -i "s/your_openai_api_key/${MY_API_KEY}/" .env | ||
sed -i "s/your_task_db_path/$PWD/tasks.sqlite3/" .env | ||
sed -i "s/your_openai_api_key/$PWD/conversations.sqlite3/" .env | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import textwrap | ||
from typing import List | ||
|
||
from automata.core.agent.tools.agent_tool import AgentTool | ||
from automata.core.base.tool import Tool | ||
from automata.core.embedding.symbol_similarity import SymbolSimilarity | ||
from automata.core.symbol.search.symbol_search import SymbolSearch | ||
|
||
|
||
class ContextOracle(AgentTool): | ||
""" | ||
ContextOracleManager is responsible for managing context oracle tools. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
symbol_search: SymbolSearch, | ||
symbol_doc_similarity: SymbolSimilarity, | ||
): | ||
""" | ||
Initializes ContextOracleManager with given SymbolSearch, SymbolSimilarity, | ||
optional ContextTool, and post processing function. | ||
Args: | ||
symbol_search (SymbolSearch): The symbol search object. | ||
symbol_doc_similarity (SymbolSimilarity): The symbol doc similarity object. | ||
""" | ||
self.symbol_search = symbol_search | ||
self.symbol_doc_similarity = symbol_doc_similarity | ||
|
||
def build(self) -> List[Tool]: | ||
""" | ||
Builds all the context tools. | ||
Returns: | ||
List[Tool]: The list of built tools. | ||
""" | ||
tools = [ | ||
Tool( | ||
name="context-oracle", | ||
func=self._context_oracle_processor, | ||
description=textwrap.dedent( | ||
""" | ||
This tool combines SymbolSearch and SymbolSimilarity to create contexts. | ||
Given a query, it uses SymbolSimilarity calculate the similarity between each symbol's documentation and the query returns the most similar document. | ||
Then, it leverages SymbolSearch to combine Semantic Search with PageRank to find the most relevant symbols to the query. | ||
The overview documentation of these symbols is then concated to the result of the SymbolSimilarity query to create a context. | ||
For instance, if a query reads 'Tell me about SymbolRank', it will find the most similar document to this query from the embeddings, | ||
which in this case would be the documentation for the SymbolRank class. | ||
Then, it will use SymbolSearch to fetch some of the most relevant symbols which would be 'Symbol', 'SymbolSearch', 'SymbolGraph', etc. | ||
This results in a comprehensive context for the query. | ||
""" | ||
), | ||
return_direct=True, | ||
) | ||
] | ||
return tools | ||
|
||
def _context_oracle_processor(self, query: str) -> str: | ||
""" | ||
The context oracle tool processor function. | ||
Args: | ||
query (str): The query string. | ||
Returns: | ||
str: The processed result. | ||
""" | ||
doc_output = self.symbol_doc_similarity.get_query_similarity_dict(query) | ||
rank_output = self.symbol_search.symbol_rank_search(query) | ||
|
||
result = self.symbol_doc_similarity.embedding_handler.get_embedding( | ||
sorted(doc_output.items(), key=lambda x: -x[1])[0][0] | ||
).embedding_source | ||
|
||
for symbol, _ in rank_output[0:10]: | ||
try: | ||
print("Processing symbol = ", symbol) | ||
result += "%s\n" % symbol.dotpath | ||
result += self.symbol_doc_similarity.embedding_handler.get_embedding( | ||
symbol | ||
).summary | ||
except Exception as e: | ||
print("Exception = ", e) | ||
continue | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.