remdb 0.3.114__py3-none-any.whl → 0.3.172__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.

Potentially problematic release.


This version of remdb might be problematic. Click here for more details.

Files changed (83) hide show
  1. rem/agentic/agents/__init__.py +16 -0
  2. rem/agentic/agents/agent_manager.py +311 -0
  3. rem/agentic/agents/sse_simulator.py +2 -0
  4. rem/agentic/context.py +103 -5
  5. rem/agentic/context_builder.py +36 -9
  6. rem/agentic/mcp/tool_wrapper.py +161 -18
  7. rem/agentic/otel/setup.py +1 -0
  8. rem/agentic/providers/phoenix.py +371 -108
  9. rem/agentic/providers/pydantic_ai.py +172 -30
  10. rem/agentic/schema.py +8 -4
  11. rem/api/deps.py +3 -5
  12. rem/api/main.py +26 -4
  13. rem/api/mcp_router/resources.py +15 -10
  14. rem/api/mcp_router/server.py +11 -3
  15. rem/api/mcp_router/tools.py +418 -4
  16. rem/api/middleware/tracking.py +5 -5
  17. rem/api/routers/admin.py +218 -1
  18. rem/api/routers/auth.py +349 -6
  19. rem/api/routers/chat/completions.py +255 -7
  20. rem/api/routers/chat/models.py +81 -7
  21. rem/api/routers/chat/otel_utils.py +33 -0
  22. rem/api/routers/chat/sse_events.py +17 -1
  23. rem/api/routers/chat/streaming.py +126 -19
  24. rem/api/routers/feedback.py +134 -14
  25. rem/api/routers/messages.py +24 -15
  26. rem/api/routers/query.py +6 -3
  27. rem/auth/__init__.py +13 -3
  28. rem/auth/jwt.py +352 -0
  29. rem/auth/middleware.py +115 -10
  30. rem/auth/providers/__init__.py +4 -1
  31. rem/auth/providers/email.py +215 -0
  32. rem/cli/commands/README.md +42 -0
  33. rem/cli/commands/cluster.py +617 -168
  34. rem/cli/commands/configure.py +4 -7
  35. rem/cli/commands/db.py +66 -22
  36. rem/cli/commands/experiments.py +468 -76
  37. rem/cli/commands/schema.py +6 -5
  38. rem/cli/commands/session.py +336 -0
  39. rem/cli/dreaming.py +2 -2
  40. rem/cli/main.py +2 -0
  41. rem/config.py +8 -1
  42. rem/models/core/experiment.py +58 -14
  43. rem/models/entities/__init__.py +4 -0
  44. rem/models/entities/ontology.py +1 -1
  45. rem/models/entities/ontology_config.py +1 -1
  46. rem/models/entities/subscriber.py +175 -0
  47. rem/models/entities/user.py +1 -0
  48. rem/schemas/agents/core/agent-builder.yaml +235 -0
  49. rem/schemas/agents/examples/contract-analyzer.yaml +1 -1
  50. rem/schemas/agents/examples/contract-extractor.yaml +1 -1
  51. rem/schemas/agents/examples/cv-parser.yaml +1 -1
  52. rem/services/__init__.py +3 -1
  53. rem/services/content/service.py +4 -3
  54. rem/services/email/__init__.py +10 -0
  55. rem/services/email/service.py +513 -0
  56. rem/services/email/templates.py +360 -0
  57. rem/services/phoenix/client.py +59 -18
  58. rem/services/postgres/README.md +38 -0
  59. rem/services/postgres/diff_service.py +127 -6
  60. rem/services/postgres/pydantic_to_sqlalchemy.py +45 -13
  61. rem/services/postgres/repository.py +5 -4
  62. rem/services/postgres/schema_generator.py +205 -4
  63. rem/services/session/compression.py +120 -50
  64. rem/services/session/reload.py +14 -7
  65. rem/services/user_service.py +41 -9
  66. rem/settings.py +442 -23
  67. rem/sql/migrations/001_install.sql +156 -0
  68. rem/sql/migrations/002_install_models.sql +1951 -88
  69. rem/sql/migrations/004_cache_system.sql +548 -0
  70. rem/sql/migrations/005_schema_update.sql +145 -0
  71. rem/utils/README.md +45 -0
  72. rem/utils/__init__.py +18 -0
  73. rem/utils/files.py +157 -1
  74. rem/utils/schema_loader.py +139 -10
  75. rem/utils/sql_paths.py +146 -0
  76. rem/utils/vision.py +1 -1
  77. rem/workers/__init__.py +3 -1
  78. rem/workers/db_listener.py +579 -0
  79. rem/workers/unlogged_maintainer.py +463 -0
  80. {remdb-0.3.114.dist-info → remdb-0.3.172.dist-info}/METADATA +218 -180
  81. {remdb-0.3.114.dist-info → remdb-0.3.172.dist-info}/RECORD +83 -68
  82. {remdb-0.3.114.dist-info → remdb-0.3.172.dist-info}/WHEEL +0 -0
  83. {remdb-0.3.114.dist-info → remdb-0.3.172.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,175 @@
1
+ """
2
+ Subscriber - Email subscription management.
3
+
4
+ This model stores subscribers who sign up via websites/apps.
5
+ Subscribers can be collected before user registration for newsletters,
6
+ updates, and approval-based access control.
7
+
8
+ Key features:
9
+ - Deterministic UUID from email (same email = same ID)
10
+ - Approval workflow for access control
11
+ - Tags for segmentation
12
+ - Origin tracking for analytics
13
+ """
14
+
15
+ import uuid
16
+ from datetime import datetime, timezone
17
+ from enum import Enum
18
+ from typing import Optional
19
+
20
+ from pydantic import Field, EmailStr, model_validator
21
+
22
+ from ..core import CoreModel
23
+
24
+
25
+ class SubscriberStatus(str, Enum):
26
+ """Subscription status."""
27
+
28
+ ACTIVE = "active" # Actively subscribed
29
+ UNSUBSCRIBED = "unsubscribed" # User unsubscribed
30
+ BOUNCED = "bounced" # Email bounced
31
+ PENDING = "pending" # Pending confirmation (if double opt-in)
32
+
33
+
34
+ class SubscriberOrigin(str, Enum):
35
+ """Where the subscription originated from."""
36
+
37
+ WEBSITE = "website" # Main website subscribe form
38
+ LANDING_PAGE = "landing_page" # Campaign landing page
39
+ APP = "app" # In-app subscription
40
+ IMPORT = "import" # Bulk import
41
+ REFERRAL = "referral" # Referred by another user
42
+ OTHER = "other"
43
+
44
+
45
+ class Subscriber(CoreModel):
46
+ """
47
+ Email subscriber for newsletters and access control.
48
+
49
+ This model captures subscribers who sign up via the website, landing pages,
50
+ or in-app prompts. Uses deterministic UUID from email for natural upserts.
51
+
52
+ Access control via `approved` field:
53
+ - When email auth checks subscriber status, only approved subscribers
54
+ can complete login (if approval is enabled in settings).
55
+ - Subscribers can be pre-approved, or approved manually/automatically.
56
+
57
+ Usage:
58
+ from rem.services.postgres import Repository
59
+ from rem.models.entities import Subscriber, SubscriberStatus
60
+
61
+ repo = Repository(Subscriber, db=db)
62
+
63
+ # Create subscriber (ID auto-generated from email)
64
+ subscriber = Subscriber(
65
+ email="user@example.com",
66
+ name="John Doe",
67
+ origin=SubscriberOrigin.WEBSITE,
68
+ )
69
+ await repo.upsert(subscriber)
70
+
71
+ # Check if approved for login
72
+ subscriber = await repo.get_by_id(subscriber.id, tenant_id="default")
73
+ if subscriber and subscriber.approved:
74
+ # Allow login
75
+ pass
76
+ """
77
+
78
+ # Required field
79
+ email: EmailStr = Field(
80
+ description="Subscriber's email address (unique identifier)"
81
+ )
82
+
83
+ # Optional fields
84
+ name: Optional[str] = Field(
85
+ default=None,
86
+ description="Subscriber's name (optional)"
87
+ )
88
+
89
+ comment: Optional[str] = Field(
90
+ default=None,
91
+ max_length=500,
92
+ description="Optional comment or message from subscriber"
93
+ )
94
+
95
+ status: SubscriberStatus = Field(
96
+ default=SubscriberStatus.ACTIVE,
97
+ description="Current subscription status"
98
+ )
99
+
100
+ # Access control
101
+ approved: bool = Field(
102
+ default=False,
103
+ description="Whether subscriber is approved for login (for approval workflows)"
104
+ )
105
+
106
+ approved_at: Optional[datetime] = Field(
107
+ default=None,
108
+ description="When the subscriber was approved"
109
+ )
110
+
111
+ approved_by: Optional[str] = Field(
112
+ default=None,
113
+ description="Who approved the subscriber (user ID or 'system')"
114
+ )
115
+
116
+ # Origin tracking
117
+ origin: SubscriberOrigin = Field(
118
+ default=SubscriberOrigin.WEBSITE,
119
+ description="Where the subscription originated"
120
+ )
121
+
122
+ origin_detail: Optional[str] = Field(
123
+ default=None,
124
+ description="Additional origin context (e.g., campaign name, page URL)"
125
+ )
126
+
127
+ # Timestamps
128
+ subscribed_at: datetime = Field(
129
+ default_factory=lambda: datetime.now(timezone.utc),
130
+ description="When the subscription was created"
131
+ )
132
+
133
+ unsubscribed_at: Optional[datetime] = Field(
134
+ default=None,
135
+ description="When the user unsubscribed (if applicable)"
136
+ )
137
+
138
+ # Compliance
139
+ ip_address: Optional[str] = Field(
140
+ default=None,
141
+ description="IP address at subscription time (for compliance)"
142
+ )
143
+
144
+ user_agent: Optional[str] = Field(
145
+ default=None,
146
+ description="Browser user agent at subscription time"
147
+ )
148
+
149
+ # Segmentation
150
+ tags: list[str] = Field(
151
+ default_factory=list,
152
+ description="Tags for segmentation (e.g., ['early-access', 'beta'])"
153
+ )
154
+
155
+ @staticmethod
156
+ def email_to_uuid(email: str) -> uuid.UUID:
157
+ """Generate a deterministic UUID from an email address.
158
+
159
+ Uses UUID v5 with DNS namespace for consistency with
160
+ EmailService.generate_user_id_from_email().
161
+
162
+ Args:
163
+ email: Email address
164
+
165
+ Returns:
166
+ Deterministic UUID
167
+ """
168
+ return uuid.uuid5(uuid.NAMESPACE_DNS, email.lower().strip())
169
+
170
+ @model_validator(mode="after")
171
+ def set_id_from_email(self) -> "Subscriber":
172
+ """Auto-generate deterministic ID from email for natural upsert."""
173
+ if self.email:
174
+ self.id = self.email_to_uuid(self.email)
175
+ return self
@@ -22,6 +22,7 @@ from ..core import CoreModel
22
22
  class UserTier(str, Enum):
23
23
  """User subscription tier for feature gating."""
24
24
 
25
+ BLOCKED = "blocked" # User is blocked from logging in
25
26
  ANONYMOUS = "anonymous"
26
27
  FREE = "free"
27
28
  BASIC = "basic"
@@ -0,0 +1,235 @@
1
+ type: object
2
+ description: |
3
+ # Agent Builder - Create Custom AI Agents Through Conversation
4
+
5
+ You help users create custom AI agents for the REM platform through natural conversation.
6
+ Guide them step-by-step, gather requirements, show previews, and save when ready.
7
+
8
+ ## Your Workflow
9
+
10
+ 1. **Understand the need**: Ask what they want the agent to do
11
+ 2. **Define personality**: Help them choose tone and communication style
12
+ 3. **Set guardrails**: What should the agent NOT do?
13
+ 4. **Structure outputs**: Define what data the agent captures (optional)
14
+ 5. **Preview**: Show them what the agent will look like
15
+ 6. **Save**: Use `save_agent` tool to persist it
16
+
17
+ ## Conversation Style
18
+
19
+ Be friendly and helpful. Ask one or two questions at a time.
20
+ Don't overwhelm with options - guide them step by step.
21
+
22
+ ## IMPORTANT: Tool Usage
23
+
24
+ - `save_agent` - Use ONLY in Step 6 when user approves the preview
25
+ - `get_agents_list` - Use if user asks to see existing agents as examples
26
+ - `get_agent_schema` - Use to load a specific agent (like "rem") as reference
27
+
28
+ DO NOT loop on tools. If a user asks for examples, call get_agents_list ONCE,
29
+ then discuss what you found. This is a conversational workflow.
30
+
31
+ ## Step 1: Identity & Purpose
32
+
33
+ Ask about:
34
+ - What should this agent help with? (primary purpose)
35
+ - What would you like to call it? (suggest kebab-case like "sales-assistant")
36
+ - What role/persona should it embody?
37
+
38
+ ## Step 2: Tone & Communication Style
39
+
40
+ Help define tone using this framework:
41
+
42
+ | Dimension | Options |
43
+ |-----------|---------|
44
+ | Formality | casual, conversational, professional, formal |
45
+ | Warmth | empathetic, friendly, neutral, businesslike |
46
+ | Pace | patient, balanced, efficient, direct |
47
+ | Expertise | peer, guide, expert, authority |
48
+
49
+ Ask: "What tone feels right? For example, should it be friendly and casual, or more professional?"
50
+
51
+ ## Step 3: Guardrails
52
+
53
+ Ask what the agent should NOT do:
54
+ - Topics to avoid?
55
+ - Actions it shouldn't take?
56
+ - Boundaries to respect?
57
+
58
+ Example guardrails:
59
+ - "Never provide medical/legal/financial advice"
60
+ - "Don't make promises about timelines"
61
+ - "Always recommend consulting a professional for serious issues"
62
+
63
+ ## Step 4: Structured Outputs (Optional)
64
+
65
+ Most agents just need an `answer` field. But some use cases benefit from structured data:
66
+
67
+ | Field | Type | Description |
68
+ |-------|------|-------------|
69
+ | answer | string | Natural language response (always required) |
70
+ | confidence | number | 0.0-1.0 confidence score |
71
+ | category | string | Classification of the request |
72
+ | follow_up_needed | boolean | Whether follow-up is required |
73
+
74
+ Field types available:
75
+ - `string` - text values
76
+ - `number` - numeric values (can add minimum/maximum)
77
+ - `boolean` - true/false
78
+ - `array` - list of items
79
+ - `string` with `enum` - fixed set of choices
80
+
81
+ Only suggest structured outputs if the use case clearly benefits from them.
82
+
83
+ ## Step 5: Preview
84
+
85
+ Before saving, show a preview:
86
+
87
+ ```
88
+ ## Agent Preview: {name}
89
+
90
+ **Purpose:** {brief description}
91
+
92
+ **Personality:** {tone and approach}
93
+
94
+ **System Prompt:**
95
+ {the actual prompt that will guide the agent}
96
+
97
+ **Guardrails:**
98
+ - {guardrail 1}
99
+ - {guardrail 2}
100
+
101
+ **Structured Fields:** (if any beyond answer)
102
+ | Field | Type | Description |
103
+ |-------|------|-------------|
104
+ | answer | string | Response to user |
105
+ ```
106
+
107
+ Ask: "Does this look good? I can save it now or adjust anything."
108
+
109
+ ## Step 6: Save the Agent
110
+
111
+ When the user approves, call `save_agent` with:
112
+ - `name`: kebab-case name (e.g., "customer-support-bot")
113
+ - `description`: The full system prompt (this is the most important part!)
114
+ - `properties`: Structured output fields (optional, defaults to just "answer")
115
+ - `required`: Which fields are required (optional, defaults to ["answer"])
116
+ - `tags`: Relevant tags for organization
117
+
118
+ ## Writing Great System Prompts
119
+
120
+ The `description` field IS the system prompt. Make it:
121
+
122
+ 1. **Clear about role**: "You are a [role] that helps users [do what]"
123
+ 2. **Specific about behavior**: How should it respond? What's the communication style?
124
+ 3. **Explicit about guardrails**: What should it NOT do?
125
+ 4. **Structured with sections**: Use markdown headers for organization
126
+
127
+ Example structure:
128
+ ```
129
+ # [Agent Name]
130
+
131
+ You are a [role description]. Your purpose is to [main goal].
132
+
133
+ ## Communication Style
134
+ [Tone, approach, language preferences]
135
+
136
+ ## Core Responsibilities
137
+ - [Responsibility 1]
138
+ - [Responsibility 2]
139
+
140
+ ## Guardrails
141
+ - Never [thing to avoid]
142
+ - Always [thing to ensure]
143
+
144
+ ## How to Respond
145
+ [Guidelines for responses]
146
+ ```
147
+
148
+ ## Example Conversation
149
+
150
+ User: "I want an agent that helps write professional emails"
151
+
152
+ You: "Great idea! Let me help you create an email writing assistant.
153
+
154
+ First, what tone should it have? For example:
155
+ - Professional and formal
156
+ - Friendly but polished
157
+ - Direct and concise"
158
+
159
+ User: "Friendly but polished"
160
+
161
+ You: "Perfect! Should it focus just on writing emails, or also help with:
162
+ - Suggesting subject lines
163
+ - Adjusting tone for different recipients
164
+ - Summarizing long email threads"
165
+
166
+ User: "All of those would be helpful"
167
+
168
+ You: "Great! Any things it should NOT do? For example, some email assistants avoid:
169
+ - Writing emails that could be seen as legally binding
170
+ - Making commitments on behalf of the user"
171
+
172
+ User: "Yeah, it shouldn't make commitments or promises"
173
+
174
+ You: "Perfect! Here's a preview:
175
+
176
+ ## Agent Preview: email-assistant
177
+
178
+ **Purpose:** Help users write polished, professional emails
179
+
180
+ **Personality:** Friendly, helpful, professional writing partner
181
+
182
+ **System Prompt:**
183
+ # Email Writing Assistant
184
+
185
+ You are a friendly email writing assistant. Help users craft polished,
186
+ professional emails while maintaining a warm, approachable tone.
187
+
188
+ ## What You Can Do
189
+ - Write new emails from scratch based on user's intent
190
+ - Suggest compelling subject lines
191
+ - Adjust tone for different audiences (colleagues, executives, clients)
192
+ - Summarize long email threads
193
+ - Proofread and improve existing drafts
194
+
195
+ ## Communication Style
196
+ Be helpful and collaborative. Suggest improvements but respect the user's voice.
197
+ Ask clarifying questions when the request is ambiguous.
198
+
199
+ ## Guardrails
200
+ - Never write emails that make commitments or promises on behalf of the user
201
+ - Don't write anything that could be legally binding
202
+ - Always let the user review before sending
203
+
204
+ Does this look good? I can save it now or adjust anything."
205
+
206
+ User: "Looks great, save it!"
207
+
208
+ You: *calls save_agent tool*
209
+ "Done! Your email-assistant is ready to use."
210
+
211
+ properties:
212
+ answer:
213
+ type: string
214
+ description: Your conversational response to the user
215
+
216
+ required:
217
+ - answer
218
+
219
+ json_schema_extra:
220
+ kind: agent
221
+ name: agent-builder
222
+ version: "1.2.0"
223
+ tags:
224
+ - meta
225
+ - builder
226
+ structured_output: false # Stream text responses, don't return JSON
227
+ mcp_servers: [] # Disable default MCP tools to prevent search_rem looping
228
+ resources:
229
+ - uri: rem://agents
230
+ description: "List all available agent schemas with descriptions"
231
+ - uri: rem://agents/{agent_name}
232
+ description: "Load a specific agent schema by name (e.g., 'rem', 'siggy')"
233
+ tools:
234
+ - name: save_agent
235
+ description: "Save the agent schema. Only call when user approves the preview in Step 6."
@@ -308,7 +308,7 @@ json_schema_extra:
308
308
  - provider_name: anthropic
309
309
  model_name: claude-sonnet-4-5-20250929
310
310
  - provider_name: openai
311
- model_name: gpt-4o
311
+ model_name: gpt-4.1
312
312
  embedding_fields:
313
313
  - contract_title
314
314
  - contract_type
@@ -131,4 +131,4 @@ json_schema_extra:
131
131
  - provider_name: anthropic
132
132
  model_name: claude-sonnet-4-5-20250929
133
133
  - provider_name: openai
134
- model_name: gpt-4o
134
+ model_name: gpt-4.1
@@ -255,7 +255,7 @@ json_schema_extra:
255
255
  - provider_name: anthropic
256
256
  model_name: claude-sonnet-4-5-20250929
257
257
  - provider_name: openai
258
- model_name: gpt-4o
258
+ model_name: gpt-4.1
259
259
  embedding_fields:
260
260
  - candidate_name
261
261
  - professional_summary
rem/services/__init__.py CHANGED
@@ -4,13 +4,15 @@ REM Services
4
4
  Service layer for REM system operations:
5
5
  - PostgresService: PostgreSQL/CloudNativePG database operations
6
6
  - RemService: REM query execution and graph operations
7
+ - EmailService: Transactional emails and passwordless login
7
8
 
8
9
  For file/S3 operations, use rem.services.fs instead:
9
10
  from rem.services.fs import FS, S3Provider
10
11
  """
11
12
 
13
+ from .email import EmailService
12
14
  from .fs.service import FileSystemService
13
15
  from .postgres import PostgresService
14
16
  from .rem import RemService
15
17
 
16
- __all__ = ["PostgresService", "RemService", "FileSystemService"]
18
+ __all__ = ["EmailService", "PostgresService", "RemService", "FileSystemService"]
@@ -666,10 +666,11 @@ class ContentService:
666
666
  # IMPORTANT: category field distinguishes agents from evaluators
667
667
  # - kind=agent → category="agent" (AI agents with tools/resources)
668
668
  # - kind=evaluator → category="evaluator" (LLM-as-a-Judge evaluators)
669
- # Schemas (agents/evaluators) default to system tenant for shared access
669
+ # User-scoped schemas: if user_id provided, scope to user's tenant
670
+ # System schemas: if no user_id, use "system" tenant for shared access
670
671
  schema_entity = Schema(
671
- tenant_id="system",
672
- user_id=None,
672
+ tenant_id=user_id or "system",
673
+ user_id=user_id,
673
674
  name=name,
674
675
  spec=schema_data,
675
676
  category=kind, # Maps kind → category for database filtering
@@ -0,0 +1,10 @@
1
+ """
2
+ Email Service Module.
3
+
4
+ Provides EmailService for sending transactional emails and passwordless login.
5
+ """
6
+
7
+ from .service import EmailService
8
+ from .templates import EmailTemplate, login_code_template
9
+
10
+ __all__ = ["EmailService", "EmailTemplate", "login_code_template"]