MCPcopy Create free account
hub / github.com/MemTensor/MemOS / get_current_context

Function get_current_context

src/memos/context/context.py:166–185  ·  view source on GitHub ↗

Get the current request context. Returns: The current RequestContext if available, None otherwise.

()

Source from the content-addressed store, hash-verified

164
165
166def get_current_context() -> RequestContext | None:
167 """
168 Get the current request context.
169
170 Returns:
171 The current RequestContext if available, None otherwise.
172 """
173 context_dict = _request_context.get()
174 if context_dict:
175 ctx = RequestContext(
176 trace_id=context_dict.get("trace_id"),
177 api_path=context_dict.get("api_path"),
178 env=context_dict.get("env"),
179 user_type=context_dict.get("user_type"),
180 user_name=context_dict.get("user_name"),
181 source=context_dict.get("source"),
182 )
183 ctx._data = context_dict.get("data", {}).copy()
184 return ctx
185 return None
186
187
188def require_context() -> RequestContext:

Callers 14

_message_consumerMethod · 0.90
get_g_objectFunction · 0.90
get_current_gFunction · 0.90
require_gFunction · 0.90
task_with_contextFunction · 0.90
thread_taskFunction · 0.90
pool_taskFunction · 0.90
map_taskFunction · 0.90
error_taskFunction · 0.90
require_contextFunction · 0.85
__init__Method · 0.85

Calls 3

RequestContextClass · 0.85
getMethod · 0.65
copyMethod · 0.45

Tested by 6

task_with_contextFunction · 0.72
thread_taskFunction · 0.72
pool_taskFunction · 0.72
map_taskFunction · 0.72
error_taskFunction · 0.72