btech-agent-lab 1.9.0__py3-none-any.whl

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.
Files changed (121) hide show
  1. agent_lab/__init__.py +52 -0
  2. agent_lab/app_factory.py +350 -0
  3. agent_lab/core/__init__.py +0 -0
  4. agent_lab/core/config.py +86 -0
  5. agent_lab/core/container.py +220 -0
  6. agent_lab/domain/__init__.py +0 -0
  7. agent_lab/domain/exceptions/__init__.py +0 -0
  8. agent_lab/domain/exceptions/base.py +54 -0
  9. agent_lab/domain/models.py +110 -0
  10. agent_lab/domain/repositories/__init__.py +0 -0
  11. agent_lab/domain/repositories/agents.py +152 -0
  12. agent_lab/domain/repositories/attachments.py +86 -0
  13. agent_lab/domain/repositories/integrations.py +72 -0
  14. agent_lab/domain/repositories/language_models.py +140 -0
  15. agent_lab/domain/repositories/messages.py +77 -0
  16. agent_lab/infrastructure/__init__.py +0 -0
  17. agent_lab/infrastructure/auth/__init__.py +0 -0
  18. agent_lab/infrastructure/auth/schema.py +7 -0
  19. agent_lab/infrastructure/auth/user.py +17 -0
  20. agent_lab/infrastructure/database/__init__.py +0 -0
  21. agent_lab/infrastructure/database/checkpoints.py +25 -0
  22. agent_lab/infrastructure/database/sql.py +52 -0
  23. agent_lab/infrastructure/database/vectors.py +42 -0
  24. agent_lab/infrastructure/metrics/__init__.py +0 -0
  25. agent_lab/infrastructure/metrics/logging_middleware.py +35 -0
  26. agent_lab/infrastructure/metrics/tracer.py +138 -0
  27. agent_lab/infrastructure/metrics/tracing.py +43 -0
  28. agent_lab/infrastructure/metrics/tracing_backends.py +126 -0
  29. agent_lab/interface/__init__.py +0 -0
  30. agent_lab/interface/api/__init__.py +0 -0
  31. agent_lab/interface/api/agents/__init__.py +0 -0
  32. agent_lab/interface/api/agents/endpoints.py +551 -0
  33. agent_lab/interface/api/agents/schema.py +100 -0
  34. agent_lab/interface/api/attachments/__init__.py +0 -0
  35. agent_lab/interface/api/attachments/endpoints.py +315 -0
  36. agent_lab/interface/api/attachments/schema.py +21 -0
  37. agent_lab/interface/api/auth/__init__.py +0 -0
  38. agent_lab/interface/api/auth/endpoints.py +210 -0
  39. agent_lab/interface/api/auth/schema.py +35 -0
  40. agent_lab/interface/api/cache_control.py +16 -0
  41. agent_lab/interface/api/integrations/__init__.py +0 -0
  42. agent_lab/interface/api/integrations/endpoints.py +243 -0
  43. agent_lab/interface/api/integrations/schema.py +44 -0
  44. agent_lab/interface/api/language_models/__init__.py +0 -0
  45. agent_lab/interface/api/language_models/endpoints.py +470 -0
  46. agent_lab/interface/api/language_models/schema.py +87 -0
  47. agent_lab/interface/api/messages/__init__.py +0 -0
  48. agent_lab/interface/api/messages/endpoints.py +367 -0
  49. agent_lab/interface/api/messages/schema.py +43 -0
  50. agent_lab/interface/api/status/__init__.py +0 -0
  51. agent_lab/interface/api/status/endpoints.py +56 -0
  52. agent_lab/interface/mcp/__init__.py +0 -0
  53. agent_lab/interface/mcp/coordinator_planner_supervisor_tool_registrar.py +96 -0
  54. agent_lab/interface/mcp/default_tool_registrar.py +204 -0
  55. agent_lab/interface/mcp/prompt_registry.py +36 -0
  56. agent_lab/interface/mcp/prompt_set_registrar.py +95 -0
  57. agent_lab/interface/mcp/registrar.py +32 -0
  58. agent_lab/interface/mcp/schema.py +61 -0
  59. agent_lab/interface/mcp/server.py +106 -0
  60. agent_lab/interface/mcp/user_prompt_resolver.py +59 -0
  61. agent_lab/main.py +11 -0
  62. agent_lab/services/__init__.py +0 -0
  63. agent_lab/services/agent_settings.py +35 -0
  64. agent_lab/services/agent_types/__init__.py +0 -0
  65. agent_lab/services/agent_types/adaptive_rag/__init__.py +0 -0
  66. agent_lab/services/agent_types/adaptive_rag/agent.py +395 -0
  67. agent_lab/services/agent_types/adaptive_rag/default_answer_grader_system_prompt.txt +9 -0
  68. agent_lab/services/agent_types/adaptive_rag/default_collection_name.txt +1 -0
  69. agent_lab/services/agent_types/adaptive_rag/default_execution_system_prompt.txt +9 -0
  70. agent_lab/services/agent_types/adaptive_rag/default_query_rewriter_system_prompt.txt +8 -0
  71. agent_lab/services/agent_types/adaptive_rag/default_retrieval_grader_system_prompt.txt +12 -0
  72. agent_lab/services/agent_types/adaptive_rag/schema.py +32 -0
  73. agent_lab/services/agent_types/azure.py +81 -0
  74. agent_lab/services/agent_types/base.py +767 -0
  75. agent_lab/services/agent_types/business/__init__.py +0 -0
  76. agent_lab/services/agent_types/business/voice_memos/__init__.py +72 -0
  77. agent_lab/services/agent_types/business/voice_memos/agent.py +599 -0
  78. agent_lab/services/agent_types/business/voice_memos/default_audio_language_model.txt +1 -0
  79. agent_lab/services/agent_types/business/voice_memos/default_content_analyst_system_prompt.txt +66 -0
  80. agent_lab/services/agent_types/business/voice_memos/default_coordinator_system_prompt.txt +55 -0
  81. agent_lab/services/agent_types/business/voice_memos/default_planner_system_prompt.txt +37 -0
  82. agent_lab/services/agent_types/business/voice_memos/default_reporter_system_prompt.txt +9 -0
  83. agent_lab/services/agent_types/business/voice_memos/default_supervisor_system_prompt.txt +19 -0
  84. agent_lab/services/agent_types/business/voice_memos/schema.py +26 -0
  85. agent_lab/services/agent_types/coordinator_planner_supervisor/__init__.py +44 -0
  86. agent_lab/services/agent_types/coordinator_planner_supervisor/agent.py +547 -0
  87. agent_lab/services/agent_types/coordinator_planner_supervisor/default_browser_system_prompt.txt +26 -0
  88. agent_lab/services/agent_types/coordinator_planner_supervisor/default_coder_system_prompt.txt +31 -0
  89. agent_lab/services/agent_types/coordinator_planner_supervisor/default_collection_name.txt +1 -0
  90. agent_lab/services/agent_types/coordinator_planner_supervisor/default_coordinator_system_prompt.txt +33 -0
  91. agent_lab/services/agent_types/coordinator_planner_supervisor/default_planner_system_prompt.txt +44 -0
  92. agent_lab/services/agent_types/coordinator_planner_supervisor/default_reporter_system_prompt.txt +57 -0
  93. agent_lab/services/agent_types/coordinator_planner_supervisor/default_researcher_system_prompt.txt +49 -0
  94. agent_lab/services/agent_types/coordinator_planner_supervisor/default_supervisor_system_prompt.txt +19 -0
  95. agent_lab/services/agent_types/coordinator_planner_supervisor/schema.py +22 -0
  96. agent_lab/services/agent_types/discovery.py +32 -0
  97. agent_lab/services/agent_types/react_rag/__init__.py +0 -0
  98. agent_lab/services/agent_types/react_rag/agent.py +119 -0
  99. agent_lab/services/agent_types/react_rag/default_collection_name.txt +1 -0
  100. agent_lab/services/agent_types/react_rag/default_execution_system_prompt.txt +24 -0
  101. agent_lab/services/agent_types/registration.py +59 -0
  102. agent_lab/services/agent_types/registry.py +44 -0
  103. agent_lab/services/agent_types/schema.py +13 -0
  104. agent_lab/services/agent_types/test_echo/__init__.py +0 -0
  105. agent_lab/services/agent_types/test_echo/test_echo_agent.py +46 -0
  106. agent_lab/services/agent_types/vision_document/__init__.py +0 -0
  107. agent_lab/services/agent_types/vision_document/agent.py +117 -0
  108. agent_lab/services/agent_types/vision_document/default_execution_system_prompt.txt +34 -0
  109. agent_lab/services/agents.py +75 -0
  110. agent_lab/services/attachments.py +176 -0
  111. agent_lab/services/auth.py +173 -0
  112. agent_lab/services/integrations.py +28 -0
  113. agent_lab/services/language_model_settings.py +38 -0
  114. agent_lab/services/language_models.py +93 -0
  115. agent_lab/services/messages.py +59 -0
  116. agent_lab/services/tasks.py +46 -0
  117. agent_lab/static/logo.svg +7 -0
  118. btech_agent_lab-1.9.0.dist-info/METADATA +200 -0
  119. btech_agent_lab-1.9.0.dist-info/RECORD +121 -0
  120. btech_agent_lab-1.9.0.dist-info/WHEEL +4 -0
  121. btech_agent_lab-1.9.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,220 @@
1
+ import hvac
2
+ from dependency_injector import containers, providers
3
+
4
+ from agent_lab.domain.repositories.agents import AgentRepository, AgentSettingRepository
5
+ from agent_lab.domain.repositories.attachments import AttachmentRepository
6
+ from agent_lab.domain.repositories.integrations import IntegrationRepository
7
+ from agent_lab.domain.repositories.language_models import (
8
+ LanguageModelRepository,
9
+ LanguageModelSettingRepository,
10
+ )
11
+ from agent_lab.domain.repositories.messages import MessageRepository
12
+ from agent_lab.infrastructure.database.checkpoints import GraphPersistenceFactory
13
+ from agent_lab.infrastructure.database.sql import Database
14
+ from agent_lab.infrastructure.database.vectors import DocumentRepository
15
+ from agent_lab.infrastructure.metrics.tracer import (
16
+ Tracer,
17
+ service_name,
18
+ service_version,
19
+ excluded_paths,
20
+ )
21
+ from agent_lab.infrastructure.metrics.tracing_backends import (
22
+ LangfuseTracingBackend,
23
+ LangWatchTracingBackend,
24
+ )
25
+ from agent_lab.interface.mcp.coordinator_planner_supervisor_tool_registrar import (
26
+ CoordinatorPlannerSupervisorToolRegistrar,
27
+ )
28
+ from agent_lab.interface.mcp.default_tool_registrar import DefaultToolRegistrar
29
+ from agent_lab.interface.mcp.prompt_registry import PromptRegistry
30
+ from agent_lab.interface.mcp.user_prompt_resolver import UserPromptResolver
31
+ from agent_lab.services.agent_settings import AgentSettingService
32
+ from agent_lab.services.agent_types.base import AgentUtils
33
+ from agent_lab.services.agent_types.registry import AgentRegistry
34
+ from agent_lab.services.agents import AgentService
35
+ from agent_lab.services.attachments import AttachmentService
36
+ from agent_lab.services.auth import AuthService
37
+ from agent_lab.services.integrations import IntegrationService
38
+ from agent_lab.services.language_model_settings import LanguageModelSettingService
39
+ from agent_lab.services.language_models import LanguageModelService
40
+ from agent_lab.services.messages import MessageService
41
+ from agent_lab.services.tasks import TaskNotificationService
42
+
43
+
44
+ class Container(containers.DeclarativeContainer):
45
+ wiring_config = containers.WiringConfiguration(
46
+ modules=[
47
+ "agent_lab.interface.api.agents.endpoints",
48
+ "agent_lab.interface.api.attachments.endpoints",
49
+ "agent_lab.interface.api.auth.endpoints",
50
+ "agent_lab.interface.api.integrations.endpoints",
51
+ "agent_lab.interface.api.language_models.endpoints",
52
+ "agent_lab.interface.api.messages.endpoints",
53
+ ]
54
+ )
55
+
56
+ # Populated at bootstrap by create_app() via load_config(); declaring the
57
+ # container performs no I/O so the library is import-safe.
58
+ config = providers.Configuration()
59
+
60
+ db = providers.Singleton(Database, db_url=config.db.url)
61
+
62
+ graph_persistence_factory = providers.Singleton(
63
+ GraphPersistenceFactory, db_checkpoints=config.db.checkpoints
64
+ )
65
+
66
+ vault_client = providers.Singleton(
67
+ hvac.Client, url=config.vault.url, token=config.vault.token, verify=False
68
+ )
69
+
70
+ document_repository = providers.Factory(
71
+ DocumentRepository, db_url=config.db.vectors
72
+ )
73
+
74
+ auth_service = providers.Factory(
75
+ AuthService,
76
+ enabled=config.auth.enabled,
77
+ url=config.auth.url,
78
+ realm=config.auth.realm,
79
+ client_id=config.auth.client_id,
80
+ client_secret=config.auth.client_secret,
81
+ )
82
+
83
+ integration_repository = providers.Factory(
84
+ IntegrationRepository,
85
+ db=db,
86
+ vault_client=vault_client,
87
+ )
88
+
89
+ integration_service = providers.Factory(
90
+ IntegrationService,
91
+ integration_repository=integration_repository,
92
+ )
93
+
94
+ task_notification_service = providers.Factory(
95
+ TaskNotificationService,
96
+ redis_url=config.broker.url,
97
+ )
98
+
99
+ language_model_setting_repository = providers.Factory(
100
+ LanguageModelSettingRepository,
101
+ db=db,
102
+ )
103
+
104
+ language_model_setting_service = providers.Factory(
105
+ LanguageModelSettingService,
106
+ language_model_setting_repository=language_model_setting_repository,
107
+ )
108
+
109
+ language_model_repository = providers.Factory(LanguageModelRepository, db=db)
110
+
111
+ language_model_service = providers.Factory(
112
+ LanguageModelService,
113
+ language_model_repository=language_model_repository,
114
+ language_model_setting_service=language_model_setting_service,
115
+ integration_service=integration_service,
116
+ )
117
+
118
+ attachment_repository = providers.Factory(AttachmentRepository, db=db)
119
+
120
+ attachment_service = providers.Factory(
121
+ AttachmentService,
122
+ attachment_repository=attachment_repository,
123
+ document_repository=document_repository,
124
+ language_model_service=language_model_service,
125
+ language_model_setting_service=language_model_setting_service,
126
+ integration_service=integration_service,
127
+ vault_client=vault_client,
128
+ )
129
+
130
+ agent_setting_repository = providers.Factory(AgentSettingRepository, db=db)
131
+
132
+ agent_setting_service = providers.Factory(
133
+ AgentSettingService,
134
+ agent_setting_repository=agent_setting_repository,
135
+ )
136
+
137
+ agent_repository = providers.Factory(AgentRepository, db=db)
138
+
139
+ agent_service = providers.Factory(
140
+ AgentService,
141
+ agent_repository=agent_repository,
142
+ agent_setting_service=agent_setting_service,
143
+ language_model_service=language_model_service,
144
+ )
145
+
146
+ message_repository = providers.Factory(MessageRepository, db=db)
147
+
148
+ message_service = providers.Factory(
149
+ MessageService,
150
+ message_repository=message_repository,
151
+ agent_service=agent_service,
152
+ attachment_service=attachment_service,
153
+ )
154
+
155
+ agent_utils = providers.Factory(
156
+ AgentUtils,
157
+ config=config,
158
+ agent_service=agent_service,
159
+ agent_setting_service=agent_setting_service,
160
+ attachment_service=attachment_service,
161
+ language_model_service=language_model_service,
162
+ language_model_setting_service=language_model_setting_service,
163
+ integration_service=integration_service,
164
+ vault_client=vault_client,
165
+ graph_persistence_factory=graph_persistence_factory,
166
+ document_repository=document_repository,
167
+ task_notification_service=task_notification_service,
168
+ )
169
+
170
+ # Agents register themselves via @RegisterAgent and are discovered through
171
+ # scan-packages/entry points. The registry needs the live container
172
+ # instance to resolve each agent's extra_deps, so create_app() binds it
173
+ # via container.agent_registry.override(...) right after instantiation
174
+ # (providers.Self() resolves to the base class under subclassing, so it
175
+ # cannot be used here).
176
+ agent_registry = providers.Singleton(AgentRegistry)
177
+
178
+ user_prompt_resolver = providers.Singleton(
179
+ UserPromptResolver,
180
+ agent_service=agent_service,
181
+ agent_setting_service=agent_setting_service,
182
+ )
183
+
184
+ prompt_registry = providers.Singleton(PromptRegistry)
185
+
186
+ default_tool_registrar = providers.Singleton(
187
+ DefaultToolRegistrar,
188
+ prompt_registry=prompt_registry,
189
+ )
190
+
191
+ coordinator_planner_supervisor_tool_registrar = providers.Singleton(
192
+ CoordinatorPlannerSupervisorToolRegistrar,
193
+ user_prompt_resolver=user_prompt_resolver,
194
+ prompt_registry=prompt_registry,
195
+ )
196
+
197
+ mcp_registrars = providers.List(
198
+ default_tool_registrar,
199
+ coordinator_planner_supervisor_tool_registrar,
200
+ )
201
+
202
+ # Tracing frameworks are decoupled behind the TracingBackend abstraction and
203
+ # composed here as a list (mirroring mcp_registrars). Adding a framework is a
204
+ # new backend class + one entry below — the Tracer coordinator, the
205
+ # @trace_agent_message decorator and the agent call sites stay untouched.
206
+ langfuse_tracing_backend = providers.Singleton(LangfuseTracingBackend)
207
+
208
+ langwatch_tracing_backend = providers.Singleton(
209
+ LangWatchTracingBackend,
210
+ service_name=service_name,
211
+ service_version=service_version,
212
+ excluded_paths=excluded_paths,
213
+ )
214
+
215
+ tracing_backends = providers.List(
216
+ langfuse_tracing_backend,
217
+ langwatch_tracing_backend,
218
+ )
219
+
220
+ tracer = providers.Singleton(Tracer, backends=tracing_backends)
File without changes
File without changes
@@ -0,0 +1,54 @@
1
+ from fastapi import HTTPException
2
+
3
+
4
+ class NotFoundError(HTTPException):
5
+ entity_name: str
6
+
7
+ def __init__(self, entity_id):
8
+ super().__init__(
9
+ status_code=404, detail=f"{self.entity_name} not found, id: {entity_id}"
10
+ )
11
+
12
+
13
+ class InvalidFieldError(HTTPException):
14
+ def __init__(self, field_name, reason):
15
+ super().__init__(
16
+ status_code=400, detail=f"Field {field_name} is invalid, reason: {reason}"
17
+ )
18
+
19
+
20
+ class ResourceNotFoundError(HTTPException):
21
+ def __init__(self, file_path):
22
+ super().__init__(status_code=500, detail=f"file not found in path {file_path}")
23
+
24
+
25
+ class ConfigurationError(HTTPException):
26
+ def __init__(self, reason):
27
+ super().__init__(
28
+ status_code=500, detail=f"Configuration error, reason: {reason}"
29
+ )
30
+
31
+
32
+ class FileToLargeError(HTTPException):
33
+ def __init__(self, file_size, max_size):
34
+ super().__init__(
35
+ status_code=413,
36
+ detail=f"File size {file_size} exceeds the maximum allowed size of {max_size} bytes",
37
+ )
38
+
39
+
40
+ class FileProcessingError(HTTPException):
41
+ def __init__(self, file_name, reason):
42
+ super().__init__(
43
+ status_code=422, detail=f"Failed to process file {file_name}: {reason}"
44
+ )
45
+
46
+
47
+ class AudioOptimizationError(HTTPException):
48
+ def __init__(self, reason):
49
+ super().__init__(status_code=500, detail=f"Audio optimization failed: {reason}")
50
+
51
+
52
+ class AuthenticationError(HTTPException):
53
+ def __init__(self, reason):
54
+ super().__init__(status_code=401, detail=f"Authentication failed: {reason}")
@@ -0,0 +1,110 @@
1
+ from sqlalchemy import (
2
+ TIMESTAMP,
3
+ Boolean,
4
+ Column,
5
+ Enum,
6
+ ForeignKey,
7
+ LargeBinary,
8
+ String,
9
+ Text,
10
+ JSON,
11
+ )
12
+ from sqlalchemy.orm import relationship
13
+
14
+ from agent_lab.infrastructure.database.sql import Base
15
+
16
+ message_role = Enum("assistant", "human", name="message_role")
17
+
18
+
19
+ class Agent(Base):
20
+ __tablename__ = "agents"
21
+
22
+ id = Column(String, primary_key=True)
23
+ created_at = Column(TIMESTAMP)
24
+ is_active = Column(Boolean)
25
+ agent_name = Column(String)
26
+ agent_type = Column(String)
27
+ agent_summary = Column(Text)
28
+ language_model_id = Column(String, ForeignKey("language_models.id"))
29
+
30
+ language_model = relationship("LanguageModel", back_populates="agents")
31
+ settings = relationship("AgentSetting", back_populates="agent")
32
+ messages = relationship("Message", back_populates="agent")
33
+
34
+
35
+ class AgentSetting(Base):
36
+ __tablename__ = "agent_settings"
37
+
38
+ id = Column(String, primary_key=True)
39
+ agent_id = Column(String, ForeignKey("agents.id"))
40
+ setting_key = Column(String)
41
+ setting_value = Column(Text)
42
+
43
+ agent = relationship("Agent", back_populates="settings")
44
+
45
+
46
+ class Attachment(Base):
47
+ __tablename__ = "attachments"
48
+
49
+ id = Column(String, primary_key=True)
50
+ created_at = Column(TIMESTAMP)
51
+ is_active = Column(Boolean)
52
+ file_name = Column(String)
53
+ raw_content = Column(LargeBinary)
54
+ parsed_content = Column(Text)
55
+ embeddings_collection = Column(String)
56
+
57
+ messages = relationship("Message", back_populates="attachment")
58
+
59
+
60
+ class LanguageModel(Base):
61
+ __tablename__ = "language_models"
62
+
63
+ id = Column(String, primary_key=True)
64
+ created_at = Column(TIMESTAMP)
65
+ is_active = Column(Boolean)
66
+ language_model_tag = Column(String)
67
+ integration_id = Column(String, ForeignKey("integrations.id"))
68
+
69
+ agents = relationship("Agent", back_populates="language_model")
70
+ integration = relationship("Integration", back_populates="language_models")
71
+ settings = relationship("LanguageModelSetting", back_populates="language_model")
72
+
73
+
74
+ class LanguageModelSetting(Base):
75
+ __tablename__ = "language_model_settings"
76
+
77
+ id = Column(String, primary_key=True)
78
+ language_model_id = Column(String, ForeignKey("language_models.id"))
79
+ setting_key = Column(String)
80
+ setting_value = Column(String)
81
+
82
+ language_model = relationship("LanguageModel", back_populates="settings")
83
+
84
+
85
+ class Integration(Base):
86
+ __tablename__ = "integrations"
87
+
88
+ id = Column(String, primary_key=True)
89
+ created_at = Column(TIMESTAMP)
90
+ is_active = Column(Boolean)
91
+ integration_type = Column(String)
92
+
93
+ language_models = relationship("LanguageModel", back_populates="integration")
94
+
95
+
96
+ class Message(Base):
97
+ __tablename__ = "messages"
98
+
99
+ id = Column(String, primary_key=True)
100
+ created_at = Column(TIMESTAMP)
101
+ is_active = Column(Boolean)
102
+ agent_id = Column(String, ForeignKey("agents.id"))
103
+ message_role = Column(message_role)
104
+ message_content = Column(Text)
105
+ response_data = Column(JSON)
106
+ attachment_id = Column(String, ForeignKey("attachments.id"))
107
+ replies_to = Column(String)
108
+
109
+ agent = relationship("Agent", back_populates="messages")
110
+ attachment = relationship("Attachment", back_populates="messages")
File without changes
@@ -0,0 +1,152 @@
1
+ from datetime import datetime
2
+ from uuid import uuid4
3
+
4
+ from typing_extensions import Iterator, Optional
5
+
6
+ from agent_lab.domain.exceptions.base import NotFoundError
7
+ from agent_lab.domain.models import Agent, AgentSetting
8
+ from agent_lab.infrastructure.database.sql import Database
9
+
10
+
11
+ class AgentRepository:
12
+ def __init__(
13
+ self,
14
+ db: Database,
15
+ ) -> None:
16
+ self.db = db
17
+
18
+ def get_all(self, schema: str) -> Iterator[Agent]:
19
+ with self.db.session(schema_name=schema) as session:
20
+ return session.query(Agent).filter(Agent.is_active).all()
21
+
22
+ def get_by_id(self, agent_id: str, schema: str) -> Agent:
23
+ with self.db.session(schema_name=schema) as session:
24
+ agent = (
25
+ session.query(Agent)
26
+ .filter(Agent.id == agent_id, Agent.is_active)
27
+ .first()
28
+ )
29
+ if not agent:
30
+ raise AgentNotFoundError(agent_id)
31
+ return agent
32
+
33
+ def add(
34
+ self, agent_name: str, agent_type: str, language_model_id: str, schema: str
35
+ ) -> Agent:
36
+ gen_id = uuid4()
37
+ with self.db.session(schema_name=schema) as session:
38
+ agent = Agent(
39
+ id=str(gen_id),
40
+ is_active=True,
41
+ created_at=datetime.now(),
42
+ agent_name=agent_name,
43
+ agent_type=agent_type,
44
+ agent_summary="",
45
+ language_model_id=language_model_id,
46
+ )
47
+ session.add(agent)
48
+ session.commit()
49
+ session.refresh(agent)
50
+ return agent
51
+
52
+ def update_agent(
53
+ self,
54
+ agent_id: str,
55
+ agent_name: str,
56
+ language_model_id: str,
57
+ schema: str,
58
+ agent_summary: Optional[str] = None,
59
+ ) -> Agent:
60
+ with self.db.session(schema_name=schema) as session:
61
+ entity: Agent = (
62
+ session.query(Agent)
63
+ .filter(Agent.id == agent_id, Agent.is_active)
64
+ .first()
65
+ )
66
+ if not entity:
67
+ raise AgentNotFoundError(agent_id)
68
+
69
+ entity.agent_name = agent_name
70
+ entity.language_model_id = language_model_id
71
+ if agent_summary is not None:
72
+ entity.agent_summary = agent_summary
73
+ session.commit()
74
+ session.refresh(entity)
75
+ return entity
76
+
77
+ def delete_by_id(self, agent_id: str, schema: str) -> None:
78
+ with self.db.session(schema_name=schema) as session:
79
+ entity: Agent = (
80
+ session.query(Agent)
81
+ .filter(Agent.id == agent_id, Agent.is_active)
82
+ .first()
83
+ )
84
+ if not entity:
85
+ raise AgentNotFoundError(agent_id)
86
+
87
+ entity.is_active = False
88
+ session.commit()
89
+
90
+
91
+ class AgentNotFoundError(NotFoundError):
92
+ entity_name: str = "Agent"
93
+
94
+
95
+ class AgentSettingRepository:
96
+ def __init__(self, db: Database) -> None:
97
+ self.db = db
98
+
99
+ def get_all(self, agent_id: str, schema: str) -> Iterator[AgentSetting]:
100
+ with self.db.session(schema_name=schema) as session:
101
+ return (
102
+ session.query(AgentSetting)
103
+ .filter(AgentSetting.agent_id == agent_id)
104
+ .all()
105
+ )
106
+
107
+ def add(
108
+ self, agent_id: str, setting_key: str, setting_value: str, schema: str
109
+ ) -> AgentSetting:
110
+ gen_id = uuid4()
111
+ with self.db.session(schema_name=schema) as session:
112
+ agent_setting = AgentSetting(
113
+ id=str(gen_id),
114
+ agent_id=agent_id,
115
+ setting_key=setting_key,
116
+ setting_value=setting_value,
117
+ )
118
+ session.add(agent_setting)
119
+ session.commit()
120
+ session.refresh(agent_setting)
121
+ return agent_setting
122
+
123
+ def update_by_key(
124
+ self, agent_id: str, setting_key: str, setting_value: str, schema: str
125
+ ) -> AgentSetting:
126
+ with self.db.session(schema_name=schema) as session:
127
+ entity: AgentSetting = (
128
+ session.query(AgentSetting)
129
+ .filter(
130
+ AgentSetting.agent_id == agent_id,
131
+ AgentSetting.setting_key == setting_key,
132
+ )
133
+ .first()
134
+ )
135
+ if not entity:
136
+ raise AgentSettingNotFoundError(agent_id)
137
+
138
+ entity.setting_value = setting_value
139
+ session.commit()
140
+ session.refresh(entity)
141
+ return entity
142
+
143
+ def delete_by_agent_id(self, agent_id: str, schema: str) -> None:
144
+ with self.db.session(schema_name=schema) as session:
145
+ session.query(AgentSetting).filter(
146
+ AgentSetting.agent_id == agent_id
147
+ ).delete(synchronize_session=False)
148
+ session.commit()
149
+
150
+
151
+ class AgentSettingNotFoundError(NotFoundError):
152
+ entity_name: str = "AgentSetting"
@@ -0,0 +1,86 @@
1
+ from datetime import datetime
2
+ from uuid import uuid4
3
+
4
+ from typing_extensions import Iterator
5
+
6
+ from agent_lab.domain.exceptions.base import NotFoundError
7
+ from agent_lab.domain.models import Attachment
8
+ from agent_lab.infrastructure.database.sql import Database
9
+
10
+
11
+ class AttachmentRepository:
12
+ def __init__(self, db: Database) -> None:
13
+ self.db = db
14
+
15
+ def get_all(self, schema: str) -> Iterator[Attachment]:
16
+ with self.db.session(schema_name=schema) as session:
17
+ return session.query(Attachment).filter(Attachment.is_active).all()
18
+
19
+ def get_by_id(self, attachment_id: str, schema: str) -> Attachment:
20
+ with self.db.session(schema_name=schema) as session:
21
+ attachment = (
22
+ session.query(Attachment)
23
+ .filter(Attachment.id == attachment_id, Attachment.is_active)
24
+ .first()
25
+ )
26
+ if not attachment:
27
+ raise AttachmentNotFoundError(attachment_id)
28
+ return attachment
29
+
30
+ def add(
31
+ self,
32
+ file_name: str,
33
+ raw_content: bytes,
34
+ parsed_content: str,
35
+ schema: str,
36
+ attachment_id: str = None,
37
+ ) -> Attachment:
38
+ if attachment_id is None:
39
+ attachment_id = str(uuid4())
40
+
41
+ with self.db.session(schema_name=schema) as session:
42
+ attachment = Attachment(
43
+ id=attachment_id,
44
+ is_active=True,
45
+ created_at=datetime.now(),
46
+ file_name=file_name,
47
+ raw_content=raw_content,
48
+ parsed_content=parsed_content,
49
+ )
50
+ session.add(attachment)
51
+ session.commit()
52
+ session.refresh(attachment)
53
+ return attachment
54
+
55
+ def delete_by_id(self, attachment_id: str, schema: str) -> None:
56
+ with self.db.session(schema_name=schema) as session:
57
+ entity: Attachment = (
58
+ session.query(Attachment)
59
+ .filter(Attachment.id == attachment_id, Attachment.is_active)
60
+ .first()
61
+ )
62
+ if not entity:
63
+ raise AttachmentNotFoundError(attachment_id)
64
+ session.delete(entity)
65
+ session.commit()
66
+
67
+ def update_attachment(
68
+ self, attachment_id: str, embeddings_collection: str, schema: str
69
+ ) -> Attachment:
70
+ with self.db.session(schema_name=schema) as session:
71
+ entity: Attachment = (
72
+ session.query(Attachment)
73
+ .filter(Attachment.id == attachment_id, Attachment.is_active)
74
+ .first()
75
+ )
76
+ if not entity:
77
+ raise AttachmentNotFoundError(attachment_id)
78
+
79
+ entity.embeddings_collection = embeddings_collection
80
+ session.commit()
81
+ session.refresh(entity)
82
+ return entity
83
+
84
+
85
+ class AttachmentNotFoundError(NotFoundError):
86
+ entity_name: str = "Attachment"
@@ -0,0 +1,72 @@
1
+ from datetime import datetime
2
+ from uuid import uuid4
3
+
4
+ import hvac
5
+ from typing_extensions import Iterator
6
+
7
+ from agent_lab.domain.exceptions.base import NotFoundError
8
+ from agent_lab.domain.models import Integration
9
+ from agent_lab.infrastructure.database.sql import Database
10
+
11
+
12
+ class IntegrationRepository:
13
+ def __init__(
14
+ self,
15
+ db: Database,
16
+ vault_client: hvac.Client,
17
+ ) -> None:
18
+ self.db = db
19
+ self.vault_client = vault_client
20
+
21
+ def get_all(self, schema: str) -> Iterator[Integration]:
22
+ with self.db.session(schema_name=schema) as session:
23
+ return session.query(Integration).filter(Integration.is_active).all()
24
+
25
+ def get_by_id(self, integration_id: str, schema: str) -> Integration:
26
+ with self.db.session(schema_name=schema) as session:
27
+ integration = (
28
+ session.query(Integration)
29
+ .filter(Integration.id == integration_id, Integration.is_active)
30
+ .first()
31
+ )
32
+ if not integration:
33
+ raise IntegrationNotFoundError(integration_id)
34
+ return integration
35
+
36
+ def add(
37
+ self, integration_type: str, api_endpoint: str, api_key: str, schema: str
38
+ ) -> Integration:
39
+ gen_id = uuid4()
40
+ self.vault_client.secrets.kv.v2.create_or_update_secret(
41
+ path=f"integration_{gen_id}",
42
+ secret={"api_endpoint": api_endpoint, "api_key": api_key},
43
+ )
44
+
45
+ with self.db.session(schema_name=schema) as session:
46
+ integration = Integration(
47
+ id=str(gen_id),
48
+ created_at=datetime.now(),
49
+ is_active=True,
50
+ integration_type=integration_type,
51
+ )
52
+ session.add(integration)
53
+ session.commit()
54
+ session.refresh(integration)
55
+ return integration
56
+
57
+ def delete_by_id(self, integration_id: str, schema: str) -> None:
58
+ with self.db.session(schema_name=schema) as session:
59
+ entity: Integration = (
60
+ session.query(Integration)
61
+ .filter(Integration.id == integration_id, Integration.is_active)
62
+ .first()
63
+ )
64
+ if not entity:
65
+ raise IntegrationNotFoundError(integration_id)
66
+
67
+ entity.is_active = False
68
+ session.commit()
69
+
70
+
71
+ class IntegrationNotFoundError(NotFoundError):
72
+ entity_name: str = "Integration"