[annotation improvement] Make AgentType->Class Conversion More Scalable (#3749)

In the current solution, AgentType and AGENT_TO_CLASS are placed in two
separate files and both manually maintained. This might cause
inconsistency when we update either of them.

— latest —
based on the discussion with hwchase17, we don’t know how to further use
the newly introduced AgentTypeConfig type, so it doesn’t make sense yet
to add it. Instead, it’s better to move the dictionary to another file
to keep the loading.py file clear. The consistency is a good point.
Instead of asserting the consistency during linting, we added a unittest
for consistency check. I think it works as auto unittest is triggered
every time with clear failure notice. (well, force push is possible, but
we all know what we are doing, so let’s show trust. :>)

~~This PR includes~~
- ~~Introduced AgentTypeConfig as the source of truth of all AgentType
related meta data.~~
- ~~Each AgentTypeConfig is a annotated class type which can be used for
annotation in other places.~~
- ~~Each AgentTypeConfig can be easily extended when we have more meta
data needs.~~
- ~~Strong assertion to ensure AgentType and AGENT_TO_CLASS are always
consistent.~~
- ~~Made AGENT_TO_CLASS automatically generated.~~

~~Test Plan:~~
- ~~since this change is focusing on annotation, lint is the major test
focus.~~
- ~~lint, format and test passed on local.~~
This commit is contained in:
Mike Wang
2023-04-28 21:17:28 -07:00
committed by GitHub
parent b7ae9f715d
commit 512c24fc9c
3 changed files with 30 additions and 17 deletions

View File

@@ -0,0 +1,9 @@
import unittest
from langchain.agents.agent_types import AgentType
from langchain.agents.types import AGENT_TO_CLASS
class TestTypes(unittest.TestCase):
def test_confirm_full_coverage(self) -> None:
self.assertEqual(list(AgentType), list(AGENT_TO_CLASS.keys()))