-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathmcp.py
More file actions
794 lines (697 loc) · 26.6 KB
/
mcp.py
File metadata and controls
794 lines (697 loc) · 26.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
import logging
from typing import Any
import ulid
from mcp.server.fastmcp import FastMCP as _FastMCPBase
from agent_memory_server.api import (
create_long_term_memory as core_create_long_term_memory,
get_working_memory as core_get_working_memory,
memory_prompt as core_memory_prompt,
put_working_memory as core_put_working_memory,
search_long_term_memory as core_search_long_term_memory,
)
from agent_memory_server.config import settings
from agent_memory_server.dependencies import get_background_tasks
from agent_memory_server.filters import (
CreatedAt,
Entities,
LastAccessed,
MemoryType,
Namespace,
SessionId,
Topics,
UserId,
)
from agent_memory_server.models import (
AckResponse,
CreateMemoryRecordRequest,
LenientMemoryRecord,
MemoryMessage,
MemoryPromptRequest,
MemoryPromptResponse,
MemoryRecord,
MemoryRecordResults,
ModelNameLiteral,
SearchRequest,
WorkingMemory,
WorkingMemoryRequest,
WorkingMemoryResponse,
)
logger = logging.getLogger(__name__)
class FastMCP(_FastMCPBase):
"""Extend FastMCP to support optional URL namespace and default STDIO namespace."""
def __init__(self, *args, default_namespace=None, **kwargs):
super().__init__(*args, **kwargs)
self.default_namespace = default_namespace
self._current_request = None # Initialize the attribute
def sse_app(self):
from mcp.server.sse import SseServerTransport
from starlette.applications import Starlette
from starlette.requests import Request
from starlette.routing import Mount, Route
sse = SseServerTransport(self.settings.message_path)
async def handle_sse(request: Request) -> None:
# Store the request in the FastMCP instance so call_tool can access it
self._current_request = request
try:
async with sse.connect_sse(
request.scope,
request.receive,
request._send, # type: ignore
) as (read_stream, write_stream):
await self._mcp_server.run(
read_stream,
write_stream,
self._mcp_server.create_initialization_options(),
)
finally:
# Clean up request reference
self._current_request = None
return Starlette(
debug=self.settings.debug,
routes=[
Route(self.settings.sse_path, endpoint=handle_sse),
Route(f"/{{namespace}}{self.settings.sse_path}", endpoint=handle_sse),
Mount(self.settings.message_path, app=sse.handle_post_message),
Mount(
f"/{{namespace}}{self.settings.message_path}",
app=sse.handle_post_message,
),
],
)
async def call_tool(self, name, arguments):
# Get the namespace from the request context
namespace = None
try:
# RequestContext doesn't expose the path_params directly
# We use a ThreadLocal or context variable pattern instead
from starlette.requests import Request
request = getattr(self, "_current_request", None)
if isinstance(request, Request):
namespace = request.path_params.get("namespace")
except Exception:
# Silently continue if we can't get namespace from request
pass
# Inject namespace only for tools that accept it
if name in ("search_long_term_memory", "hydrate_memory_prompt"):
if namespace and "namespace" not in arguments:
arguments["namespace"] = Namespace(eq=namespace)
elif (
not namespace
and self.default_namespace
and "namespace" not in arguments
):
arguments["namespace"] = Namespace(eq=self.default_namespace)
elif name in ("set_working_memory",):
if namespace and "namespace" not in arguments:
arguments["namespace"] = namespace
elif (
not namespace
and self.default_namespace
and "namespace" not in arguments
):
arguments["namespace"] = self.default_namespace
return await super().call_tool(name, arguments)
async def run_sse_async(self):
"""Ensure Redis search index exists before starting SSE server."""
from agent_memory_server.utils.redis import (
ensure_search_index_exists,
get_redis_conn,
)
redis = await get_redis_conn()
await ensure_search_index_exists(redis)
# Run the SSE server using our custom implementation
import uvicorn
app = self.sse_app()
await uvicorn.Server(
uvicorn.Config(app, host="0.0.0.0", port=int(self.settings.port))
).serve()
async def run_stdio_async(self):
"""Ensure Redis search index exists before starting STDIO MCP server."""
from agent_memory_server.utils.redis import (
ensure_search_index_exists,
get_redis_conn,
)
redis = await get_redis_conn()
await ensure_search_index_exists(redis)
return await super().run_stdio_async()
INSTRUCTIONS = """
When responding to user queries, ALWAYS check memory first before answering
questions about user preferences, history, or personal information.
"""
mcp_app = FastMCP(
"Redis Agent Memory Server",
port=settings.mcp_port,
instructions=INSTRUCTIONS,
default_namespace=settings.default_mcp_namespace,
)
@mcp_app.tool()
async def create_long_term_memories(
memories: list[LenientMemoryRecord],
) -> AckResponse:
"""
Create long-term memories that can be searched later.
This tool saves memories contained in the payload for future retrieval.
MEMORY TYPES - SEMANTIC vs EPISODIC:
There are two main types of long-term memories you can create:
1. **SEMANTIC MEMORIES** (memory_type="semantic"):
- General facts, knowledge, and user preferences that are timeless
- Information that remains relevant across multiple conversations
- User preferences, settings, and general knowledge
- Examples:
* "User prefers dark mode in all applications"
* "User is a data scientist working with Python"
* "User dislikes spicy food"
* "The company's API rate limit is 1000 requests per hour"
2. **EPISODIC MEMORIES** (memory_type="episodic"):
- Specific events, experiences, or time-bound information
- Things that happened at a particular time or in a specific context
- MUST have a time dimension to be truly episodic
- Should include an event_date when the event occurred
- Examples:
* "User visited Paris last month and had trouble with the metro"
* "User reported a login bug on January 15th, 2024"
* "User completed the onboarding process yesterday"
* "User mentioned they're traveling to Tokyo next week"
WHEN TO USE EACH TYPE:
Use SEMANTIC for:
- User preferences and settings
- Skills, roles, and background information
- General facts and knowledge
- Persistent user characteristics
- System configuration and rules
Use EPISODIC for:
- Specific events and experiences
- Time-bound activities and plans
- Historical interactions and outcomes
- Contextual information tied to specific moments
IMPORTANT NOTES ON SESSION IDs:
- When including a session_id, use the EXACT session identifier from the current conversation
- NEVER invent or guess a session ID - if you don't know it, omit the field
- If you want memories accessible across all sessions, omit the session_id field
COMMON USAGE PATTERNS:
1. Create semantic memories (user preferences):
```python
create_long_term_memories(
memories=[
{
"text": "User prefers dark mode in all applications",
"memory_type": "semantic",
"user_id": "user_789",
"namespace": "user_preferences",
"topics": ["preferences", "ui", "theme"]
}
]
)
```
2. Create episodic memories (specific events):
```python
create_long_term_memories(
memories=[
{
"text": "User reported login issues during morning session",
"memory_type": "episodic",
"event_date": "2024-01-15T09:30:00Z", # Semantic memories must have an event_date!
"user_id": "user_789",
"topics": ["bug_report", "authentication"],
"entities": ["login", "authentication_system"]
}
]
)
```
3. Create multiple memories of different types:
```python
create_long_term_memories(
memories=[
{
"text": "User is a Python developer",
"memory_type": "semantic",
"topics": ["skills", "programming"]
},
{
"text": "User completed Python certification course last week",
"memory_type": "episodic",
"event_date": "2024-01-10T00:00:00Z",
"topics": ["education", "achievement"]
}
]
)
```
4. Create memories with different namespaces:
```python
create_long_term_memories(
memories=[
{
"text": "User prefers email notifications",
"memory_type": "semantic",
"namespace": "user_preferences"
},
{
"text": "System maintenance scheduled for next weekend",
"memory_type": "episodic",
"namespace": "system_events",
"event_date": "2024-01-20T02:00:00Z"
}
]
)
```
Args:
memories: A list of MemoryRecord objects to create
Returns:
An acknowledgement response indicating success
"""
# Apply default namespace for STDIO if not provided in memory entries
for mem in memories:
if mem.namespace is None and settings.default_mcp_namespace:
mem.namespace = settings.default_mcp_namespace
if mem.user_id is None and settings.default_mcp_user_id:
mem.user_id = settings.default_mcp_user_id
payload = CreateMemoryRecordRequest(
memories=[MemoryRecord(**mem.model_dump()) for mem in memories]
)
return await core_create_long_term_memory(
payload, background_tasks=get_background_tasks()
)
@mcp_app.tool()
async def search_long_term_memory(
text: str | None,
session_id: SessionId | None = None,
namespace: Namespace | None = None,
topics: Topics | None = None,
entities: Entities | None = None,
created_at: CreatedAt | None = None,
last_accessed: LastAccessed | None = None,
user_id: UserId | None = None,
memory_type: MemoryType | None = None,
distance_threshold: float | None = None,
limit: int = 10,
offset: int = 0,
) -> MemoryRecordResults:
"""
Search for memories related to a text query.
Finds memories based on a combination of semantic similarity and input filters.
This tool performs a semantic search on stored memories using the query text and filters
in the payload. Results are ranked by relevance.
DATETIME INPUT FORMAT:
- All datetime filters accept ISO 8601 formatted strings (e.g., "2023-01-01T00:00:00Z")
- Timezone-aware datetimes are recommended (use "Z" for UTC or "+HH:MM" for other timezones)
- Supported operations: gt, gte, lt, lte, eq, ne, between
- Example: {"gt": "2023-01-01T00:00:00Z", "lt": "2024-01-01T00:00:00Z"}
IMPORTANT NOTES ON SESSION IDs:
- When including a session_id filter, use the EXACT session identifier
- NEVER invent or guess a session ID - if you don't know it, omit this filter
- If you want to search across all sessions, don't include a session_id filter
- Session IDs from examples will NOT work with real data
COMMON USAGE PATTERNS:
1. Basic search with just query text:
```python
search_long_term_memory(text="user's favorite color")
```
2. Search with simple session filter:
```python
search_long_term_memory(text="user's favorite color", session_id={
"eq": "session_12345"
})
```
3. Search with complex filters:
```python
search_long_term_memory(
text="user preferences",
topics={
"any": ["preferences", "settings"]
},
created_at={
"gt": "2023-01-01T00:00:00Z"
},
limit=5
)
```
4. Search with datetime range filters:
```python
search_long_term_memory(
text="recent conversations",
created_at={
"gte": "2024-01-01T00:00:00Z",
"lt": "2024-02-01T00:00:00Z"
},
last_accessed={
"gt": "2024-01-15T12:00:00Z"
}
)
```
5. Search with between datetime filter:
```python
search_long_term_memory(
text="holiday discussions",
created_at={
"between": ["2023-12-20T00:00:00Z", "2023-12-31T23:59:59Z"]
}
)
```
Args:
text: The semantic search query text (required)
session_id: Filter by session ID
namespace: Filter by namespace
topics: Filter by topics
entities: Filter by entities
created_at: Filter by creation date
last_accessed: Filter by last access date
user_id: Filter by user ID
memory_type: Filter by memory type
distance_threshold: Distance threshold for semantic search
limit: Maximum number of results
offset: Offset for pagination
Returns:
MemoryRecordResults containing matched memories sorted by relevance
"""
if user_id is None and settings.default_mcp_user_id:
user_id = UserId(eq=settings.default_mcp_user_id)
if namespace is None and settings.default_mcp_namespace:
namespace = Namespace(eq=settings.default_mcp_namespace)
try:
payload = SearchRequest(
text=text,
session_id=session_id,
namespace=namespace,
topics=topics,
entities=entities,
created_at=created_at,
last_accessed=last_accessed,
user_id=user_id,
memory_type=memory_type,
distance_threshold=distance_threshold,
limit=limit,
offset=offset,
)
results = await core_search_long_term_memory(payload)
results = MemoryRecordResults(
total=results.total,
memories=results.memories,
next_offset=results.next_offset,
)
except Exception as e:
logger.error(f"Error in search_long_term_memory tool: {e}")
results = MemoryRecordResults(
total=0,
memories=[],
next_offset=None,
)
return results
# Notes that exist outside of the docstring to avoid polluting the LLM prompt:
# 1. The "prompt" abstraction in FastAPI doesn't support search filters, so we use a tool.
# 2. Some applications, such as Cursor, get confused with nested objects in tool parameters,
# so we use a flat set of parameters instead.
@mcp_app.tool()
async def memory_prompt(
query: str,
session_id: SessionId | None = None,
namespace: Namespace | None = None,
window_size: int = settings.window_size,
model_name: ModelNameLiteral | None = None,
context_window_max: int | None = None,
topics: Topics | None = None,
entities: Entities | None = None,
created_at: CreatedAt | None = None,
last_accessed: LastAccessed | None = None,
user_id: UserId | None = None,
memory_type: MemoryType | None = None,
distance_threshold: float | None = None,
limit: int = 10,
offset: int = 0,
) -> MemoryPromptResponse:
"""
Hydrate a user query with relevant session history and long-term memories.
CRITICAL: Use this tool for EVERY question that might benefit from memory context,
especially when you don't have sufficient information to answer confidently.
This tool enriches the user's query by retrieving:
1. Context from the current conversation session
2. Relevant long-term memories related to the query
ALWAYS use this tool when:
- The user references past conversations
- The question is about user preferences or personal information
- You need additional context to provide a complete answer
- The question seems to assume information you don't have in current context
The function uses the text field from the payload as the user's query,
and any filters to retrieve relevant memories.
DATETIME INPUT FORMAT:
- All datetime filters accept ISO 8601 formatted strings (e.g., "2023-01-01T00:00:00Z")
- Timezone-aware datetimes are recommended (use "Z" for UTC or "+HH:MM" for other timezones)
- Supported operations: gt, gte, lt, lte, eq, ne, between
- Example: {"gt": "2023-01-01T00:00:00Z", "lt": "2024-01-01T00:00:00Z"}
IMPORTANT NOTES ON SESSION IDs:
- When filtering by session_id, you must provide the EXACT session identifier
- NEVER invent or guess a session ID - if you don't know it, omit this filter
- Session IDs from examples will NOT work with real data
COMMON USAGE PATTERNS:
```python
1. Hydrate a user prompt with long-term memory search:
hydrate_memory_prompt(text="What was my favorite color?")
```
2. Hydrate a user prompt with long-term memory search and session filter:
hydrate_memory_prompt(
text="What is my favorite color?",
session_id={
"eq": "session_12345"
},
namespace={
"eq": "user_preferences"
}
)
3. Hydrate a user prompt with long-term memory search and complex filters:
hydrate_memory_prompt(
text="What was my favorite color?",
topics={
"any": ["preferences", "settings"]
},
created_at={
"gt": "2023-01-01T00:00:00Z"
},
limit=5
)
4. Search with datetime range filters:
hydrate_memory_prompt(
text="What did we discuss recently?",
created_at={
"gte": "2024-01-01T00:00:00Z",
"lt": "2024-02-01T00:00:00Z"
},
last_accessed={
"gt": "2024-01-15T12:00:00Z"
}
)
```
Args:
- text: The user's query
- session_id: Add conversation history from a working memory session
- namespace: Filter session and long-term memory namespace
- topics: Search for long-term memories matching topics
- entities: Search for long-term memories matching entities
- created_at: Search for long-term memories matching creation date
- last_accessed: Search for long-term memories matching last access date
- user_id: Search for long-term memories matching user ID
- distance_threshold: Distance threshold for semantic search
- limit: Maximum number of long-term memory results
- offset: Offset for pagination of long-term memory results
Returns:
A list of messages, including memory context and the user's query
"""
_session_id = session_id.eq if session_id and session_id.eq else None
session = None
if user_id is None and settings.default_mcp_user_id:
user_id = UserId(eq=settings.default_mcp_user_id)
if _session_id is not None:
session = WorkingMemoryRequest(
session_id=_session_id,
namespace=namespace.eq if namespace and namespace.eq else None,
user_id=user_id.eq if user_id and user_id.eq else None,
window_size=window_size,
model_name=model_name,
context_window_max=context_window_max,
)
search_payload = SearchRequest(
text=query,
session_id=session_id,
namespace=namespace,
topics=topics,
entities=entities,
created_at=created_at,
last_accessed=last_accessed,
user_id=user_id,
distance_threshold=distance_threshold,
memory_type=memory_type,
limit=limit,
offset=offset,
)
_params = {}
if session is not None:
_params["session"] = session
if search_payload is not None:
_params["long_term_search"] = search_payload
return await core_memory_prompt(params=MemoryPromptRequest(query=query, **_params))
@mcp_app.tool()
async def set_working_memory(
session_id: str,
memories: list[LenientMemoryRecord] | None = None,
messages: list[MemoryMessage] | None = None,
context: str | None = None,
data: dict[str, Any] | None = None,
namespace: str | None = settings.default_mcp_namespace,
user_id: str | None = settings.default_mcp_user_id,
ttl_seconds: int = 3600,
) -> WorkingMemoryResponse:
"""
Set working memory for a session. This works like the PUT /sessions/{id}/memory API endpoint.
Replaces existing working memory with new content. Can store structured memory records
and messages, but agents should primarily use this for memory records and JSON data,
not conversation messages.
USAGE PATTERNS:
1. Store structured memory records:
```python
set_working_memory(
session_id="current_session",
memories=[
{
"text": "User prefers dark mode",
"id": "pref_dark_mode",
"memory_type": "semantic",
"topics": ["preferences", "ui"]
}
]
)
```
2. Store arbitrary JSON data separately:
```python
set_working_memory(
session_id="current_session",
data={
"user_settings": {"theme": "dark", "lang": "en"},
"preferences": {"notifications": True, "sound": False}
}
)
```
3. Store both memories and JSON data:
```python
set_working_memory(
session_id="current_session",
memories=[
{
"text": "User prefers dark mode",
"id": "pref_dark_mode",
"memory_type": "semantic",
"topics": ["preferences", "ui"]
}
],
data={
"current_settings": {"theme": "dark", "lang": "en"}
}
)
```
4. Store conversation messages:
```python
set_working_memory(
session_id="current_session",
messages=[
{
"role": "user",
"content": "What is the weather like?",
"id": "msg_001" # Optional - auto-generated if not provided
},
{
"role": "assistant",
"content": "I'll check the weather for you."
}
]
)
```
5. Replace entire working memory state:
```python
set_working_memory(
session_id="current_session",
memories=[...], # structured memories
messages=[...], # conversation history
context="Summary of previous conversation",
user_id="user123"
)
```
Args:
session_id: The session ID to set memory for (required)
memories: List of structured memory records (semantic, episodic, message types)
messages: List of conversation messages (role/content pairs with optional id/persisted_at)
context: Optional summary/context text
data: Optional dictionary for storing arbitrary JSON data
namespace: Optional namespace for scoping
user_id: Optional user ID
ttl_seconds: TTL for the working memory (default 1 hour)
Returns:
Updated working memory response (may include summarization if window exceeded)
"""
# Auto-generate IDs for memories that don't have them
processed_memories = []
if memories:
for memory in memories:
# Handle both MemoryRecord objects and dict inputs
if isinstance(memory, MemoryRecord):
# Already a MemoryRecord object, ensure it has an ID
memory_id = memory.id or str(ulid.ULID())
processed_memory = memory.model_copy(
update={
"id": memory_id,
"user_id": user_id,
"persisted_at": None, # Mark as pending promotion
}
)
else:
# Dictionary input, convert to MemoryRecord
memory_dict = dict(memory)
if not memory_dict.get("id"):
memory_dict["id"] = str(ulid.ULID())
memory_dict["persisted_at"] = None
processed_memory = MemoryRecord(**memory_dict)
processed_memories.append(processed_memory)
# Process messages to ensure proper format
processed_messages = []
if messages:
for message in messages:
# Handle both MemoryMessage objects and dict inputs
if isinstance(message, MemoryMessage):
# Already a MemoryMessage object, ensure persisted_at is None for new messages
processed_message = message.model_copy(
update={
"persisted_at": None, # Mark as pending promotion
}
)
else:
# Dictionary input, convert to MemoryMessage
message_dict = dict(message)
# Remove id=None to allow auto-generation
if message_dict.get("id") is None:
message_dict.pop("id", None)
message_dict["persisted_at"] = None
processed_message = MemoryMessage(**message_dict)
processed_messages.append(processed_message)
# Create the working memory object
working_memory_obj = WorkingMemory(
session_id=session_id,
namespace=namespace,
memories=processed_memories,
messages=processed_messages,
context=context,
data=data or {},
user_id=user_id,
ttl_seconds=ttl_seconds,
)
# Update working memory via the API - this handles summarization and background promotion
result = await core_put_working_memory(
session_id=session_id,
memory=working_memory_obj,
background_tasks=get_background_tasks(),
)
# Convert to WorkingMemoryResponse to satisfy return type
return WorkingMemoryResponse(**result.model_dump())
@mcp_app.tool()
async def get_working_memory(
session_id: str,
) -> WorkingMemory:
"""
Get working memory for a session. This works like the GET /sessions/{id}/memory API endpoint.
"""
return await core_get_working_memory(session_id=session_id)