agentc-core 0.2.1a1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agentc_core-0.2.1a1/PKG-INFO +28 -0
- agentc_core-0.2.1a1/agentc_core/__init__.py +9 -0
- agentc_core-0.2.1a1/agentc_core/activity/__init__.py +7 -0
- agentc_core-0.2.1a1/agentc_core/activity/logger/__init__.py +6 -0
- agentc_core-0.2.1a1/agentc_core/activity/logger/base.py +59 -0
- agentc_core-0.2.1a1/agentc_core/activity/logger/chain.py +22 -0
- agentc_core-0.2.1a1/agentc_core/activity/logger/db.py +43 -0
- agentc_core-0.2.1a1/agentc_core/activity/logger/local.py +47 -0
- agentc_core-0.2.1a1/agentc_core/activity/models/__init__.py +0 -0
- agentc_core-0.2.1a1/agentc_core/activity/models/content.py +567 -0
- agentc_core-0.2.1a1/agentc_core/activity/models/log.py +61 -0
- agentc_core-0.2.1a1/agentc_core/activity/remote/__init__.py +0 -0
- agentc_core-0.2.1a1/agentc_core/activity/remote/analytics/1.sessions.sqlpp +50 -0
- agentc_core-0.2.1a1/agentc_core/activity/remote/analytics/2.last_session.sqlpp +12 -0
- agentc_core-0.2.1a1/agentc_core/activity/remote/analytics/3.exchanges.sqlpp +127 -0
- agentc_core-0.2.1a1/agentc_core/activity/remote/analytics/4.tool_invocations.sqlpp +132 -0
- agentc_core-0.2.1a1/agentc_core/activity/remote/create.py +63 -0
- agentc_core-0.2.1a1/agentc_core/activity/remote/query/1.sessions.sqlpp +53 -0
- agentc_core-0.2.1a1/agentc_core/activity/remote/query/2.last_session.sqlpp +12 -0
- agentc_core-0.2.1a1/agentc_core/activity/remote/query/3.exchanges.sqlpp +128 -0
- agentc_core-0.2.1a1/agentc_core/activity/remote/query/4.tool_invocations.sqlpp +130 -0
- agentc_core-0.2.1a1/agentc_core/activity/span.py +466 -0
- agentc_core-0.2.1a1/agentc_core/annotation/__init__.py +3 -0
- agentc_core-0.2.1a1/agentc_core/annotation/annotation.py +72 -0
- agentc_core-0.2.1a1/agentc_core/catalog/__init__.py +15 -0
- agentc_core-0.2.1a1/agentc_core/catalog/catalog.py +392 -0
- agentc_core-0.2.1a1/agentc_core/catalog/descriptor.py +73 -0
- agentc_core-0.2.1a1/agentc_core/catalog/directory.py +63 -0
- agentc_core-0.2.1a1/agentc_core/catalog/implementations/__init__.py +0 -0
- agentc_core-0.2.1a1/agentc_core/catalog/implementations/base.py +60 -0
- agentc_core-0.2.1a1/agentc_core/catalog/implementations/chain.py +59 -0
- agentc_core-0.2.1a1/agentc_core/catalog/implementations/db.py +267 -0
- agentc_core-0.2.1a1/agentc_core/catalog/implementations/mem.py +116 -0
- agentc_core-0.2.1a1/agentc_core/catalog/index.py +241 -0
- agentc_core-0.2.1a1/agentc_core/catalog/version.py +41 -0
- agentc_core-0.2.1a1/agentc_core/config/__init__.py +19 -0
- agentc_core-0.2.1a1/agentc_core/config/config.py +547 -0
- agentc_core-0.2.1a1/agentc_core/defaults.py +59 -0
- agentc_core-0.2.1a1/agentc_core/evaluation/__init__.py +4 -0
- agentc_core-0.2.1a1/agentc_core/evaluation/decorator.py +12 -0
- agentc_core-0.2.1a1/agentc_core/evaluation/evaluate.py +54 -0
- agentc_core-0.2.1a1/agentc_core/indexer/__init__.py +5 -0
- agentc_core-0.2.1a1/agentc_core/indexer/indexer.py +184 -0
- agentc_core-0.2.1a1/agentc_core/learned/__init__.py +0 -0
- agentc_core-0.2.1a1/agentc_core/learned/embedding.py +189 -0
- agentc_core-0.2.1a1/agentc_core/learned/model.py +23 -0
- agentc_core-0.2.1a1/agentc_core/prompt/__init__.py +0 -0
- agentc_core-0.2.1a1/agentc_core/prompt/models.py +134 -0
- agentc_core-0.2.1a1/agentc_core/prompt/templates/prompt.jinja +47 -0
- agentc_core-0.2.1a1/agentc_core/provider/__init__.py +15 -0
- agentc_core-0.2.1a1/agentc_core/provider/loader.py +167 -0
- agentc_core-0.2.1a1/agentc_core/provider/provider.py +194 -0
- agentc_core-0.2.1a1/agentc_core/provider/refiner.py +66 -0
- agentc_core-0.2.1a1/agentc_core/record/__init__.py +0 -0
- agentc_core-0.2.1a1/agentc_core/record/descriptor.py +109 -0
- agentc_core-0.2.1a1/agentc_core/record/helper.py +73 -0
- agentc_core-0.2.1a1/agentc_core/remote/__init__.py +0 -0
- agentc_core-0.2.1a1/agentc_core/remote/init.py +111 -0
- agentc_core-0.2.1a1/agentc_core/remote/publish.py +154 -0
- agentc_core-0.2.1a1/agentc_core/remote/util/__init__.py +0 -0
- agentc_core-0.2.1a1/agentc_core/remote/util/ddl.py +571 -0
- agentc_core-0.2.1a1/agentc_core/remote/util/query.py +23 -0
- agentc_core-0.2.1a1/agentc_core/secrets/__init__.py +4 -0
- agentc_core-0.2.1a1/agentc_core/secrets/secrets.py +27 -0
- agentc_core-0.2.1a1/agentc_core/security/__init__.py +3 -0
- agentc_core-0.2.1a1/agentc_core/security/security.py +10 -0
- agentc_core-0.2.1a1/agentc_core/tool/__init__.py +3 -0
- agentc_core-0.2.1a1/agentc_core/tool/decorator.py +59 -0
- agentc_core-0.2.1a1/agentc_core/tool/descriptor/__init__.py +11 -0
- agentc_core-0.2.1a1/agentc_core/tool/descriptor/models.py +446 -0
- agentc_core-0.2.1a1/agentc_core/tool/descriptor/secrets.py +21 -0
- agentc_core-0.2.1a1/agentc_core/tool/generate/__init__.py +5 -0
- agentc_core-0.2.1a1/agentc_core/tool/generate/common.py +66 -0
- agentc_core-0.2.1a1/agentc_core/tool/generate/generator.py +242 -0
- agentc_core-0.2.1a1/agentc_core/tool/generate/templates/httpreq_q.jinja +80 -0
- agentc_core-0.2.1a1/agentc_core/tool/generate/templates/semantic_q.jinja +84 -0
- agentc_core-0.2.1a1/agentc_core/tool/generate/templates/sqlpp_q.jinja +63 -0
- agentc_core-0.2.1a1/agentc_core/tool/templates/http_request.jinja +23 -0
- agentc_core-0.2.1a1/agentc_core/tool/templates/python_function.jinja +18 -0
- agentc_core-0.2.1a1/agentc_core/tool/templates/semantic_search.jinja +70 -0
- agentc_core-0.2.1a1/agentc_core/tool/templates/sqlpp_query.jinja +41 -0
- agentc_core-0.2.1a1/agentc_core/version/__init__.py +3 -0
- agentc_core-0.2.1a1/agentc_core/version/identifier.py +40 -0
- agentc_core-0.2.1a1/pyproject.toml +89 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: agentc-core
|
|
3
|
+
Version: 0.2.1a1
|
|
4
|
+
Summary: The core for the Couchbase Agent Catalog project.
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
Author: Glenn Galvizo
|
|
7
|
+
Author-email: glenn.galvizo@couchbase.com
|
|
8
|
+
Requires-Python: >=3.12
|
|
9
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Requires-Dist: GitPython (>=3.1.43,<4.0.0)
|
|
14
|
+
Requires-Dist: PyYAML (>=6.0.1,<7.0.0)
|
|
15
|
+
Requires-Dist: couchbase (>=4.3.0,<5.0.0)
|
|
16
|
+
Requires-Dist: datamodel-code-generator (>=0.26.0,<0.27.0)
|
|
17
|
+
Requires-Dist: gitignore-parser (>=0.1.11,<0.2.0)
|
|
18
|
+
Requires-Dist: jinja2 (>=3.1.4,<4.0.0)
|
|
19
|
+
Requires-Dist: jsbeautifier (>=1.15.1,<2.0.0)
|
|
20
|
+
Requires-Dist: jsonschema (>=4.23.0,<5.0.0)
|
|
21
|
+
Requires-Dist: openapi-pydantic (>=0.5.1,<0.6.0)
|
|
22
|
+
Requires-Dist: py-openapi-schema-to-json-schema (>=0.0.3,<0.0.4)
|
|
23
|
+
Requires-Dist: pydantic (>=2.10.6,<3.0.0)
|
|
24
|
+
Requires-Dist: requests (>=2.32.3,<3.0.0)
|
|
25
|
+
Requires-Dist: semantic_version (>=2.10.0,<3.0.0)
|
|
26
|
+
Requires-Dist: sentence-transformers (>=3.4.1,<4.0.0)
|
|
27
|
+
Project-URL: Documentation, https://couchbaselabs.github.io/agent-catalog/api.html
|
|
28
|
+
Project-URL: Repository, https://github.com/couchbaselabs/agent-catalog
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import agentc_core.catalog as catalog
|
|
2
|
+
import agentc_core.config as config
|
|
3
|
+
import agentc_core.provider as provider
|
|
4
|
+
import agentc_core.tool as tool
|
|
5
|
+
|
|
6
|
+
__all__ = ["tool", "provider", "catalog", "config"]
|
|
7
|
+
|
|
8
|
+
# DO NOT edit this value, the plugin "poetry-dynamic-versioning" will automatically set this.
|
|
9
|
+
__version__ = "0.0.0"
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import abc
|
|
2
|
+
import datetime
|
|
3
|
+
import logging
|
|
4
|
+
import uuid
|
|
5
|
+
|
|
6
|
+
from ...version import VersionDescriptor
|
|
7
|
+
from ..models.content import Content
|
|
8
|
+
from ..models.log import Log
|
|
9
|
+
|
|
10
|
+
logger = logging.getLogger(__name__)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class BaseLogger(abc.ABC):
|
|
14
|
+
def __init__(self, catalog_version: VersionDescriptor, **kwargs):
|
|
15
|
+
self.catalog_version = catalog_version
|
|
16
|
+
self.annotations = kwargs
|
|
17
|
+
|
|
18
|
+
def log(
|
|
19
|
+
self,
|
|
20
|
+
content: Content,
|
|
21
|
+
span_name: list[str],
|
|
22
|
+
session_id: str,
|
|
23
|
+
log_id: str = None,
|
|
24
|
+
timestamp: datetime.datetime = None,
|
|
25
|
+
**kwargs,
|
|
26
|
+
) -> Log:
|
|
27
|
+
# If the timestamp is not given, generate this value ourselves.
|
|
28
|
+
if timestamp is None:
|
|
29
|
+
timestamp = datetime.datetime.now().astimezone()
|
|
30
|
+
|
|
31
|
+
# Note: The accept call annotations take precedence over init-time annotations.
|
|
32
|
+
if len(self.annotations) > 0 and len(kwargs) > 0:
|
|
33
|
+
annotations = {**self.annotations, **kwargs}
|
|
34
|
+
elif len(self.annotations) > 0:
|
|
35
|
+
annotations = self.annotations
|
|
36
|
+
elif len(kwargs) > 0:
|
|
37
|
+
annotations = kwargs
|
|
38
|
+
else:
|
|
39
|
+
annotations = None
|
|
40
|
+
|
|
41
|
+
message = Log(
|
|
42
|
+
identifier=log_id or uuid.uuid4().hex,
|
|
43
|
+
timestamp=timestamp.isoformat(),
|
|
44
|
+
span=Log.Span(name=span_name, session=session_id),
|
|
45
|
+
content=content,
|
|
46
|
+
catalog_version=self.catalog_version,
|
|
47
|
+
annotations=annotations,
|
|
48
|
+
)
|
|
49
|
+
self._accept(message, message.model_dump(exclude_none=True, mode="json"))
|
|
50
|
+
|
|
51
|
+
# For debug, we'll pretty-print what we log.
|
|
52
|
+
if logger.isEnabledFor(logging.DEBUG):
|
|
53
|
+
logger.debug(f"Logging message: {message.model_dump_json(indent=2, exclude_none=True)}")
|
|
54
|
+
|
|
55
|
+
return message
|
|
56
|
+
|
|
57
|
+
@abc.abstractmethod
|
|
58
|
+
def _accept(self, log_obj: Log, log_json: dict):
|
|
59
|
+
pass
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import logging.handlers
|
|
2
|
+
|
|
3
|
+
from ..models.log import Log
|
|
4
|
+
from .base import BaseLogger
|
|
5
|
+
from .db import DBLogger
|
|
6
|
+
from .local import LocalLogger
|
|
7
|
+
|
|
8
|
+
logger = logging.getLogger(__name__)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class ChainLogger(BaseLogger):
|
|
12
|
+
# TODO (GLENN): Add rollover to our Config class.
|
|
13
|
+
def __init__(self, local_logger: LocalLogger, db_logger: DBLogger, **kwargs):
|
|
14
|
+
if db_logger.catalog_version != local_logger.catalog_version:
|
|
15
|
+
raise ValueError("Catalog versions must match between remote and local-FS loggers!")
|
|
16
|
+
super(ChainLogger, self).__init__(catalog_version=local_logger.catalog_version, **kwargs)
|
|
17
|
+
self.db_logger = db_logger
|
|
18
|
+
self.local_logger = local_logger
|
|
19
|
+
|
|
20
|
+
def _accept(self, log_obj: Log, log_json: dict):
|
|
21
|
+
self.db_logger._accept(log_obj, log_json)
|
|
22
|
+
self.local_logger._accept(log_obj, log_json)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import textwrap
|
|
3
|
+
|
|
4
|
+
from ...defaults import DEFAULT_ACTIVITY_LOG_COLLECTION
|
|
5
|
+
from ...defaults import DEFAULT_ACTIVITY_SCOPE
|
|
6
|
+
from .base import BaseLogger
|
|
7
|
+
from agentc_core.activity.models.log import Log
|
|
8
|
+
from agentc_core.config import RemoteCatalogConfig
|
|
9
|
+
from agentc_core.remote.util.ddl import check_if_scope_collection_exist
|
|
10
|
+
from agentc_core.version import VersionDescriptor
|
|
11
|
+
|
|
12
|
+
logger = logging.getLogger(__name__)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class DBLogger(BaseLogger):
|
|
16
|
+
def __init__(self, cfg: RemoteCatalogConfig, catalog_version: VersionDescriptor, **kwargs):
|
|
17
|
+
super().__init__(catalog_version=catalog_version, **kwargs)
|
|
18
|
+
|
|
19
|
+
# Get bucket ref
|
|
20
|
+
self.cluster = cfg.Cluster()
|
|
21
|
+
cb = self.cluster.bucket(cfg.bucket)
|
|
22
|
+
|
|
23
|
+
# Get the bucket manager
|
|
24
|
+
bucket_manager = cb.collections()
|
|
25
|
+
|
|
26
|
+
scope_collection_exist = check_if_scope_collection_exist(
|
|
27
|
+
bucket_manager, DEFAULT_ACTIVITY_SCOPE, DEFAULT_ACTIVITY_LOG_COLLECTION, False
|
|
28
|
+
)
|
|
29
|
+
if not scope_collection_exist:
|
|
30
|
+
raise ValueError(
|
|
31
|
+
textwrap.dedent(f"""
|
|
32
|
+
The collection {cfg.bucket}.{DEFAULT_ACTIVITY_SCOPE}.{DEFAULT_ACTIVITY_LOG_COLLECTION} does not exist.\n
|
|
33
|
+
Please use the 'agentc init' command to create this collection.\n
|
|
34
|
+
Execute 'agentc init --help' for more information.
|
|
35
|
+
""")
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
# get collection ref
|
|
39
|
+
cb_coll = cb.scope(DEFAULT_ACTIVITY_SCOPE).collection(DEFAULT_ACTIVITY_LOG_COLLECTION)
|
|
40
|
+
self.cb_coll = cb_coll
|
|
41
|
+
|
|
42
|
+
def _accept(self, log_obj: Log, log_json: dict):
|
|
43
|
+
self.cb_coll.insert(log_obj.identifier, log_json)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import agentc_core.defaults
|
|
2
|
+
import gzip
|
|
3
|
+
import json
|
|
4
|
+
import logging
|
|
5
|
+
import logging.handlers
|
|
6
|
+
import os
|
|
7
|
+
import shutil
|
|
8
|
+
|
|
9
|
+
from ...config import LocalCatalogConfig
|
|
10
|
+
from .base import BaseLogger
|
|
11
|
+
from agentc_core.activity.models.log import Log
|
|
12
|
+
from agentc_core.version import VersionDescriptor
|
|
13
|
+
|
|
14
|
+
logger = logging.getLogger(__name__)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class LocalLogger(BaseLogger):
|
|
18
|
+
# TODO (GLENN): Add rollover to our Config class.
|
|
19
|
+
def __init__(
|
|
20
|
+
self, cfg: LocalCatalogConfig, catalog_version: VersionDescriptor, rollover: int = 128_000_000, **kwargs
|
|
21
|
+
):
|
|
22
|
+
"""
|
|
23
|
+
:param output: Output file to write the audit logs to.
|
|
24
|
+
:param catalog_version: Catalog version associated with this audit instance.
|
|
25
|
+
:param rollover: Maximum size (bytes) of a log-file before rollover. Set this field to 0 to never rollover.
|
|
26
|
+
"""
|
|
27
|
+
super(LocalLogger, self).__init__(catalog_version=catalog_version, **kwargs)
|
|
28
|
+
self.audit_logger = logging.getLogger("AGENT_CATALOG_" + LocalLogger.__name__.upper())
|
|
29
|
+
self.audit_logger.setLevel(logging.INFO)
|
|
30
|
+
self.audit_logger.handlers.clear()
|
|
31
|
+
self.audit_logger.propagate = False
|
|
32
|
+
|
|
33
|
+
def compress_and_remove(source_log_file: str, dest_log_file: str):
|
|
34
|
+
with open(source_log_file, "rb") as input_fp, gzip.open(dest_log_file, "wb") as output_fp:
|
|
35
|
+
shutil.copyfileobj(input_fp, output_fp)
|
|
36
|
+
os.remove(source_log_file)
|
|
37
|
+
|
|
38
|
+
# We'll rotate log files and subsequently compress them when they get too large.
|
|
39
|
+
filename = cfg.ActivityPath() / agentc_core.defaults.DEFAULT_ACTIVITY_FILE
|
|
40
|
+
self.rotating_handler = logging.handlers.RotatingFileHandler(filename, maxBytes=rollover)
|
|
41
|
+
self.rotating_handler.rotator = compress_and_remove
|
|
42
|
+
self.rotating_handler.namer = lambda name: name + ".gz"
|
|
43
|
+
self.rotating_handler.setFormatter(logging.Formatter("%(message)s"))
|
|
44
|
+
self.audit_logger.addHandler(self.rotating_handler)
|
|
45
|
+
|
|
46
|
+
def _accept(self, log_obj: Log, log_json: dict):
|
|
47
|
+
self.audit_logger.info(json.dumps(log_json))
|
|
File without changes
|