remdb 0.3.127__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 (62) hide show
  1. rem/agentic/agents/__init__.py +16 -0
  2. rem/agentic/agents/agent_manager.py +311 -0
  3. rem/agentic/context.py +81 -3
  4. rem/agentic/context_builder.py +36 -9
  5. rem/agentic/mcp/tool_wrapper.py +132 -15
  6. rem/agentic/providers/phoenix.py +371 -108
  7. rem/agentic/providers/pydantic_ai.py +163 -45
  8. rem/agentic/schema.py +8 -4
  9. rem/api/deps.py +3 -5
  10. rem/api/main.py +22 -3
  11. rem/api/mcp_router/resources.py +15 -10
  12. rem/api/mcp_router/server.py +2 -0
  13. rem/api/mcp_router/tools.py +94 -2
  14. rem/api/middleware/tracking.py +5 -5
  15. rem/api/routers/auth.py +349 -6
  16. rem/api/routers/chat/completions.py +5 -3
  17. rem/api/routers/chat/streaming.py +95 -22
  18. rem/api/routers/messages.py +24 -15
  19. rem/auth/__init__.py +13 -3
  20. rem/auth/jwt.py +352 -0
  21. rem/auth/middleware.py +115 -10
  22. rem/auth/providers/__init__.py +4 -1
  23. rem/auth/providers/email.py +215 -0
  24. rem/cli/commands/configure.py +3 -4
  25. rem/cli/commands/experiments.py +226 -50
  26. rem/cli/commands/session.py +336 -0
  27. rem/cli/dreaming.py +2 -2
  28. rem/cli/main.py +2 -0
  29. rem/models/core/experiment.py +58 -14
  30. rem/models/entities/__init__.py +4 -0
  31. rem/models/entities/ontology.py +1 -1
  32. rem/models/entities/ontology_config.py +1 -1
  33. rem/models/entities/subscriber.py +175 -0
  34. rem/models/entities/user.py +1 -0
  35. rem/schemas/agents/core/agent-builder.yaml +235 -0
  36. rem/schemas/agents/examples/contract-analyzer.yaml +1 -1
  37. rem/schemas/agents/examples/contract-extractor.yaml +1 -1
  38. rem/schemas/agents/examples/cv-parser.yaml +1 -1
  39. rem/services/__init__.py +3 -1
  40. rem/services/content/service.py +4 -3
  41. rem/services/email/__init__.py +10 -0
  42. rem/services/email/service.py +513 -0
  43. rem/services/email/templates.py +360 -0
  44. rem/services/postgres/README.md +38 -0
  45. rem/services/postgres/diff_service.py +19 -3
  46. rem/services/postgres/pydantic_to_sqlalchemy.py +45 -13
  47. rem/services/postgres/repository.py +5 -4
  48. rem/services/session/compression.py +113 -50
  49. rem/services/session/reload.py +14 -7
  50. rem/services/user_service.py +41 -9
  51. rem/settings.py +292 -5
  52. rem/sql/migrations/001_install.sql +1 -1
  53. rem/sql/migrations/002_install_models.sql +91 -91
  54. rem/sql/migrations/005_schema_update.sql +145 -0
  55. rem/utils/README.md +45 -0
  56. rem/utils/files.py +157 -1
  57. rem/utils/schema_loader.py +45 -7
  58. rem/utils/vision.py +1 -1
  59. {remdb-0.3.127.dist-info → remdb-0.3.172.dist-info}/METADATA +7 -5
  60. {remdb-0.3.127.dist-info → remdb-0.3.172.dist-info}/RECORD +62 -52
  61. {remdb-0.3.127.dist-info → remdb-0.3.172.dist-info}/WHEEL +0 -0
  62. {remdb-0.3.127.dist-info → remdb-0.3.172.dist-info}/entry_points.txt +0 -0
@@ -107,27 +107,144 @@ def create_mcp_tool_wrapper(
107
107
  return Tool(tool_func)
108
108
 
109
109
 
110
- def create_resource_tool(uri: str, usage: str) -> Tool:
110
+ def create_resource_tool(uri: str, usage: str = "", mcp_server: Any = None) -> Tool:
111
111
  """
112
112
  Build a Tool instance from an MCP resource URI.
113
113
 
114
- This is a placeholder for now. A real implementation would create a
115
- tool that reads the content of the resource URI.
114
+ Creates a tool that fetches the resource content when called.
115
+ Resources declared in agent YAML become callable tools - this eliminates
116
+ the artificial MCP distinction between tools and resources.
117
+
118
+ Supports both:
119
+ - Concrete URIs: "rem://schemas" -> tool with no parameters
120
+ - Template URIs: "patient-profile://field/{field_key}" -> tool with field_key parameter
116
121
 
117
122
  Args:
118
- uri: The resource URI (e.g., "rem://resources/some-id").
119
- usage: The description of how to use the tool.
123
+ uri: The resource URI (concrete or template with {variable} placeholders).
124
+ usage: The description of what this resource provides.
125
+ mcp_server: Optional FastMCP server instance to resolve resources from.
126
+ If provided, resources are resolved from this server's registry.
127
+ If not provided, falls back to REM's built-in load_resource().
120
128
 
121
129
  Returns:
122
- A Pydantic AI Tool instance.
123
- """
124
- # Placeholder function that would read the resource
125
- def read_resource():
126
- """Reads content from a resource URI."""
127
- return f"Content of {uri}"
130
+ A Pydantic AI Tool instance that fetches the resource.
128
131
 
129
- read_resource.__name__ = f"read_{uri.replace('://', '_').replace('/', '_')}"
130
- read_resource.__doc__ = usage
132
+ Example:
133
+ # Concrete URI -> no-param tool
134
+ tool = create_resource_tool("rem://schemas", "List all agent schemas")
131
135
 
132
- logger.info(f"Built resource tool: {read_resource.__name__} (uri: {uri})")
133
- return Tool(read_resource)
136
+ # Template URI -> parameterized tool
137
+ tool = create_resource_tool("patient-profile://field/{field_key}", "Get field definition", mcp_server=mcp)
138
+ # Agent calls: get_patient_profile_field(field_key="safety.suicidality")
139
+ """
140
+ import json
141
+ import re
142
+
143
+ # Extract template variables from URI (e.g., {field_key}, {domain_name})
144
+ template_vars = re.findall(r'\{([^}]+)\}', uri)
145
+
146
+ # Parse URI to create function name (strip template vars for cleaner name)
147
+ clean_uri = re.sub(r'\{[^}]+\}', '', uri)
148
+ parts = clean_uri.replace("://", "_").replace("-", "_").replace("/", "_").replace(".", "_")
149
+ parts = re.sub(r'_+', '_', parts).strip('_') # Clean up multiple underscores
150
+ func_name = f"get_{parts}"
151
+
152
+ # For parameterized URIs, append _by_{params} to avoid naming conflicts
153
+ # e.g., rem://agents/{name} -> get_rem_agents_by_name (distinct from get_rem_agents)
154
+ if template_vars:
155
+ param_suffix = "_by_" + "_".join(template_vars)
156
+ func_name = f"{func_name}{param_suffix}"
157
+
158
+ # Build description including parameter info
159
+ description = usage or f"Fetch {uri} resource"
160
+ if template_vars:
161
+ param_desc = ", ".join(template_vars)
162
+ description = f"{description}\n\nParameters: {param_desc}"
163
+
164
+ if template_vars:
165
+ # Template URI -> create parameterized tool
166
+ async def wrapper(**kwargs: Any) -> str:
167
+ """Fetch MCP resource with substituted parameters."""
168
+ import asyncio
169
+ import inspect
170
+
171
+ # Try to resolve from MCP server's resource templates first
172
+ if mcp_server is not None:
173
+ try:
174
+ # Get resource templates from MCP server
175
+ templates = await mcp_server.get_resource_templates()
176
+ if uri in templates:
177
+ template = templates[uri]
178
+ # Call the template's underlying function directly
179
+ # The fn expects the template variables as kwargs
180
+ fn_result = template.fn(**kwargs)
181
+ # Handle both sync and async functions
182
+ if inspect.iscoroutine(fn_result):
183
+ fn_result = await fn_result
184
+ if isinstance(fn_result, str):
185
+ return fn_result
186
+ return json.dumps(fn_result, indent=2)
187
+ except Exception as e:
188
+ logger.warning(f"Failed to resolve resource {uri} from MCP server: {e}")
189
+
190
+ # Fallback: substitute template variables and use load_resource
191
+ resolved_uri = uri
192
+ for var in template_vars:
193
+ if var in kwargs:
194
+ resolved_uri = resolved_uri.replace(f"{{{var}}}", str(kwargs[var]))
195
+ else:
196
+ return json.dumps({"error": f"Missing required parameter: {var}"})
197
+
198
+ from rem.api.mcp_router.resources import load_resource
199
+ result = await load_resource(resolved_uri)
200
+ if isinstance(result, str):
201
+ return result
202
+ return json.dumps(result, indent=2)
203
+
204
+ # Build parameter annotations for Pydantic AI
205
+ wrapper.__name__ = func_name
206
+ wrapper.__doc__ = description
207
+ # Add type hints for parameters
208
+ wrapper.__annotations__ = {var: str for var in template_vars}
209
+ wrapper.__annotations__['return'] = str
210
+
211
+ logger.info(f"Built parameterized resource tool: {func_name} (uri: {uri}, params: {template_vars})")
212
+ else:
213
+ # Concrete URI -> no-param tool
214
+ async def wrapper(**kwargs: Any) -> str:
215
+ """Fetch MCP resource and return contents."""
216
+ import asyncio
217
+ import inspect
218
+
219
+ if kwargs:
220
+ logger.warning(f"Resource tool {func_name} called with unexpected kwargs: {list(kwargs.keys())}")
221
+
222
+ # Try to resolve from MCP server's resources first
223
+ if mcp_server is not None:
224
+ try:
225
+ resources = await mcp_server.get_resources()
226
+ if uri in resources:
227
+ resource = resources[uri]
228
+ # Call the resource's underlying function
229
+ fn_result = resource.fn()
230
+ if inspect.iscoroutine(fn_result):
231
+ fn_result = await fn_result
232
+ if isinstance(fn_result, str):
233
+ return fn_result
234
+ return json.dumps(fn_result, indent=2)
235
+ except Exception as e:
236
+ logger.warning(f"Failed to resolve resource {uri} from MCP server: {e}")
237
+
238
+ # Fallback to load_resource
239
+ from rem.api.mcp_router.resources import load_resource
240
+ result = await load_resource(uri)
241
+ if isinstance(result, str):
242
+ return result
243
+ return json.dumps(result, indent=2)
244
+
245
+ wrapper.__name__ = func_name
246
+ wrapper.__doc__ = description
247
+
248
+ logger.info(f"Built resource tool: {func_name} (uri: {uri})")
249
+
250
+ return Tool(wrapper)