swarmauri-core 0.5.0.dev1__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.
- swarmauri_core-0.5.0.dev1/PKG-INFO +26 -0
- swarmauri_core-0.5.0.dev1/setup.cfg +4 -0
- swarmauri_core-0.5.0.dev1/setup.py +27 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/ComponentBase.py +163 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/__init__.py +11 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/agent_apis/IAgentCommands.py +83 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/agent_apis/IAgentRouterCRUD.py +56 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/agent_apis/__init__.py +4 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/agent_factories/IAgentFactory.py +79 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/agent_factories/IExportConf.py +40 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/agent_factories/__init__.py +0 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/agents/IAgent.py +12 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/agents/IAgentConversation.py +5 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/agents/IAgentParser.py +14 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/agents/IAgentRetrieve.py +4 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/agents/IAgentSystemContext.py +4 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/agents/IAgentToolkit.py +4 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/agents/IAgentVectorStore.py +4 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/agents/__init__.py +0 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/chains/ICallableChain.py +15 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/chains/IChain.py +75 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/chains/IChainContext.py +11 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/chains/IChainContextLoader.py +8 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/chains/IChainDependencyResolver.py +32 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/chains/IChainFactory.py +61 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/chains/IChainStep.py +7 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/chains/__init__.py +1 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/chunkers/IChunker.py +15 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/chunkers/__init__.py +0 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/conversations/IConversation.py +45 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/conversations/IMaxSize.py +4 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/conversations/ISystemContext.py +4 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/conversations/__init__.py +0 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/distances/IDistanceSimilarity.py +49 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/distances/__init__.py +0 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/document_stores/IDocumentRetrieve.py +25 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/document_stores/IDocumentStore.py +79 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/document_stores/__init__.py +0 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/documents/IDocument.py +4 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/documents/IExperimentDocument.py +120 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/documents/__init__.py +0 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/embeddings/IFeature.py +9 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/embeddings/ISaveModel.py +30 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/embeddings/IVectorize.py +26 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/embeddings/__init__.py +1 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/experiment_stores/IExperimentStore.py +72 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/experiment_stores/__init__.py +99 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/llms/IFit.py +13 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/llms/IPredict.py +13 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/llms/__init__.py +0 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/messages/IMessage.py +10 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/messages/__init__.py +1 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/metrics/IMetric.py +19 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/metrics/IMetricAggregate.py +16 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/metrics/IMetricCalculate.py +30 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/metrics/IThreshold.py +4 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/metrics/__init__.py +0 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/parsers/IParser.py +19 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/parsers/__init__.py +0 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/prompts/IPrompt.py +18 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/prompts/IPromptMatrix.py +30 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/prompts/ITemplate.py +46 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/prompts/__init__.py +0 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/schema_converters/ISchemaConvert.py +9 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/schema_converters/__init__.py +0 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/swarm_apis/IAgentRegistrationAPI.py +72 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/swarm_apis/ISwarmAPI.py +24 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/swarm_apis/__init__.py +0 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/swarms/ISwarm.py +67 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/swarms/ISwarmAgentRegistration.py +73 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/swarms/ISwarmChainCRUD.py +62 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/swarms/ISwarmComponent.py +13 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/swarms/ISwarmConfigurationExporter.py +33 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/swarms/ISwarmFactory.py +120 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/swarms/__init__.py +0 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/toolkits/IToolkit.py +44 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/toolkits/__init__.py +0 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/tools/IParameter.py +9 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/tools/ITool.py +12 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/tools/__init__.py +0 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/tracing/IChainTracer.py +25 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/tracing/ITraceContext.py +29 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/tracing/ITracer.py +45 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/tracing/__init__.py +0 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/typing.py +26 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/utils/ITransactional.py +24 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/utils/__init__.py +0 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/vector_stores/IAngleBetweenVectors.py +23 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/vector_stores/ICloudVectorStore.py +21 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/vector_stores/IDecompose.py +24 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/vector_stores/IDivergence.py +21 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/vector_stores/IGradient.py +22 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/vector_stores/IOrthogonalProject.py +21 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/vector_stores/IPersistentVectorStore.py +21 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/vector_stores/IProject.py +22 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/vector_stores/IReflect.py +21 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/vector_stores/ISimilarity.py +26 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/vector_stores/ISimiliarityQuery.py +19 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/vector_stores/IVectorArithmetic.py +31 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/vector_stores/IVectorBasisCheck.py +20 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/vector_stores/IVectorLinearCombination.py +21 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/vector_stores/IVectorNorm.py +49 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/vector_stores/IVectorRotate.py +24 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/vector_stores/IVectorSpan.py +21 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/vector_stores/IVectorStore.py +88 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/vector_stores/IVectorStoreRetrieve.py +26 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/vector_stores/IVectorStoreSaveLoad.py +45 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/vector_stores/__init__.py +0 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/vectors/IVector.py +10 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/vectors/IVectorMeta.py +28 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/vectors/IVectorProduct.py +66 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/vectors/IVectorTransform.py +49 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core/vectors/__init__.py +0 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core.egg-info/PKG-INFO +26 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core.egg-info/SOURCES.txt +116 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core.egg-info/dependency_links.txt +1 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core.egg-info/requires.txt +3 -0
- swarmauri_core-0.5.0.dev1/swarmauri_core.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: swarmauri_core
|
|
3
|
+
Version: 0.5.0.dev1
|
|
4
|
+
Summary: This repository includes core interfaces, standard ABCs and concrete references, third party plugins, and experimental modules for the swarmaURI framework.
|
|
5
|
+
Home-page: http://github.com/swarmauri/swarmauri-sdk
|
|
6
|
+
Author: Jacob Stewart
|
|
7
|
+
Author-email: corporate@swarmauri.com
|
|
8
|
+
License: Apache Software License
|
|
9
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
Requires-Dist: numpy
|
|
15
|
+
Requires-Dist: requests
|
|
16
|
+
Requires-Dist: pydantic
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# Swarmauri Core
|
|
20
|
+
|
|
21
|
+
## Core
|
|
22
|
+
- **Core Interfaces**: Define the fundamental communication and data-sharing protocols between components in a Swarmauri-based system.
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
Visit us at: https://swarmauri.com
|
|
26
|
+
Follow us at: https://github.com/swarmauri
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
import swarmauri_core
|
|
3
|
+
|
|
4
|
+
setup(
|
|
5
|
+
name='swarmauri_core',
|
|
6
|
+
version=swarmauri_core.__version__,
|
|
7
|
+
author='Jacob Stewart',
|
|
8
|
+
author_email='corporate@swarmauri.com',
|
|
9
|
+
description='This repository includes core interfaces, standard ABCs and concrete references, third party plugins, and experimental modules for the swarmaURI framework.',
|
|
10
|
+
long_description=swarmauri_core.__long_desc__,
|
|
11
|
+
long_description_content_type='text/markdown',
|
|
12
|
+
url='http://github.com/swarmauri/swarmauri-sdk',
|
|
13
|
+
license='Apache Software License',
|
|
14
|
+
packages=find_packages(include=['swarmauri_core*']), # Include packages in your_package and libs directories
|
|
15
|
+
install_requires=[
|
|
16
|
+
'numpy',
|
|
17
|
+
'requests',
|
|
18
|
+
'pydantic'
|
|
19
|
+
],
|
|
20
|
+
classifiers=[
|
|
21
|
+
'License :: OSI Approved :: Apache Software License',
|
|
22
|
+
'Programming Language :: Python :: 3.10',
|
|
23
|
+
'Programming Language :: Python :: 3.11'
|
|
24
|
+
],
|
|
25
|
+
python_requires='>=3.10',
|
|
26
|
+
setup_requires=["wheel"]
|
|
27
|
+
)
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
from typing import (
|
|
2
|
+
Optional,
|
|
3
|
+
List,
|
|
4
|
+
Literal,
|
|
5
|
+
TypeVar,
|
|
6
|
+
Type,
|
|
7
|
+
Union,
|
|
8
|
+
Annotated,
|
|
9
|
+
Generic,
|
|
10
|
+
ClassVar,
|
|
11
|
+
Set,
|
|
12
|
+
get_args)
|
|
13
|
+
|
|
14
|
+
from uuid import uuid4
|
|
15
|
+
from enum import Enum
|
|
16
|
+
import inspect
|
|
17
|
+
import hashlib
|
|
18
|
+
from pydantic import BaseModel, Field, field_validator
|
|
19
|
+
import logging
|
|
20
|
+
from swarmauri.core.typing import SubclassUnion
|
|
21
|
+
|
|
22
|
+
class ResourceTypes(Enum):
|
|
23
|
+
UNIVERSAL_BASE = 'ComponentBase'
|
|
24
|
+
AGENT = 'Agent'
|
|
25
|
+
AGENT_FACTORY = 'AgentFactory'
|
|
26
|
+
CHAIN = 'Chain'
|
|
27
|
+
CHAIN_METHOD = 'ChainMethod'
|
|
28
|
+
CHUNKER = 'Chunker'
|
|
29
|
+
CONVERSATION = 'Conversation'
|
|
30
|
+
DISTANCE = 'Distance'
|
|
31
|
+
DOCUMENT_STORE = 'DocumentStore'
|
|
32
|
+
DOCUMENT = 'Document'
|
|
33
|
+
EMBEDDING = 'Embedding'
|
|
34
|
+
EXCEPTION = 'Exception'
|
|
35
|
+
LLM = 'LLM'
|
|
36
|
+
MESSAGE = 'Message'
|
|
37
|
+
METRIC = 'Metric'
|
|
38
|
+
PARSER = 'Parser'
|
|
39
|
+
PROMPT = 'Prompt'
|
|
40
|
+
STATE = 'State'
|
|
41
|
+
CHAINSTEP = 'ChainStep'
|
|
42
|
+
SCHEMA_CONVERTER = 'SchemaConverter'
|
|
43
|
+
SWARM = 'Swarm'
|
|
44
|
+
TOOLKIT = 'Toolkit'
|
|
45
|
+
TOOL = 'Tool'
|
|
46
|
+
PARAMETER = 'Parameter'
|
|
47
|
+
TRACE = 'Trace'
|
|
48
|
+
UTIL = 'Util'
|
|
49
|
+
VECTOR_STORE = 'VectorStore'
|
|
50
|
+
VECTOR = 'Vector'
|
|
51
|
+
|
|
52
|
+
def generate_id() -> str:
|
|
53
|
+
return str(uuid4())
|
|
54
|
+
|
|
55
|
+
class ComponentBase(BaseModel):
|
|
56
|
+
name: Optional[str] = None
|
|
57
|
+
id: str = Field(default_factory=generate_id)
|
|
58
|
+
members: List[str] = Field(default_factory=list)
|
|
59
|
+
owner: Optional[str] = None
|
|
60
|
+
host: Optional[str] = None
|
|
61
|
+
resource: str = Field(default="ComponentBase")
|
|
62
|
+
version: str = "0.1.0"
|
|
63
|
+
__swm_subclasses__: ClassVar[Set[Type['ComponentBase']]] = set()
|
|
64
|
+
type: Literal['ComponentBase'] = 'ComponentBase'
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def __init_subclass__(cls, **kwargs):
|
|
68
|
+
super().__init_subclass__(**kwargs)
|
|
69
|
+
ComponentBase.__swm_register_subclass__(cls)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@classmethod
|
|
73
|
+
def __swm_register_subclass__(cls, subclass) -> None:
|
|
74
|
+
logging.debug('__swm_register_subclass__ executed\n')
|
|
75
|
+
|
|
76
|
+
if 'type' in subclass.__annotations__:
|
|
77
|
+
sub_type = subclass.__annotations__['type']
|
|
78
|
+
if sub_type not in [subclass.__annotations__['type'] for subclass in cls.__swm_subclasses__]:
|
|
79
|
+
cls.__swm_subclasses__.add(subclass)
|
|
80
|
+
else:
|
|
81
|
+
logging.warning(f'Subclass {subclass.__name__} does not have a type annotation')
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
# [subclass.__swm_reset_class__() for subclass in cls.__swm_subclasses__
|
|
85
|
+
# if hasattr(subclass, '__swm_reset_class__')]
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
@classmethod
|
|
89
|
+
def __swm_reset_class__(cls):
|
|
90
|
+
logging.debug('__swm_reset_class__ executed\n')
|
|
91
|
+
for each in cls.__fields__:
|
|
92
|
+
logging.debug(each, cls.__fields__[each].discriminator)
|
|
93
|
+
if (cls.__fields__[each].discriminator and each in cls.__annotations__
|
|
94
|
+
):
|
|
95
|
+
if len(get_args(cls.__fields__[each].annotation)) > 0:
|
|
96
|
+
for x in range(0, len(get_args(cls.__fields__[each].annotation))):
|
|
97
|
+
if hasattr(get_args(cls.__fields__[each].annotation)[x], '__base__'):
|
|
98
|
+
if (hasattr(get_args(cls.__fields__[each].annotation)[x].__base__, '__swm_subclasses__') and
|
|
99
|
+
not get_args(cls.__fields__[each].annotation)[x].__base__.__name__ == 'ComponentBase'):
|
|
100
|
+
|
|
101
|
+
baseclass = get_args(cls.__fields__[each].annotation)[x].__base__
|
|
102
|
+
|
|
103
|
+
sc = SubclassUnion[baseclass]
|
|
104
|
+
|
|
105
|
+
cls.__annotations__[each] = sc
|
|
106
|
+
cls.__fields__[each].annotation = sc
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
# This is not necessary as the model_rebuild address forward_refs
|
|
110
|
+
# https://docs.pydantic.dev/latest/api/base_model/#pydantic.BaseModel.model_post_init
|
|
111
|
+
# cls.update_forward_refs()
|
|
112
|
+
cls.model_rebuild(force=True)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
@field_validator('type')
|
|
116
|
+
def set_type(cls, v, values):
|
|
117
|
+
if v == 'ComponentBase' and cls.__name__ != 'ComponentBase':
|
|
118
|
+
return cls.__name__
|
|
119
|
+
return v
|
|
120
|
+
|
|
121
|
+
def __swm_class_hash__(self):
|
|
122
|
+
sig_hash = hashlib.sha256()
|
|
123
|
+
for attr_name in dir(self):
|
|
124
|
+
attr_value = getattr(self, attr_name)
|
|
125
|
+
if callable(attr_value) and not attr_name.startswith("_"):
|
|
126
|
+
sig = inspect.signature(attr_value)
|
|
127
|
+
sig_hash.update(str(sig).encode())
|
|
128
|
+
return sig_hash.hexdigest()
|
|
129
|
+
|
|
130
|
+
@classmethod
|
|
131
|
+
def swm_public_interfaces(cls):
|
|
132
|
+
methods = []
|
|
133
|
+
for attr_name in dir(cls):
|
|
134
|
+
attr_value = getattr(cls, attr_name)
|
|
135
|
+
if (callable(attr_value) and not attr_name.startswith("_")) or isinstance(attr_value, property):
|
|
136
|
+
methods.append(attr_name)
|
|
137
|
+
return methods
|
|
138
|
+
|
|
139
|
+
@classmethod
|
|
140
|
+
def swm_ismethod_registered(cls, method_name: str):
|
|
141
|
+
return method_name in cls.public_interfaces()
|
|
142
|
+
|
|
143
|
+
@classmethod
|
|
144
|
+
def swm_method_signature(cls, input_signature):
|
|
145
|
+
for method_name in cls.public_interfaces():
|
|
146
|
+
method = getattr(cls, method_name)
|
|
147
|
+
if callable(method):
|
|
148
|
+
sig = str(inspect.signature(method))
|
|
149
|
+
if sig == input_signature:
|
|
150
|
+
return True
|
|
151
|
+
return False
|
|
152
|
+
|
|
153
|
+
@property
|
|
154
|
+
def swm_path(self):
|
|
155
|
+
if self.host and self.owner:
|
|
156
|
+
return f"{self.host}/{self.owner}/{self.resource}/{self.name}/{self.id}"
|
|
157
|
+
if self.resource and self.name:
|
|
158
|
+
return f"/{self.resource}/{self.name}/{self.id}"
|
|
159
|
+
return f"/{self.resource}/{self.id}"
|
|
160
|
+
|
|
161
|
+
@property
|
|
162
|
+
def swm_isremote(self):
|
|
163
|
+
return bool(self.host)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
__version__ = "0.5.0.dev1"
|
|
2
|
+
__long_desc__ = """
|
|
3
|
+
# Swarmauri Core
|
|
4
|
+
|
|
5
|
+
## Core
|
|
6
|
+
- **Core Interfaces**: Define the fundamental communication and data-sharing protocols between components in a Swarmauri-based system.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
Visit us at: https://swarmauri.com
|
|
10
|
+
Follow us at: https://github.com/swarmauri
|
|
11
|
+
"""
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from typing import Callable, Any, List
|
|
3
|
+
|
|
4
|
+
class IAgentCommands(ABC):
|
|
5
|
+
"""
|
|
6
|
+
Interface for the API object that enables a SwarmAgent to host various API routes.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@abstractmethod
|
|
11
|
+
def invoke(self, request: Any) -> Any:
|
|
12
|
+
"""
|
|
13
|
+
Handles invocation requests synchronously.
|
|
14
|
+
|
|
15
|
+
Parameters:
|
|
16
|
+
request (Any): The incoming request payload.
|
|
17
|
+
|
|
18
|
+
Returns:
|
|
19
|
+
Any: The response payload.
|
|
20
|
+
"""
|
|
21
|
+
pass
|
|
22
|
+
|
|
23
|
+
@abstractmethod
|
|
24
|
+
async def ainvoke(self, request: Any) -> Any:
|
|
25
|
+
"""
|
|
26
|
+
Handles invocation requests asynchronously.
|
|
27
|
+
|
|
28
|
+
Parameters:
|
|
29
|
+
request (Any): The incoming request payload.
|
|
30
|
+
|
|
31
|
+
Returns:
|
|
32
|
+
Any: The response payload.
|
|
33
|
+
"""
|
|
34
|
+
pass
|
|
35
|
+
|
|
36
|
+
@abstractmethod
|
|
37
|
+
def batch(self, requests: List[Any]) -> List[Any]:
|
|
38
|
+
"""
|
|
39
|
+
Handles batched invocation requests synchronously.
|
|
40
|
+
|
|
41
|
+
Parameters:
|
|
42
|
+
requests (List[Any]): A list of incoming request payloads.
|
|
43
|
+
|
|
44
|
+
Returns:
|
|
45
|
+
List[Any]: A list of responses.
|
|
46
|
+
"""
|
|
47
|
+
pass
|
|
48
|
+
|
|
49
|
+
@abstractmethod
|
|
50
|
+
async def abatch(self, requests: List[Any]) -> List[Any]:
|
|
51
|
+
"""
|
|
52
|
+
Handles batched invocation requests asynchronously.
|
|
53
|
+
|
|
54
|
+
Parameters:
|
|
55
|
+
requests (List[Any]): A list of incoming request payloads.
|
|
56
|
+
|
|
57
|
+
Returns:
|
|
58
|
+
List[Any]: A list of responses.
|
|
59
|
+
"""
|
|
60
|
+
pass
|
|
61
|
+
|
|
62
|
+
@abstractmethod
|
|
63
|
+
def stream(self, request: Any) -> Any:
|
|
64
|
+
"""
|
|
65
|
+
Handles streaming requests.
|
|
66
|
+
|
|
67
|
+
Parameters:
|
|
68
|
+
request (Any): The incoming request payload.
|
|
69
|
+
|
|
70
|
+
Returns:
|
|
71
|
+
Any: A streaming response.
|
|
72
|
+
"""
|
|
73
|
+
pass
|
|
74
|
+
|
|
75
|
+
@abstractmethod
|
|
76
|
+
def get_schema_config(self) -> dict:
|
|
77
|
+
"""
|
|
78
|
+
Retrieves the schema configuration for the API.
|
|
79
|
+
|
|
80
|
+
Returns:
|
|
81
|
+
dict: The schema configuration.
|
|
82
|
+
"""
|
|
83
|
+
pass
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from typing import Callable, Any, Dict
|
|
3
|
+
|
|
4
|
+
class IAgentRouterCRUD(ABC):
|
|
5
|
+
"""
|
|
6
|
+
Interface for managing API routes within a SwarmAgent.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
@abstractmethod
|
|
10
|
+
def create_route(self, path: str, method: str, handler: Callable[[Any], Any]) -> None:
|
|
11
|
+
"""
|
|
12
|
+
Create a new route for the API.
|
|
13
|
+
|
|
14
|
+
Parameters:
|
|
15
|
+
- path (str): The URL path for the route.
|
|
16
|
+
- method (str): The HTTP method (e.g., 'GET', 'POST').
|
|
17
|
+
- handler (Callable[[Any], Any]): The function that handles requests to this route.
|
|
18
|
+
"""
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
@abstractmethod
|
|
22
|
+
def read_route(self, path: str, method: str) -> Dict:
|
|
23
|
+
"""
|
|
24
|
+
Retrieve information about a specific route.
|
|
25
|
+
|
|
26
|
+
Parameters:
|
|
27
|
+
- path (str): The URL path for the route.
|
|
28
|
+
- method (str): The HTTP method.
|
|
29
|
+
|
|
30
|
+
Returns:
|
|
31
|
+
- Dict: Information about the route, including path, method, and handler.
|
|
32
|
+
"""
|
|
33
|
+
pass
|
|
34
|
+
|
|
35
|
+
@abstractmethod
|
|
36
|
+
def update_route(self, path: str, method: str, new_handler: Callable[[Any], Any]) -> None:
|
|
37
|
+
"""
|
|
38
|
+
Update the handler function for an existing route.
|
|
39
|
+
|
|
40
|
+
Parameters:
|
|
41
|
+
- path (str): The URL path for the route.
|
|
42
|
+
- method (str): The HTTP method.
|
|
43
|
+
- new_handler (Callable[[Any], Any]): The new function that handles requests to this route.
|
|
44
|
+
"""
|
|
45
|
+
pass
|
|
46
|
+
|
|
47
|
+
@abstractmethod
|
|
48
|
+
def delete_route(self, path: str, method: str) -> None:
|
|
49
|
+
"""
|
|
50
|
+
Delete a specific route from the API.
|
|
51
|
+
|
|
52
|
+
Parameters:
|
|
53
|
+
- path (str): The URL path for the route.
|
|
54
|
+
- method (str): The HTTP method.
|
|
55
|
+
"""
|
|
56
|
+
pass
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from typing import Type, Any
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
|
|
5
|
+
class IAgentFactory(ABC):
|
|
6
|
+
"""
|
|
7
|
+
Interface for Agent Factories, extended to include properties like ID, name, type,
|
|
8
|
+
creation date, and last modification date.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
@abstractmethod
|
|
12
|
+
def create_agent(self, agent_type: str, **kwargs) -> Any:
|
|
13
|
+
pass
|
|
14
|
+
|
|
15
|
+
@abstractmethod
|
|
16
|
+
def register_agent(self, agent_type: str, constructor: Type[Any]) -> None:
|
|
17
|
+
pass
|
|
18
|
+
|
|
19
|
+
# Abstract properties and setters
|
|
20
|
+
@property
|
|
21
|
+
@abstractmethod
|
|
22
|
+
def id(self) -> str:
|
|
23
|
+
"""Unique identifier for the factory instance."""
|
|
24
|
+
pass
|
|
25
|
+
|
|
26
|
+
@id.setter
|
|
27
|
+
@abstractmethod
|
|
28
|
+
def id(self, value: str) -> None:
|
|
29
|
+
pass
|
|
30
|
+
|
|
31
|
+
@property
|
|
32
|
+
@abstractmethod
|
|
33
|
+
def name(self) -> str:
|
|
34
|
+
"""Name of the factory."""
|
|
35
|
+
pass
|
|
36
|
+
|
|
37
|
+
@name.setter
|
|
38
|
+
@abstractmethod
|
|
39
|
+
def name(self, value: str) -> None:
|
|
40
|
+
pass
|
|
41
|
+
|
|
42
|
+
@property
|
|
43
|
+
@abstractmethod
|
|
44
|
+
def type(self) -> str:
|
|
45
|
+
"""Type of agents this factory produces."""
|
|
46
|
+
pass
|
|
47
|
+
|
|
48
|
+
@type.setter
|
|
49
|
+
@abstractmethod
|
|
50
|
+
def type(self, value: str) -> None:
|
|
51
|
+
pass
|
|
52
|
+
|
|
53
|
+
@property
|
|
54
|
+
@abstractmethod
|
|
55
|
+
def date_created(self) -> datetime:
|
|
56
|
+
"""The creation date of the factory instance."""
|
|
57
|
+
pass
|
|
58
|
+
|
|
59
|
+
@property
|
|
60
|
+
@abstractmethod
|
|
61
|
+
def last_modified(self) -> datetime:
|
|
62
|
+
"""Date when the factory was last modified."""
|
|
63
|
+
pass
|
|
64
|
+
|
|
65
|
+
@last_modified.setter
|
|
66
|
+
@abstractmethod
|
|
67
|
+
def last_modified(self, value: datetime) -> None:
|
|
68
|
+
pass
|
|
69
|
+
|
|
70
|
+
def __hash__(self):
|
|
71
|
+
"""
|
|
72
|
+
The __hash__ method allows objects of this class to be used in sets and as dictionary keys.
|
|
73
|
+
__hash__ should return an integer and be defined based on immutable properties.
|
|
74
|
+
This is generally implemented directly in concrete classes rather than in the interface,
|
|
75
|
+
but it's declared here to indicate that implementing classes must provide it.
|
|
76
|
+
"""
|
|
77
|
+
pass
|
|
78
|
+
|
|
79
|
+
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from typing import Any, Dict
|
|
3
|
+
|
|
4
|
+
class IExportConf(ABC):
|
|
5
|
+
"""
|
|
6
|
+
Interface for exporting configurations related to agent factories.
|
|
7
|
+
|
|
8
|
+
Implementing classes are expected to provide functionality for representing
|
|
9
|
+
the factory's configuration as a dictionary, JSON string, or exporting to a file.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
@abstractmethod
|
|
13
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
14
|
+
"""
|
|
15
|
+
Serializes the agent factory's configuration to a dictionary.
|
|
16
|
+
|
|
17
|
+
Returns:
|
|
18
|
+
Dict[str, Any]: A dictionary representation of the factory's configuration.
|
|
19
|
+
"""
|
|
20
|
+
pass
|
|
21
|
+
|
|
22
|
+
@abstractmethod
|
|
23
|
+
def to_json(self) -> str:
|
|
24
|
+
"""
|
|
25
|
+
Serializes the agent factory's configuration to a JSON string.
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
str: A JSON string representation of the factory's configuration.
|
|
29
|
+
"""
|
|
30
|
+
pass
|
|
31
|
+
|
|
32
|
+
@abstractmethod
|
|
33
|
+
def to_file(self, file_path: str) -> None:
|
|
34
|
+
"""
|
|
35
|
+
Exports the agent factory's configuration to a file in a suitable format.
|
|
36
|
+
|
|
37
|
+
Parameters:
|
|
38
|
+
file_path (str): The path to the file where the configuration should be saved.
|
|
39
|
+
"""
|
|
40
|
+
pass
|
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from typing import Any, Optional, Dict
|
|
3
|
+
|
|
4
|
+
class IAgent(ABC):
|
|
5
|
+
|
|
6
|
+
@abstractmethod
|
|
7
|
+
def exec(self, input_data: Optional[Any], llm_kwargs: Optional[Dict]) -> Any:
|
|
8
|
+
"""
|
|
9
|
+
Executive method that triggers the agent's action based on the input data.
|
|
10
|
+
"""
|
|
11
|
+
pass
|
|
12
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from swarmauri.core.parsers.IParser import IParser
|
|
3
|
+
|
|
4
|
+
class IAgentParser(ABC):
|
|
5
|
+
|
|
6
|
+
@property
|
|
7
|
+
@abstractmethod
|
|
8
|
+
def parser(self) -> IParser:
|
|
9
|
+
pass
|
|
10
|
+
|
|
11
|
+
@parser.setter
|
|
12
|
+
@abstractmethod
|
|
13
|
+
def parser(self) -> IParser:
|
|
14
|
+
pass
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from typing import Any, Callable, List, Tuple
|
|
3
|
+
|
|
4
|
+
CallableDefinition = Tuple[Callable, List[Any], dict]
|
|
5
|
+
|
|
6
|
+
class ICallableChain(ABC):
|
|
7
|
+
@abstractmethod
|
|
8
|
+
def __call__(self, *initial_args: Any, **initial_kwargs: Any) -> Any:
|
|
9
|
+
"""Executes the chain of callables."""
|
|
10
|
+
pass
|
|
11
|
+
|
|
12
|
+
@abstractmethod
|
|
13
|
+
def add_callable(self, func: Callable, args: List[Any] = None, kwargs: dict = None) -> None:
|
|
14
|
+
"""Adds a new callable to the chain."""
|
|
15
|
+
pass
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from typing import List, Any, Dict
|
|
3
|
+
from swarmauri.core.chains.IChainStep import IChainStep
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class IChain(ABC):
|
|
7
|
+
"""
|
|
8
|
+
Defines the interface for a Chain within a system, facilitating the organized
|
|
9
|
+
execution of a sequence of tasks or operations. This interface is at the core of
|
|
10
|
+
orchestrating operations that require coordination between multiple steps, potentially
|
|
11
|
+
involving decision-making, branching, and conditional execution based on the outcomes
|
|
12
|
+
of previous steps or external data.
|
|
13
|
+
|
|
14
|
+
A chain can be thought of as a workflow or pipeline, where each step in the chain can
|
|
15
|
+
perform an operation, transform data, or make decisions that influence the flow of
|
|
16
|
+
execution.
|
|
17
|
+
|
|
18
|
+
Implementors of this interface are responsible for managing the execution order,
|
|
19
|
+
data flow between steps, and any dynamic adjustments to the execution based on
|
|
20
|
+
runtime conditions.
|
|
21
|
+
|
|
22
|
+
Methods:
|
|
23
|
+
add_step: Adds a step to the chain.
|
|
24
|
+
remove_step: Removes a step from the chain.
|
|
25
|
+
execute: Executes the chain, potentially returning a result.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
@abstractmethod
|
|
29
|
+
def add_step(self, step: IChainStep, **kwargs) -> None:
|
|
30
|
+
"""
|
|
31
|
+
Adds a new step to the chain. Steps are executed in the order they are added.
|
|
32
|
+
Each step is represented by a Callable, which can be a function or method, with
|
|
33
|
+
optional keyword arguments that specify execution aspects or data needed by the step.
|
|
34
|
+
|
|
35
|
+
Parameters:
|
|
36
|
+
step (IChainStep): The Callable representing the step to add to the chain.
|
|
37
|
+
**kwargs: Optional keyword arguments that provide additional data or configuration
|
|
38
|
+
for the step when it is executed.
|
|
39
|
+
"""
|
|
40
|
+
pass
|
|
41
|
+
|
|
42
|
+
@abstractmethod
|
|
43
|
+
def remove_step(self, step: IChainStep) -> None:
|
|
44
|
+
"""
|
|
45
|
+
Removes an existing step from the chain. This alters the chain's execution sequence
|
|
46
|
+
by excluding the specified step from subsequent executions of the chain.
|
|
47
|
+
|
|
48
|
+
Parameters:
|
|
49
|
+
step (IChainStep): The Callable representing the step to remove from the chain.
|
|
50
|
+
"""
|
|
51
|
+
pass
|
|
52
|
+
|
|
53
|
+
@abstractmethod
|
|
54
|
+
def execute(self, *args, **kwargs) -> Dict[str, Any]:
|
|
55
|
+
"""
|
|
56
|
+
Initiates the execution of the chain. This involves invoking each step in the order
|
|
57
|
+
they have been added to the chain, passing control from one step to the next, and optionally
|
|
58
|
+
aggregating or transforming results along the way.
|
|
59
|
+
|
|
60
|
+
The execution process can incorporate branching, looping, or conditional logic based on the
|
|
61
|
+
implementation, allowing for complex workflows to be represented and managed within the chain.
|
|
62
|
+
|
|
63
|
+
Parameters:
|
|
64
|
+
*args: Positional arguments passed to the first step in the chain. These can be data inputs
|
|
65
|
+
or other values required for the chain's execution.
|
|
66
|
+
**kwargs: Keyword arguments that provide additional context, data inputs, or configuration
|
|
67
|
+
for the chain's execution. These can be passed to individual steps or influence
|
|
68
|
+
the execution flow of the chain.
|
|
69
|
+
|
|
70
|
+
Returns:
|
|
71
|
+
Any: The outcome of executing the chain. This could be a value produced by the final
|
|
72
|
+
step, a collection of outputs from multiple steps, or any other result type as
|
|
73
|
+
determined by the specific chain implementation.
|
|
74
|
+
"""
|
|
75
|
+
pass
|