remdb 0.3.7__py3-none-any.whl → 0.3.133__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.
- rem/__init__.py +129 -2
- rem/agentic/README.md +76 -0
- rem/agentic/__init__.py +15 -0
- rem/agentic/agents/__init__.py +16 -2
- rem/agentic/agents/sse_simulator.py +502 -0
- rem/agentic/context.py +51 -25
- rem/agentic/llm_provider_models.py +301 -0
- rem/agentic/mcp/tool_wrapper.py +112 -17
- rem/agentic/otel/setup.py +93 -4
- rem/agentic/providers/phoenix.py +314 -132
- rem/agentic/providers/pydantic_ai.py +215 -26
- rem/agentic/schema.py +361 -21
- rem/agentic/tools/rem_tools.py +3 -3
- rem/api/README.md +238 -1
- rem/api/deps.py +255 -0
- rem/api/main.py +154 -37
- rem/api/mcp_router/resources.py +1 -1
- rem/api/mcp_router/server.py +26 -5
- rem/api/mcp_router/tools.py +465 -7
- rem/api/middleware/tracking.py +172 -0
- rem/api/routers/admin.py +494 -0
- rem/api/routers/auth.py +124 -0
- rem/api/routers/chat/completions.py +402 -20
- rem/api/routers/chat/models.py +88 -10
- rem/api/routers/chat/otel_utils.py +33 -0
- rem/api/routers/chat/sse_events.py +542 -0
- rem/api/routers/chat/streaming.py +642 -45
- rem/api/routers/dev.py +81 -0
- rem/api/routers/feedback.py +268 -0
- rem/api/routers/messages.py +473 -0
- rem/api/routers/models.py +78 -0
- rem/api/routers/query.py +360 -0
- rem/api/routers/shared_sessions.py +406 -0
- rem/auth/middleware.py +126 -27
- rem/cli/commands/README.md +237 -64
- rem/cli/commands/ask.py +13 -10
- rem/cli/commands/cluster.py +1808 -0
- rem/cli/commands/configure.py +5 -6
- rem/cli/commands/db.py +396 -139
- rem/cli/commands/experiments.py +469 -74
- rem/cli/commands/process.py +22 -15
- rem/cli/commands/scaffold.py +47 -0
- rem/cli/commands/schema.py +97 -50
- rem/cli/main.py +29 -6
- rem/config.py +10 -3
- rem/models/core/core_model.py +7 -1
- rem/models/core/experiment.py +54 -0
- rem/models/core/rem_query.py +5 -2
- rem/models/entities/__init__.py +21 -0
- rem/models/entities/domain_resource.py +38 -0
- rem/models/entities/feedback.py +123 -0
- rem/models/entities/message.py +30 -1
- rem/models/entities/session.py +83 -0
- rem/models/entities/shared_session.py +180 -0
- rem/models/entities/user.py +10 -3
- rem/registry.py +373 -0
- rem/schemas/agents/rem.yaml +7 -3
- rem/services/content/providers.py +92 -133
- rem/services/content/service.py +92 -20
- rem/services/dreaming/affinity_service.py +2 -16
- rem/services/dreaming/moment_service.py +2 -15
- rem/services/embeddings/api.py +24 -17
- rem/services/embeddings/worker.py +16 -16
- rem/services/phoenix/EXPERIMENT_DESIGN.md +3 -3
- rem/services/phoenix/client.py +302 -28
- rem/services/postgres/README.md +159 -15
- rem/services/postgres/__init__.py +2 -1
- rem/services/postgres/diff_service.py +531 -0
- rem/services/postgres/pydantic_to_sqlalchemy.py +427 -129
- rem/services/postgres/repository.py +132 -0
- rem/services/postgres/schema_generator.py +291 -9
- rem/services/postgres/service.py +6 -6
- rem/services/rate_limit.py +113 -0
- rem/services/rem/README.md +14 -0
- rem/services/rem/parser.py +44 -9
- rem/services/rem/service.py +36 -2
- rem/services/session/compression.py +24 -1
- rem/services/session/reload.py +1 -1
- rem/services/user_service.py +98 -0
- rem/settings.py +399 -29
- rem/sql/background_indexes.sql +21 -16
- rem/sql/migrations/001_install.sql +387 -54
- rem/sql/migrations/002_install_models.sql +2320 -393
- rem/sql/migrations/003_optional_extensions.sql +326 -0
- rem/sql/migrations/004_cache_system.sql +548 -0
- rem/utils/__init__.py +18 -0
- rem/utils/constants.py +97 -0
- rem/utils/date_utils.py +228 -0
- rem/utils/embeddings.py +17 -4
- rem/utils/files.py +167 -0
- rem/utils/mime_types.py +158 -0
- rem/utils/model_helpers.py +156 -1
- rem/utils/schema_loader.py +282 -35
- rem/utils/sql_paths.py +146 -0
- rem/utils/sql_types.py +3 -1
- rem/utils/vision.py +9 -14
- rem/workers/README.md +14 -14
- rem/workers/__init__.py +3 -1
- rem/workers/db_listener.py +579 -0
- rem/workers/db_maintainer.py +74 -0
- rem/workers/unlogged_maintainer.py +463 -0
- {remdb-0.3.7.dist-info → remdb-0.3.133.dist-info}/METADATA +460 -303
- {remdb-0.3.7.dist-info → remdb-0.3.133.dist-info}/RECORD +105 -74
- {remdb-0.3.7.dist-info → remdb-0.3.133.dist-info}/WHEEL +1 -1
- rem/sql/002_install_models.sql +0 -1068
- rem/sql/install_models.sql +0 -1038
- {remdb-0.3.7.dist-info → remdb-0.3.133.dist-info}/entry_points.txt +0 -0
rem/__init__.py
CHANGED
|
@@ -1,2 +1,129 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"""
|
|
2
|
+
REM - Resources, Entities, Moments.
|
|
3
|
+
|
|
4
|
+
A bio-inspired memory system for agentic AI, built on FastAPI.
|
|
5
|
+
|
|
6
|
+
Usage (API mode):
|
|
7
|
+
from rem import create_app
|
|
8
|
+
|
|
9
|
+
# Create REM app (FastAPI with MCP server pre-configured)
|
|
10
|
+
app = create_app()
|
|
11
|
+
|
|
12
|
+
# Extend like any FastAPI app
|
|
13
|
+
@app.get("/my-endpoint")
|
|
14
|
+
async def my_endpoint():
|
|
15
|
+
return {"custom": True}
|
|
16
|
+
|
|
17
|
+
# Add routers
|
|
18
|
+
app.include_router(my_router)
|
|
19
|
+
|
|
20
|
+
# Access MCP server directly (FastMCP instance)
|
|
21
|
+
@app.mcp_server.tool()
|
|
22
|
+
async def my_custom_tool(query: str) -> dict:
|
|
23
|
+
'''Custom MCP tool for my application.'''
|
|
24
|
+
return {"result": "..."}
|
|
25
|
+
|
|
26
|
+
@app.mcp_server.resource("custom://config")
|
|
27
|
+
async def get_config() -> str:
|
|
28
|
+
'''Custom resource.'''
|
|
29
|
+
return '{"setting": "value"}'
|
|
30
|
+
|
|
31
|
+
Usage (model registration - works with or without API):
|
|
32
|
+
import rem
|
|
33
|
+
from rem.models.core import CoreModel
|
|
34
|
+
|
|
35
|
+
@rem.register_model
|
|
36
|
+
class CustomEntity(CoreModel):
|
|
37
|
+
name: str
|
|
38
|
+
custom_field: str
|
|
39
|
+
|
|
40
|
+
# Or register multiple:
|
|
41
|
+
rem.register_models(ModelA, ModelB)
|
|
42
|
+
|
|
43
|
+
# Then schema generation includes your models:
|
|
44
|
+
# rem db schema generate
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
from .registry import (
|
|
48
|
+
# Model registration
|
|
49
|
+
register_model,
|
|
50
|
+
register_models,
|
|
51
|
+
get_model_registry,
|
|
52
|
+
clear_model_registry,
|
|
53
|
+
# Schema path registration
|
|
54
|
+
register_schema_path,
|
|
55
|
+
register_schema_paths,
|
|
56
|
+
get_schema_paths,
|
|
57
|
+
get_schema_path_registry,
|
|
58
|
+
clear_schema_path_registry,
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def create_app():
|
|
63
|
+
"""
|
|
64
|
+
Create and return a FastAPI application with REM features pre-configured.
|
|
65
|
+
|
|
66
|
+
The returned app has:
|
|
67
|
+
- MCP server mounted at /api/v1/mcp
|
|
68
|
+
- Chat completions endpoint at /api/v1/chat/completions
|
|
69
|
+
- Health check at /health
|
|
70
|
+
- OpenAPI docs at /docs
|
|
71
|
+
|
|
72
|
+
The app exposes `app.mcp_server` (FastMCP instance) for adding custom
|
|
73
|
+
tools, resources, and prompts.
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
|
+
FastAPI application with .mcp_server attribute
|
|
77
|
+
|
|
78
|
+
Example:
|
|
79
|
+
from rem import create_app
|
|
80
|
+
|
|
81
|
+
app = create_app()
|
|
82
|
+
|
|
83
|
+
# Add custom endpoint
|
|
84
|
+
@app.get("/custom")
|
|
85
|
+
async def custom():
|
|
86
|
+
return {"custom": True}
|
|
87
|
+
|
|
88
|
+
# Add custom MCP tool
|
|
89
|
+
@app.mcp_server.tool()
|
|
90
|
+
async def my_tool(query: str) -> dict:
|
|
91
|
+
return {"result": query}
|
|
92
|
+
"""
|
|
93
|
+
from .api.main import create_app as _create_app
|
|
94
|
+
return _create_app()
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
# Lazy app instance - created on first access
|
|
98
|
+
_app = None
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def get_app():
|
|
102
|
+
"""
|
|
103
|
+
Get or create the default REM app instance.
|
|
104
|
+
|
|
105
|
+
For most cases, use create_app() to get a fresh instance.
|
|
106
|
+
This is provided for convenience in simple scripts.
|
|
107
|
+
"""
|
|
108
|
+
global _app
|
|
109
|
+
if _app is None:
|
|
110
|
+
_app = create_app()
|
|
111
|
+
return _app
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
__all__ = [
|
|
115
|
+
# App creation
|
|
116
|
+
"create_app",
|
|
117
|
+
"get_app",
|
|
118
|
+
# Model registration
|
|
119
|
+
"register_model",
|
|
120
|
+
"register_models",
|
|
121
|
+
"get_model_registry",
|
|
122
|
+
"clear_model_registry",
|
|
123
|
+
# Schema path registration
|
|
124
|
+
"register_schema_path",
|
|
125
|
+
"register_schema_paths",
|
|
126
|
+
"get_schema_paths",
|
|
127
|
+
"get_schema_path_registry",
|
|
128
|
+
"clear_schema_path_registry",
|
|
129
|
+
]
|
rem/agentic/README.md
CHANGED
|
@@ -640,6 +640,82 @@ If `query_agent_model` is not set, the agent uses `settings.llm.default_model`.
|
|
|
640
640
|
- PostgreSQL dialect aware (knows about KV_STORE, embeddings tables)
|
|
641
641
|
- Can generate multi-step query plans for complex questions
|
|
642
642
|
|
|
643
|
+
## SSE Simulator
|
|
644
|
+
|
|
645
|
+
The SSE Simulator is a **programmatic** event generator (not an LLM-based agent) that produces
|
|
646
|
+
a scripted sequence of SSE events for testing and demonstrating the streaming protocol.
|
|
647
|
+
|
|
648
|
+
### Purpose
|
|
649
|
+
|
|
650
|
+
- Frontend development without LLM costs
|
|
651
|
+
- Testing SSE parsing and rendering
|
|
652
|
+
- Demonstrating the full event protocol
|
|
653
|
+
- Load testing streaming infrastructure
|
|
654
|
+
|
|
655
|
+
### Usage
|
|
656
|
+
|
|
657
|
+
```python
|
|
658
|
+
from rem.agentic.agents import stream_simulator_events
|
|
659
|
+
from rem.api.routers.chat.sse_events import format_sse_event
|
|
660
|
+
|
|
661
|
+
# Generate all event types
|
|
662
|
+
async for event in stream_simulator_events("demo"):
|
|
663
|
+
print(format_sse_event(event))
|
|
664
|
+
|
|
665
|
+
# Minimal demo (text + done only)
|
|
666
|
+
from rem.agentic.agents import stream_minimal_demo
|
|
667
|
+
async for event in stream_minimal_demo("Hello world!"):
|
|
668
|
+
print(event)
|
|
669
|
+
|
|
670
|
+
# Error simulation
|
|
671
|
+
from rem.agentic.agents import stream_error_demo
|
|
672
|
+
async for event in stream_error_demo(error_after_words=10):
|
|
673
|
+
print(event)
|
|
674
|
+
```
|
|
675
|
+
|
|
676
|
+
### Event Sequence
|
|
677
|
+
|
|
678
|
+
The full simulator produces events in this order:
|
|
679
|
+
|
|
680
|
+
1. **Reasoning** (4 steps) - Model thinking process
|
|
681
|
+
2. **Progress** (step 1/4) - Starting
|
|
682
|
+
3. **Tool calls** (2 tools) - Simulated tool invocations
|
|
683
|
+
4. **Progress** (step 2/4) - Generating
|
|
684
|
+
5. **Text deltas** - Streamed markdown content
|
|
685
|
+
6. **Progress** (step 3/4) - Formatting
|
|
686
|
+
7. **Metadata** - Confidence, sources, flags
|
|
687
|
+
8. **Progress** (step 4/4) - Preparing actions
|
|
688
|
+
9. **Action request** - Feedback card with buttons and inputs
|
|
689
|
+
10. **Progress** (all complete)
|
|
690
|
+
11. **Done** - Stream completion
|
|
691
|
+
|
|
692
|
+
### Configuration Options
|
|
693
|
+
|
|
694
|
+
```python
|
|
695
|
+
await stream_simulator_events(
|
|
696
|
+
prompt="demo",
|
|
697
|
+
delay_ms=50, # Delay between events
|
|
698
|
+
include_reasoning=True, # Emit reasoning events
|
|
699
|
+
include_progress=True, # Emit progress events
|
|
700
|
+
include_tool_calls=True, # Emit tool call events
|
|
701
|
+
include_actions=True, # Emit action request at end
|
|
702
|
+
include_metadata=True, # Emit metadata event
|
|
703
|
+
)
|
|
704
|
+
```
|
|
705
|
+
|
|
706
|
+
### HTTP Endpoint
|
|
707
|
+
|
|
708
|
+
Use the simulator via the chat completions endpoint:
|
|
709
|
+
|
|
710
|
+
```bash
|
|
711
|
+
curl -X POST http://localhost:8000/api/v1/chat/completions \
|
|
712
|
+
-H "Content-Type: application/json" \
|
|
713
|
+
-H "X-Agent-Schema: simulator" \
|
|
714
|
+
-d '{"messages": [{"role": "user", "content": "demo"}], "stream": true}'
|
|
715
|
+
```
|
|
716
|
+
|
|
717
|
+
See `rem/api/README.md` for full SSE event protocol documentation.
|
|
718
|
+
|
|
643
719
|
## Future Work
|
|
644
720
|
|
|
645
721
|
- [ ] Phoenix evaluator integration
|
rem/agentic/__init__.py
CHANGED
|
@@ -17,6 +17,14 @@ from .schema import (
|
|
|
17
17
|
)
|
|
18
18
|
from .providers.pydantic_ai import create_agent_from_schema_file, create_agent, AgentRuntime
|
|
19
19
|
from .query_helper import ask_rem, REMQueryOutput
|
|
20
|
+
from .llm_provider_models import (
|
|
21
|
+
ModelInfo,
|
|
22
|
+
AVAILABLE_MODELS,
|
|
23
|
+
ALLOWED_MODEL_IDS,
|
|
24
|
+
is_valid_model,
|
|
25
|
+
get_valid_model_or_default,
|
|
26
|
+
get_model_by_id,
|
|
27
|
+
)
|
|
20
28
|
|
|
21
29
|
__all__ = [
|
|
22
30
|
# Context and Query
|
|
@@ -36,4 +44,11 @@ __all__ = [
|
|
|
36
44
|
# REM Query Helpers
|
|
37
45
|
"ask_rem",
|
|
38
46
|
"REMQueryOutput",
|
|
47
|
+
# LLM Provider Models
|
|
48
|
+
"ModelInfo",
|
|
49
|
+
"AVAILABLE_MODELS",
|
|
50
|
+
"ALLOWED_MODEL_IDS",
|
|
51
|
+
"is_valid_model",
|
|
52
|
+
"get_valid_model_or_default",
|
|
53
|
+
"get_model_by_id",
|
|
39
54
|
]
|
rem/agentic/agents/__init__.py
CHANGED
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
"""
|
|
2
2
|
REM Agents - Specialized agents for REM operations.
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
Most agents are defined as YAML schemas in src/rem/schemas/agents/.
|
|
5
5
|
Use create_agent_from_schema_file() to instantiate agents.
|
|
6
|
+
|
|
7
|
+
The SSE Simulator is a special programmatic "agent" that generates
|
|
8
|
+
scripted SSE events for testing and demonstration - it doesn't use an LLM.
|
|
6
9
|
"""
|
|
7
10
|
|
|
8
|
-
|
|
11
|
+
from .sse_simulator import (
|
|
12
|
+
stream_simulator_events,
|
|
13
|
+
stream_minimal_demo,
|
|
14
|
+
stream_error_demo,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
# SSE Simulator (programmatic, no LLM)
|
|
19
|
+
"stream_simulator_events",
|
|
20
|
+
"stream_minimal_demo",
|
|
21
|
+
"stream_error_demo",
|
|
22
|
+
]
|