Skip to content

Commit

Permalink
WIP: Current redesign to make configuration management easier + speci…
Browse files Browse the repository at this point in the history
…fication of scope and catalog.
  • Loading branch information
glennga committed Feb 18, 2025
1 parent f5e1135 commit d5649ba
Show file tree
Hide file tree
Showing 30 changed files with 295 additions and 149 deletions.
1 change: 1 addition & 0 deletions docs/source/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ be read from there.

.. autopydantic_model:: agentc_core.config.config.RemoteCatalogConfig
.. autopydantic_model:: agentc_core.config.config.LocalCatalogConfig
.. autopydantic_model:: agentc_core.config.config.EmbeddingModelConfig
.. autopydantic_model:: agentc_core.config.config.CommandLineConfig
.. autopydantic_model:: agentc_core.config.config.VersioningConfig
.. autopydantic_model:: agentc_core.config.config.Config
2 changes: 2 additions & 0 deletions libs/agentc_cli/agentc_cli/cmds/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import subprocess
import typing

from .util import logging_command
from agentc_core.config import Config
from agentc_core.record.descriptor import RecordKind

Expand Down Expand Up @@ -149,6 +150,7 @@ def add_sqlpp_query(output: pathlib.Path, template_env: jinja2.Environment):
subprocess.run([default_editor, f"{output_file}"])


@logging_command(parent_logger=logger)
def cmd_add(
cfg: Config = None,
*,
Expand Down
2 changes: 2 additions & 0 deletions libs/agentc_cli/agentc_cli/cmds/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import shutil
import typing

from .util import logging_command
from agentc_core.config import Config
from agentc_core.defaults import DEFAULT_ACTIVITY_FOLDER
from agentc_core.defaults import DEFAULT_AUDIT_SCOPE
Expand Down Expand Up @@ -103,6 +104,7 @@ def clean_db(
return len(all_errs)


@logging_command(parent_logger=logger)
def cmd_clean(
cfg: Config = None,
*,
Expand Down
5 changes: 5 additions & 0 deletions libs/agentc_cli/agentc_cli/cmds/env.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import click
import importlib.util
import json
import logging
import re

from .util import logging_command
from agentc_core.config import Config

logger = logging.getLogger(__name__)


@logging_command(logger)
def cmd_env(cfg: Config = None):
if cfg is None:
cfg = Config()
Expand Down
11 changes: 3 additions & 8 deletions libs/agentc_cli/agentc_cli/cmds/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .util import DASHES
from .util import KIND_COLORS
from .util import get_catalog
from agentc_cli.cmds.util import logging_command
from agentc_core.config import Config
from agentc_core.provider import ToolProvider
from agentc_core.record.descriptor import RecordDescriptor
Expand All @@ -27,6 +28,7 @@
logger = logging.getLogger(__name__)


@logging_command(logger)
def cmd_execute(
cfg: Config = None,
*,
Expand Down Expand Up @@ -58,14 +60,7 @@ def cmd_execute(
raise ValueError("Either local FS or DB catalog must be specified!")

# Initialize a catalog instance.
catalog = get_catalog(
catalog_path=cfg.CatalogPath(),
bucket=cfg.bucket,
cluster=cfg.Cluster() if with_db else None,
force=force,
include_dirty=include_dirty,
kind="tool",
)
catalog = get_catalog(cfg=cfg, force=force, include_dirty=include_dirty, kind="tool")

# create temp directory for code dump
_dir = cfg.codegen_output if cfg.codegen_output is not None else os.getcwd()
Expand Down
13 changes: 3 additions & 10 deletions libs/agentc_cli/agentc_cli/cmds/find.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import click
import couchbase.cluster
import logging
import pydantic
import textwrap
Expand All @@ -8,6 +7,7 @@
from .util import DASHES
from .util import KIND_COLORS
from .util import get_catalog
from .util import logging_command
from agentc_core.annotation import AnnotationPredicate
from agentc_core.catalog import SearchResult
from agentc_core.config import Config
Expand Down Expand Up @@ -41,6 +41,7 @@ def check_one_field_populated(cls, values):
return values


@logging_command(logger)
def cmd_find(
cfg: Config = None,
*,
Expand Down Expand Up @@ -84,15 +85,7 @@ def cmd_find(
raise ValueError("Either local FS or DB catalog must be specified!")

# Execute the find on our catalog.
cluster: couchbase.cluster.Cluster = cfg.Cluster()
catalog = get_catalog(
catalog_path=cfg.CatalogPath(),
bucket=cfg.bucket,
cluster=cluster,
force=force,
include_dirty=include_dirty,
kind=kind,
)
catalog = get_catalog(cfg=cfg, force=force, include_dirty=include_dirty, kind=kind)
annotations_predicate = AnnotationPredicate(annotations) if annotations is not None else None
search_results = [
SearchResult(entry=x.entry, delta=x.delta)
Expand Down
9 changes: 6 additions & 3 deletions libs/agentc_cli/agentc_cli/cmds/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
from ..cmds.util import load_repository
from .util import DASHES
from .util import KIND_COLORS
from .util import logging_command
from agentc_core.catalog import __version__ as CATALOG_SCHEMA_VERSION
from agentc_core.catalog.index import MetaVersion
from agentc_core.catalog.index import index_catalog
from agentc_core.catalog.version import lib_version
from agentc_core.config import Config
from agentc_core.defaults import DEFAULT_EMBEDDING_MODEL
from agentc_core.defaults import DEFAULT_MAX_ERRS
from agentc_core.defaults import DEFAULT_MODEL_INPUT_CATALOG_FILE
from agentc_core.defaults import DEFAULT_SCAN_DIRECTORY_OPTS
Expand All @@ -25,12 +25,12 @@
logger = logging.getLogger(__name__)


@logging_command(logger)
def cmd_index(
cfg: Config = None,
*,
source_dirs: list[str | os.PathLike],
kinds: list[typing.Literal["tool", "model-input"]],
embedding_model_name: str = DEFAULT_EMBEDDING_MODEL,
dry_run: bool = False,
):
assert all(k in {"tool", "model-input"} for k in kinds)
Expand All @@ -52,7 +52,10 @@ def cmd_index(
# approach of opening & reading file contents directly,
repo, get_path_version = load_repository(pathlib.Path(os.getcwd()))
embedding_model = EmbeddingModel(
embedding_model_name=embedding_model_name,
embedding_model_name=cfg.embedding_model_name,
embedding_model_url=cfg.embedding_model_url,
embedding_model_auth=cfg.embedding_model_auth,
sentence_transformers_model_cache=cfg.sentence_transformers_model_cache,
catalog_path=cfg.CatalogPath(),
)

Expand Down
13 changes: 11 additions & 2 deletions libs/agentc_cli/agentc_cli/cmds/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import typing

from .util import CATALOG_KINDS
from .util import logging_command
from agentc_core.analytics.create import create_analytics_views
from agentc_core.analytics.create import create_query_udfs
from agentc_core.config import Config
Expand All @@ -27,6 +28,7 @@
logger = logging.getLogger(__name__)


@logging_command(parent_logger=logger)
def cmd_init(
cfg: Config = None,
*,
Expand All @@ -38,12 +40,14 @@ def cmd_init(
cfg = Config()

if local:
logger.debug("Initializing local-FS catalog and activity.")
if "catalog" in targets:
init_local_catalog(cfg)
if "activity" in targets:
init_local_activity(cfg)

if db:
logger.debug("Initializing DB catalog and activity.")
cluster = cfg.Cluster()
if "catalog" in targets:
init_db_catalog(cfg, cluster)
Expand Down Expand Up @@ -112,6 +116,13 @@ def init_db_catalog(cfg: Config, cluster: couchbase.cluster.Cluster):
# ---------------------------------------------------------------------------------------- #
# GSI and Vector Indexes #
# ---------------------------------------------------------------------------------------- #
embedding_model = EmbeddingModel(
embedding_model_name=cfg.embedding_model_name,
embedding_model_url=cfg.embedding_model_url,
embedding_model_auth=cfg.embedding_model_auth,
sentence_transformers_model_cache=cfg.sentence_transformers_model_cache,
)
dims = len(embedding_model.encode("test"))
for kind in CATALOG_KINDS:
click.secho(f"Now building the GSI indexes for the {kind} catalog.", fg="yellow")
completion_status, err = create_gsi_indexes(cfg, kind, True)
Expand All @@ -121,8 +132,6 @@ def init_db_catalog(cfg: Config, cluster: couchbase.cluster.Cluster):
click.secho(f"All GSI indexes for the {kind} catalog have been successfully created!\n", fg="green")

click.secho(f"Now building the vector index for the {kind} catalog.", fg="yellow")
embedding_model = EmbeddingModel(embedding_model_name=cfg.embedding_model)
dims = len(embedding_model.encode("test"))
_, err = create_vector_index(
cfg=cfg,
scope=DEFAULT_CATALOG_SCOPE,
Expand Down
15 changes: 6 additions & 9 deletions libs/agentc_cli/agentc_cli/cmds/ls.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import click
import logging
import typing

from agentc_cli.cmds.util import DASHES
from agentc_cli.cmds.util import KIND_COLORS
from agentc_cli.cmds.util import get_catalog
from agentc_cli.cmds.util import logging_command
from agentc_core.catalog import CatalogBase
from agentc_core.config import Config

logger = logging.getLogger(__name__)


@logging_command(parent_logger=logger)
def cmd_ls(
cfg: Config = None,
*,
Expand All @@ -33,15 +38,7 @@ def cmd_ls(
click.secho(DASHES, fg=KIND_COLORS[k])
click.secho(k.upper(), bold=True, fg=KIND_COLORS[k])
click.secho(DASHES, fg=KIND_COLORS[k])
catalog: CatalogBase = get_catalog(
catalog_path=cfg.CatalogPath(),
bucket=cfg.bucket,
cluster=cfg.Cluster() if with_db else None,
force=force,
include_dirty=include_dirty,
kind=k,
)

catalog: CatalogBase = get_catalog(cfg, force=force, include_dirty=include_dirty, kind=k)
catalog_items = list(catalog)
num = 1
for catalog_item in catalog_items:
Expand Down
7 changes: 5 additions & 2 deletions libs/agentc_cli/agentc_cli/cmds/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import pathlib
import tqdm
import typing
import uuid

from .util import DASHES
from .util import KIND_COLORS
from agentc_cli.cmds.util import logging_command
from agentc_core.analytics import Log
from agentc_core.catalog.descriptor import CatalogDescriptor
from agentc_core.config import Config
Expand All @@ -28,6 +30,7 @@
logger = logging.getLogger(__name__)


@logging_command(parent_logger=logger)
def cmd_publish(
cfg: Config = None,
*,
Expand Down Expand Up @@ -155,7 +158,7 @@ def cmd_publish(
progress_bar = tqdm.tqdm(catalog_desc.items)
for item in progress_bar:
try:
key = item.identifier + "_" + metadata["version"]["identifier"]
key = uuid.uuid4().hex
progress_bar.set_description(item.name)

# serialise object to str
Expand All @@ -169,5 +172,5 @@ def cmd_publish(
cb_coll.upsert(key, item_json)
except CouchbaseException as e:
click.secho(f"Couldn't insert catalog items!\n{e.message}", fg="red")
return e
raise e
click.secho(f"{k.capitalize()} catalog items successfully uploaded to Couchbase!\n", fg="green")
8 changes: 7 additions & 1 deletion libs/agentc_cli/agentc_cli/cmds/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from ..cmds.util import KIND_COLORS
from ..cmds.util import LEVEL_COLORS
from ..cmds.util import load_repository
from .util import logging_command
from agentc_core.catalog.descriptor import CatalogDescriptor
from agentc_core.catalog.index import MetaVersion
from agentc_core.catalog.index import index_catalog_start
Expand All @@ -33,6 +34,7 @@
logger = logging.getLogger(__name__)


@logging_command(logger)
def cmd_status(
cfg: Config = None,
*,
Expand Down Expand Up @@ -269,7 +271,11 @@ def get_local_status(
# Start a CatalogMem on-the-fly that incorporates the dirty
# source file items which we'll use instead of the local catalog file.
errs, catalog, uninitialized_items = index_catalog_start(
EmbeddingModel(embedding_model_name=catalog_desc.embedding_model),
EmbeddingModel(
embedding_model_name=cfg.embedding_model_name,
embedding_model_auth=cfg.embedding_model_auth,
embedding_model_url=cfg.embedding_model_url,
),
MetaVersion(
schema_version=catalog_desc.schema_version, library_version=catalog_desc.library_version
),
Expand Down
Loading

0 comments on commit d5649ba

Please # to comment.