Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Improve docs and nbs (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
emrgnt-cmplxty authored Jul 6, 2023
1 parent ee7fb58 commit 9c45309
Show file tree
Hide file tree
Showing 52 changed files with 1,501 additions and 419 deletions.
29 changes: 9 additions & 20 deletions automata/core/tools/builders/context_oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from automata.core.agent.agent import AgentToolkitBuilder, AgentToolkitNames
from automata.core.agent.providers import OpenAIAgentToolkitBuilder
from automata.core.embedding.base import EmbeddingSimilarityCalculator
from automata.core.experimental.search.symbol_search import SymbolSearch
from automata.core.llm.providers.openai import OpenAITool
from automata.core.memory_store.symbol_code_embedding import SymbolCodeEmbeddingHandler
from automata.core.memory_store.symbol_doc_embedding import SymbolDocEmbeddingHandler
Expand All @@ -22,11 +23,13 @@ class ContextOracleToolkitBuilder(AgentToolkitBuilder):

def __init__(
self,
symbol_search: SymbolSearch,
symbol_doc_embedding_handler: SymbolDocEmbeddingHandler,
symbol_code_embedding_handler: SymbolCodeEmbeddingHandler,
embedding_similarity_calculator: EmbeddingSimilarityCalculator,
**kwargs,
) -> None:
self.symbol_search = symbol_search
self.symbol_doc_embedding_handler = symbol_doc_embedding_handler
self.symbol_code_embedding_handler = symbol_code_embedding_handler
self.embedding_similarity_calculator = embedding_similarity_calculator
Expand All @@ -43,7 +46,7 @@ def build(self) -> List[Tool]:
)
]

def _get_context(self, query: str, max_related_symbols=1) -> str:
def _get_context(self, query: str, max_related_symbols=10) -> str:
"""
Retrieves the context corresponding to a given query.
Expand All @@ -55,24 +58,10 @@ def _get_context(self, query: str, max_related_symbols=1) -> str:
results when populated for the relevant query. Thus, selecting the maximum will factor in documentation
when populated.
"""
doc_embeddings = self.symbol_doc_embedding_handler.get_ordered_embeddings()
doc_search_results = self.embedding_similarity_calculator.calculate_query_similarity_dict(
doc_embeddings, query
)
code_embeddings = self.symbol_code_embedding_handler.get_ordered_embeddings()
code_search_results = self.embedding_similarity_calculator.calculate_query_similarity_dict(
code_embeddings, query
)
combined_results = {
key: max(doc_search_results.get(key, 0), code_search_results.get(key, 0))
for key in set(doc_search_results).union(code_search_results)
}

most_similar_symbols = [
ele[0] for ele in sorted(combined_results.items(), key=lambda x: -x[1])
]
symbol_rank_search_results = self.symbol_search.symbol_rank_search(query)

most_similar_symbol = most_similar_symbols[0]
most_similar_symbol = symbol_rank_search_results[0][0]

most_similar_code_embedding = self.symbol_code_embedding_handler.get_embedding(
most_similar_symbol
Expand All @@ -84,7 +73,7 @@ def _get_context(self, query: str, max_related_symbols=1) -> str:
most_similar_doc_embedding = self.symbol_doc_embedding_handler.get_embedding(
most_similar_symbol
)
result += f"Documentation Summary:\n\n{most_similar_doc_embedding.summary}"
result += f"Documentation:\n\n{most_similar_doc_embedding.input_object}"
except Exception as e:
logger.error(
"Failed to get embedding for symbol %s with error: %s",
Expand All @@ -96,7 +85,7 @@ def _get_context(self, query: str, max_related_symbols=1) -> str:

counter = 0

for symbol in most_similar_symbols:
for symbol in [symbol for symbol, _ in symbol_rank_search_results]:
if symbol == most_similar_symbol:
continue
if counter >= max_related_symbols:
Expand All @@ -114,7 +103,7 @@ def _get_context(self, query: str, max_related_symbols=1) -> str:
e,
)
continue

print("result = ", result)
return result


Expand Down
1 change: 1 addition & 0 deletions automata/core/tools/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class AgentToolFactory:
AgentToolkitNames.PY_WRITER: [("py_writer", PyWriter)],
AgentToolkitNames.SYMBOL_SEARCH: [("symbol_search", SymbolSearch)],
AgentToolkitNames.CONTEXT_ORACLE: [
("symbol_search", SymbolSearch),
("symbol_doc_embedding_handler", SymbolDocEmbeddingHandler),
("symbol_code_embedding_handler", SymbolCodeEmbeddingHandler),
("embedding_similarity_calculator", EmbeddingSimilarityCalculator),
Expand Down
63 changes: 63 additions & 0 deletions automata/docs/agent_guide.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
=================
Agent Guide
=================

OpenAIAutomataAgentConfigBuilder
================================

Overview
--------

The OpenAIAutomataAgentConfigBuilder is used to build instances of AutomataAgents. It provides a flexible way to set different properties of the agent before instantiation. This class is a subclass of AgentConfigBuilder and belongs to the `automata.config.openai_agent` module.

The builder takes an OpenAIAutomataAgentConfig object as an attribute, which holds various configuration settings for the agent. These settings can include the model, instruction version, system template formatter, etc.

You can use the `create_config` and `create_from_args` static methods to instantiate the OpenAIAutomataAgentConfig class. Individual properties of the agent can be set using the `with_*` methods.

Example
-------

.. code-block:: python
from automata.config.openai_agent import OpenAIAutomataAgentConfigBuilder
from automata.config.base import AgentConfigName
# Create an instance of OpenAIAutomataAgentConfig using create_config method
config = OpenAIAutomataAgentConfigBuilder.create_config(config_name=AgentConfigName.DEFAULT)
# Create an instance of OpenAIAutomataAgentConfigBuilder using with_model method
builder = OpenAIAutomataAgentConfigBuilder.with_model("gpt-4")
OpenAIAutomataAgent
===================

Overview
--------

OpenAIAutomataAgent is an autonomous agent designed to execute instructions and report the results back to the main system. It uses the OpenAI API to generate responses based on given instructions and manages interactions with various tools.

The agent operates in iterations and stops when it completes its task or exceeds the maximum iterations set in the configuration. OpenAIAutomataAgent uses tools that are instances of OpenAITool.

Usage
-----

.. code-block:: python
from automata.core.agent.providers import OpenAIAutomataAgent
from automata.config.openai_agent import OpenAIAutomataAgentConfig
# Create OpenAIAutomataAgentConfig
config = OpenAIAutomataAgentConfig()
# Initialize OpenAIAutomataAgent
agent = OpenAIAutomataAgent('your_instructions', config)
# Run the agent
result = agent.run()
Limitations
-----------

OpenAIAutomataAgent's full functionality depends on the integration with OpenAI API requirements and limitations. Improvements might be needed in logging and exception handling. It currently does not support multiple assistants.

7 changes: 4 additions & 3 deletions automata/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = []
extensions = ["sphinx_panels", "sphinx_rtd_dark_mode"]

templates_path = ["_templates"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
Expand All @@ -23,7 +23,8 @@


# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
# https://www.sphinx-doc.org/en/master/usage/configurat3ion.html#options-for-html-output

html_theme = "sphinx-rtd-dark-mode"

html_theme = "sphinx_rtd_theme"
html_static_path = ["_static"]
8 changes: 8 additions & 0 deletions automata/docs/config/base/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ how to :ref:`installation` the project.











.. AUTO-GENERATED CONTENT START
..
Expand Down
10 changes: 9 additions & 1 deletion automata/docs/config/index.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
Config Modules
Config Classes
==============

**Automata** is a Python library for autonomous providers.

Check out the :doc:`usage` section for further information, including
how to :ref:`installation` the project.









.. AUTO-GENERATED CONTENT START
..
Expand Down
8 changes: 8 additions & 0 deletions automata/docs/config/openai_agent/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ how to :ref:`installation` the project.











.. AUTO-GENERATED CONTENT START
..
Expand Down
8 changes: 8 additions & 0 deletions automata/docs/core/agent/agent/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ how to :ref:`installation` the project.











.. AUTO-GENERATED CONTENT START
..
Expand Down
8 changes: 8 additions & 0 deletions automata/docs/core/agent/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ how to :ref:`installation` the project.











.. AUTO-GENERATED CONTENT START
..
Expand Down
8 changes: 8 additions & 0 deletions automata/docs/core/agent/instances/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ how to :ref:`installation` the project.











.. AUTO-GENERATED CONTENT START
..
Expand Down
8 changes: 8 additions & 0 deletions automata/docs/core/base/database/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ how to :ref:`installation` the project.











.. AUTO-GENERATED CONTENT START
..
Expand Down
8 changes: 8 additions & 0 deletions automata/docs/core/base/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ how to :ref:`installation` the project.











.. AUTO-GENERATED CONTENT START
..
Expand Down
8 changes: 8 additions & 0 deletions automata/docs/core/base/patterns/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ how to :ref:`installation` the project.











.. AUTO-GENERATED CONTENT START
..
Expand Down
8 changes: 8 additions & 0 deletions automata/docs/core/code_handling/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ how to :ref:`installation` the project.











.. AUTO-GENERATED CONTENT START
..
Expand Down
8 changes: 8 additions & 0 deletions automata/docs/core/code_handling/py/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ how to :ref:`installation` the project.











.. AUTO-GENERATED CONTENT START
..
Expand Down
8 changes: 8 additions & 0 deletions automata/docs/core/code_handling/py/writer/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ how to :ref:`installation` the project.











.. AUTO-GENERATED CONTENT START
..
Expand Down
8 changes: 8 additions & 0 deletions automata/docs/core/context_providers/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ how to :ref:`installation` the project.











.. AUTO-GENERATED CONTENT START
..
Expand Down
8 changes: 8 additions & 0 deletions automata/docs/core/embedding/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ how to :ref:`installation` the project.











.. AUTO-GENERATED CONTENT START
..
Expand Down
Loading

0 comments on commit 9c45309

Please sign in to comment.