Skip to content

Commit

Permalink
WIP: refactoring into mono-repo
Browse files Browse the repository at this point in the history
  • Loading branch information
glennga committed Oct 15, 2024
1 parent 0d4519f commit 2fabf54
Show file tree
Hide file tree
Showing 143 changed files with 739 additions and 1,971 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/github-actions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ jobs:
- name: Check out repository code
uses: actions/checkout@v4

- name: Verify existence of essential files
uses: thebinaryfelix/[email protected]
with:
files: 'README.md, pyproject.toml, .gitignore, libs/agent_catalog_libs/cmd/, libs/agent_catalog_libs/core/, libs/agent_catalog_libs/tests/, libs/lc/agent_catalog_lc/, libs/lc/examples/'
# - name: Verify existence of essential files
# uses: thebinaryfelix/[email protected]
# with:
# files: 'README.md, pyproject.toml, .gitignore, libs/agentc_core/agentc_cli/, libs/agentc_core/agentc_core/, libs/agentc_core/tests/, libs/agentc_langchain/agentc_langchain/, libs/agentc_langchain/examples/'

- name: Verify command file existence
uses: thebinaryfelix/[email protected]
with:
files: 'libs/agent_catalog_libs/cmd/cmds/index.py, libs/agent_catalog_libs/cmd/cmds/publish.py, libs/agent_catalog_libs/cmd/cmds/version.py, libs/agent_catalog_libs/cmd/cmds/find.py,
libs/agent_catalog_libs/cmd/cmds/clean.py, libs/agent_catalog_libs/cmd/cmds/env.py, libs/agent_catalog_libs/cmd/cmds/execute.py, libs/agent_catalog_libs/cmd/cmds/status.py, libs/agent_catalog_libs/cmd/cmds/util.py'
# - name: Verify command file existence
# uses: thebinaryfelix/[email protected]
# with:
# files: 'libs/agentc_core/agentc_cli/cmds/index.py, libs/agentc_core/agentc_cli/cmds/publish.py, libs/agentc_core/agentc_cli/cmds/version.py, libs/agentc_core/agentc_cli/cmds/find.py,
# libs/agentc_core/agentc_cli/cmds/clean.py, libs/agentc_core/agentc_cli/cmds/env.py, libs/agentc_core/agentc_cli/cmds/execute.py, libs/agentc_core/agentc_cli/cmds/status.py, libs/agentc_core/agentc_cli/cmds/util.py'

- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- name: Set up Python Poetry
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ ipython_config.py
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
Expand Down
16 changes: 0 additions & 16 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,3 @@ repos:
args: ["--fix"]
- id: ruff-format
name: format code with ruff

# # To make sure we don't commit anything incorrectly.
# - repo: local
# hooks:
# - id: do-not-commit-local-dev
# name: check for local dev environment
# entry: ^agent-catalog-\w+\s*=\s*\{\s*path\s*=
# language: pygrep
# types: [ toml ]

# For making sure the poetry.lock file is up-to-date.
- repo: https://github.com/python-poetry/poetry
rev: '1.8.0'
hooks:
- id: poetry-check
- id: poetry-lock
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# agent-catalog

User facing repository for all things agent-catalog (tooling around agent workflows).
The mono-repo for the Couchbase Agent Catalog project.

## Building From Source

Expand Down Expand Up @@ -40,10 +40,10 @@ Refer to [`docs/`](docs) to explore templates and other references while writing

All sdk code is wrapped under [`libs`](libs). Following are sub-folders that you can explore:

1. [`agent_catalog`](libs/agent_catalog), which contains the classes to use with your agent development frameworks,
2. [`agent_catalog_libs`](libs/agent_catalog_libs), which implements the core functionality of
1. [`agent_catalog`](libs/agentc), which contains the classes to use with your agent development frameworks,
2. [`agent_catalog_libs`](libs/agentc_core), which implements the core functionality of
`agentc` in an "un-opinionated" manner,
3. [`lc`](libs/lc), which supplies additional tooling around building
3. [`lc`](libs/agentc_langchain), which supplies additional tooling around building
LangChain-specific agents.

This repository (`agent-catalog`) is meant to serve as a "front-desk", where we focus on _setting defaults_
Expand Down
5 changes: 0 additions & 5 deletions libs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
# from libs.agent_catalog import *
# from libs.agent_catalog_libs import *
from libs.lc import audit

__all__ = ["audit"]
9 changes: 0 additions & 9 deletions libs/agent_catalog/__init__.py

This file was deleted.

9 changes: 0 additions & 9 deletions libs/agent_catalog/__main__.py

This file was deleted.

21 changes: 0 additions & 21 deletions libs/agent_catalog_libs/__init__.py

This file was deleted.

5 changes: 0 additions & 5 deletions libs/agent_catalog_libs/core/activity/auditor/__init__.py

This file was deleted.

19 changes: 0 additions & 19 deletions libs/agent_catalog_libs/core/defaults.py

This file was deleted.

9 changes: 9 additions & 0 deletions libs/agentc/agentc/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from agentc.auditor import Auditor
from agentc.provider import Provider
from agentc_core.tool.decorator import tool

__all__ = [
"Provider",
"Auditor",
"tool",
]
9 changes: 9 additions & 0 deletions libs/agentc/agentc/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def main():
import agentc_cli

# Note: all the CLI code currently resides in agentc_cli.
agentc_cli.main()


if __name__ == "__main__":
main()
44 changes: 22 additions & 22 deletions libs/agent_catalog/auditor.py → libs/agentc/agentc/auditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
import typing

from .provider import Provider
from libs.agent_catalog_libs import activity
from libs.agent_catalog_libs import analytics
from libs.agent_catalog_libs import catalog_defaults
from agentc_core.activity import DBAuditor
from agentc_core.activity import LocalAuditor
from agentc_core.analytics import Kind
from agentc_core.defaults import DEFAULT_ACTIVITY_FOLDER
from agentc_core.defaults import DEFAULT_LLM_ACTIVITY_NAME

logger = logging.getLogger(__name__)

# On audits, we need to export the "kind" associated with a log...
Kind = analytics.log.Kind
Kind = Kind


class Auditor(pydantic_settings.BaseSettings):
Expand All @@ -33,10 +35,10 @@ class Auditor(pydantic_settings.BaseSettings):
""" Couchbase connection string that points to the audit logs.
This Couchbase instance refers to a CB instance that possesses the audit log collection. This collection is
automatically generated on `agent_catalog index`, so this field is most likely the same instance as the CB instance
automatically generated on `agentc index`, so this field is most likely the same instance as the CB instance
possessing the catalog. If there exists no local audit log location (e.g., this is deployed in a standalone
environment) OR if $AGENT_CATALOG_CATALOG is not explicitly set, we will perform all "accept" commands directly on the
remote audit log collection.
environment) OR if $AGENT_CATALOG_CATALOG is not explicitly set, we will perform all "accept" commands directly on
the remote audit log collection.
This field must be specified with username, password, and bucket.
"""
Expand All @@ -63,21 +65,21 @@ class Auditor(pydantic_settings.BaseSettings):
""" Location of the catalog path.
This field is used to search for the catalog version. If this field is not set, we will defer to the default
behavior of agent_catalog.Provider.
behavior of agentc.Provider.
"""

local_log: typing.Optional[pathlib.Path] = None
""" Local audit log file to write to.
If this field and $AGENT_CATALOG_CONN_STRING are not set, we will perform a best-effort search by walking upward from the
current working directory until we find the 'agent_catalog_libs.catalog_defaults.DEFAULT_ACTIVITY_FOLDER' folder and subsequently
generate an audit log here.
If this field and $AGENT_CATALOG_CONN_STRING are not set, we will perform a best-effort search by walking upward
from the current working directory until we find the 'agentc_core.defaults.DEFAULT_ACTIVITY_FOLDER' folder and
subsequently generate an audit log here.
Audit log files will reach a maximum of 128MB (by default) before they are rotated and compressed.
"""

_local_auditor: activity.LocalAuditor = None
_db_auditor: activity.DBAuditor = None
_local_auditor: LocalAuditor = None
_db_auditor: DBAuditor = None
_audit: typing.Callable = None

@pydantic.model_validator(mode="after")
Expand All @@ -86,17 +88,15 @@ def _find_local_log(self) -> typing.Self:
working_path = pathlib.Path.cwd()
logger.debug(
'Starting best effort search for the activity folder. Searching for "%s".',
catalog_defaults.DEFAULT_ACTIVITY_FOLDER,
DEFAULT_ACTIVITY_FOLDER,
)

# Iteratively ascend our starting path until we find the activity folder.
while not (working_path / catalog_defaults.DEFAULT_ACTIVITY_FOLDER).exists():
while not (working_path / DEFAULT_ACTIVITY_FOLDER).exists():
if working_path.parent == working_path:
return self
working_path = working_path.parent
self.local_log = (
working_path / catalog_defaults.DEFAULT_ACTIVITY_FOLDER / catalog_defaults.DEFAULT_LLM_ACTIVITY_NAME
)
self.local_log = working_path / DEFAULT_ACTIVITY_FOLDER / DEFAULT_LLM_ACTIVITY_NAME

return self

Expand All @@ -122,8 +122,8 @@ def _find_remote_log(self) -> typing.Self:
def _initialize_auditor(self) -> typing.Self:
if self.local_log is None and self.conn_string is None:
error_message = textwrap.dedent("""
Could not find $AGENT_CATALOG_ACTIVITY nor $AGENT_CATALOG_CONN_STRING! If this is a new project, please run the
command `agent_catalog index` before instantiating an auditor. Otherwise, please set either of these
Could not find $AGENT_CATALOG_ACTIVITY nor $AGENT_CATALOG_CONN_STRING! If this is a new project, please
run the command `agentc index` before instantiating an auditor. Otherwise, please set either of these
variables.
""")
logger.error(error_message)
Expand All @@ -140,11 +140,11 @@ def _initialize_auditor(self) -> typing.Self:

# Finally, instantiate our auditors.
if self.local_log is not None:
self._local_auditor = activity.LocalAuditor(
self._local_auditor = LocalAuditor(
output=self.local_log, catalog_version=provider.version, model=self.llm_name
)
if self.conn_string is not None:
self._db_auditor = activity.DBAuditor(
self._db_auditor = DBAuditor(
conn_string=self.conn_string,
username=self.username.get_secret_value(),
password=self.password.get_secret_value(),
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

logger = logging.getLogger(__name__)

# We will only expose agent_catalog_lc if it exists.
if importlib.util.find_spec("agent_catalog_lc") is not None:
mod = importlib.import_module("agent_catalog_lc")
# We will only expose agentc_langchain if it exists.
if importlib.util.find_spec("agentc_langchain") is not None:
mod = importlib.import_module("agentc_langchain")

# TODO (GLENN): Is there a less messy way to do this that doesn't erase symbols? (to keep IDEs happy)
class AuditType(typing.Protocol):
Expand All @@ -28,7 +28,7 @@ def audit(
session: typing.AnyStr,
auditor: agent_catalog.auditor,
) -> langchain_core.language_models.chat_models.BaseChatModel:
logger.warning("agent_catalog_lc not found! Returning chat_model without modification.")
logger.warning("agentc_langchain not found! Returning chat_model without modification.")
return chat_model


Expand Down
Loading

0 comments on commit 2fabf54

Please sign in to comment.