|
37 | 37 |
|
38 | 38 | # Updated import for KernelArguments |
39 | 39 | from common.utils.utils_kernel import ( |
40 | | - initialize_runtime_and_context, |
41 | 40 | rai_success, |
42 | 41 | ) |
43 | 42 |
|
| 43 | +from common.database.database_factory import DatabaseFactory |
44 | 44 | from v3.api.router import app_v3 |
45 | 45 |
|
46 | 46 | # Check if the Application Insights Instrumentation Key is set in the environment variables |
@@ -223,9 +223,7 @@ async def input_task_endpoint(input_task: InputTask, request: Request): |
223 | 223 | try: |
224 | 224 | # Create all agents instead of just the planner agent |
225 | 225 | # This ensures other agents are created first and the planner has access to them |
226 | | - kernel, memory_store = await initialize_runtime_and_context( |
227 | | - input_task.session_id, user_id |
228 | | - ) |
| 226 | + memory_store = await DatabaseFactory.get_database(user_id=user_id) |
229 | 227 | client = None |
230 | 228 | try: |
231 | 229 | client = config.get_ai_project_client() |
@@ -368,9 +366,7 @@ async def human_feedback_endpoint(human_feedback: HumanFeedback, request: Reques |
368 | 366 | ) |
369 | 367 | raise HTTPException(status_code=400, detail="no user") |
370 | 368 |
|
371 | | - kernel, memory_store = await initialize_runtime_and_context( |
372 | | - human_feedback.session_id, user_id |
373 | | - ) |
| 369 | + memory_store = await DatabaseFactory.get_database(user_id=user_id) |
374 | 370 |
|
375 | 371 | client = None |
376 | 372 | try: |
@@ -501,9 +497,7 @@ async def human_clarification_endpoint( |
501 | 497 | ) |
502 | 498 | raise HTTPException(status_code=400, detail="no user") |
503 | 499 |
|
504 | | - kernel, memory_store = await initialize_runtime_and_context( |
505 | | - human_clarification.session_id, user_id |
506 | | - ) |
| 500 | + memory_store = await DatabaseFactory.get_database(user_id=user_id) |
507 | 501 | client = None |
508 | 502 | try: |
509 | 503 | client = config.get_ai_project_client() |
@@ -615,9 +609,7 @@ async def approve_step_endpoint( |
615 | 609 | raise HTTPException(status_code=400, detail="no user") |
616 | 610 |
|
617 | 611 | # Get the agents for this session |
618 | | - kernel, memory_store = await initialize_runtime_and_context( |
619 | | - human_feedback.session_id, user_id |
620 | | - ) |
| 612 | + memory_store = await DatabaseFactory.get_database(user_id=user_id) |
621 | 613 | client = None |
622 | 614 | try: |
623 | 615 | client = config.get_ai_project_client() |
@@ -733,10 +725,7 @@ async def get_plans( |
733 | 725 | raise HTTPException(status_code=400, detail="no user") |
734 | 726 |
|
735 | 727 | # Initialize memory context |
736 | | - kernel, memory_store = await initialize_runtime_and_context( |
737 | | - session_id or "", user_id |
738 | | - ) |
739 | | - |
| 728 | + memory_store = await DatabaseFactory.get_database(user_id=user_id) |
740 | 729 | if session_id: |
741 | 730 | plan = await memory_store.get_plan_by_session(session_id=session_id) |
742 | 731 | if not plan: |
@@ -851,7 +840,7 @@ async def get_steps_by_plan(plan_id: str, request: Request) -> List[Step]: |
851 | 840 | raise HTTPException(status_code=400, detail="no user") |
852 | 841 |
|
853 | 842 | # Initialize memory context |
854 | | - kernel, memory_store = await initialize_runtime_and_context("", user_id) |
| 843 | + memory_store = await DatabaseFactory.get_database(user_id=user_id) |
855 | 844 | steps = await memory_store.get_steps_for_plan(plan_id=plan_id) |
856 | 845 | return steps |
857 | 846 |
|
@@ -917,175 +906,11 @@ async def get_agent_messages(session_id: str, request: Request) -> List[AgentMes |
917 | 906 | raise HTTPException(status_code=400, detail="no user") |
918 | 907 |
|
919 | 908 | # Initialize memory context |
920 | | - kernel, memory_store = await initialize_runtime_and_context( |
921 | | - session_id or "", user_id |
922 | | - ) |
| 909 | + memory_store = await DatabaseFactory.get_database(user_id=user_id) |
923 | 910 | agent_messages = await memory_store.get_data_by_type("agent_message") |
924 | 911 | return agent_messages |
925 | 912 |
|
926 | 913 |
|
927 | | -@app.get("/api/agent_messages_by_plan/{plan_id}", response_model=List[AgentMessage]) |
928 | | -async def get_agent_messages_by_plan( |
929 | | - plan_id: str, request: Request |
930 | | -) -> List[AgentMessage]: |
931 | | - """ |
932 | | - Retrieve agent messages for a specific session. |
933 | | -
|
934 | | - --- |
935 | | - tags: |
936 | | - - Agent Messages |
937 | | - parameters: |
938 | | - - name: session_id |
939 | | - in: path |
940 | | - type: string |
941 | | - required: true |
942 | | - in: path |
943 | | - type: string |
944 | | - required: true |
945 | | - description: The ID of the session to retrieve agent messages for |
946 | | - responses: |
947 | | - 200: |
948 | | - description: List of agent messages associated with the specified session |
949 | | - schema: |
950 | | - type: array |
951 | | - items: |
952 | | - type: object |
953 | | - properties: |
954 | | - id: |
955 | | - type: string |
956 | | - description: Unique ID of the agent message |
957 | | - session_id: |
958 | | - type: string |
959 | | - description: Session ID associated with the message |
960 | | - plan_id: |
961 | | - type: string |
962 | | - description: Plan ID related to the agent message |
963 | | - content: |
964 | | - type: string |
965 | | - description: Content of the message |
966 | | - source: |
967 | | - type: string |
968 | | - description: Source of the message (e.g., agent type) |
969 | | - timestamp: |
970 | | - type: string |
971 | | - format: date-time |
972 | | - description: Timestamp of the message |
973 | | - step_id: |
974 | | - type: string |
975 | | - description: Optional step ID associated with the message |
976 | | - 400: |
977 | | - description: Missing or invalid user information |
978 | | - 404: |
979 | | - description: Agent messages not found |
980 | | - """ |
981 | | - authenticated_user = get_authenticated_user_details(request_headers=request.headers) |
982 | | - user_id = authenticated_user["user_principal_id"] |
983 | | - if not user_id: |
984 | | - track_event_if_configured( |
985 | | - "UserIdNotFound", {"status_code": 400, "detail": "no user"} |
986 | | - ) |
987 | | - raise HTTPException(status_code=400, detail="no user") |
988 | | - |
989 | | - # Initialize memory context |
990 | | - kernel, memory_store = await initialize_runtime_and_context("", user_id) |
991 | | - agent_messages = await memory_store.get_data_by_type_and_plan_id("agent_message") |
992 | | - return agent_messages |
993 | | - |
994 | | - |
995 | | -@app.delete("/api/messages") |
996 | | -async def delete_all_messages(request: Request) -> Dict[str, str]: |
997 | | - """ |
998 | | - Delete all messages across sessions. |
999 | | -
|
1000 | | - --- |
1001 | | - tags: |
1002 | | - - Messages |
1003 | | - responses: |
1004 | | - 200: |
1005 | | - description: Confirmation of deletion |
1006 | | - schema: |
1007 | | - type: object |
1008 | | - properties: |
1009 | | - status: |
1010 | | - type: string |
1011 | | - description: Status message indicating all messages were deleted |
1012 | | - 400: |
1013 | | - description: Missing or invalid user information |
1014 | | - """ |
1015 | | - authenticated_user = get_authenticated_user_details(request_headers=request.headers) |
1016 | | - user_id = authenticated_user["user_principal_id"] |
1017 | | - if not user_id: |
1018 | | - track_event_if_configured( |
1019 | | - "UserIdNotFound", {"status_code": 400, "detail": "no user"} |
1020 | | - ) |
1021 | | - raise HTTPException(status_code=400, detail="no user") |
1022 | | - |
1023 | | - # Initialize memory context |
1024 | | - kernel, memory_store = await initialize_runtime_and_context("", user_id) |
1025 | | - |
1026 | | - await memory_store.delete_all_items("plan") |
1027 | | - await memory_store.delete_all_items("session") |
1028 | | - await memory_store.delete_all_items("step") |
1029 | | - await memory_store.delete_all_items("agent_message") |
1030 | | - |
1031 | | - # Clear the agent factory cache |
1032 | | - AgentFactory.clear_cache() |
1033 | | - |
1034 | | - return {"status": "All messages deleted"} |
1035 | | - |
1036 | | - |
1037 | | -@app.get("/api/messages") |
1038 | | -async def get_all_messages(request: Request): |
1039 | | - """ |
1040 | | - Retrieve all messages across sessions. |
1041 | | -
|
1042 | | - --- |
1043 | | - tags: |
1044 | | - - Messages |
1045 | | - responses: |
1046 | | - 200: |
1047 | | - description: List of all messages across sessions |
1048 | | - schema: |
1049 | | - type: array |
1050 | | - items: |
1051 | | - type: object |
1052 | | - properties: |
1053 | | - id: |
1054 | | - type: string |
1055 | | - description: Unique ID of the message |
1056 | | - data_type: |
1057 | | - type: string |
1058 | | - description: Type of the message (e.g., session, step, plan, agent_message) |
1059 | | - session_id: |
1060 | | - type: string |
1061 | | - description: Session ID associated with the message |
1062 | | - user_id: |
1063 | | - type: string |
1064 | | - description: User ID associated with the message |
1065 | | - content: |
1066 | | - type: string |
1067 | | - description: Content of the message |
1068 | | - timestamp: |
1069 | | - type: string |
1070 | | - format: date-time |
1071 | | - description: Timestamp of the message |
1072 | | - 400: |
1073 | | - description: Missing or invalid user information |
1074 | | - """ |
1075 | | - authenticated_user = get_authenticated_user_details(request_headers=request.headers) |
1076 | | - user_id = authenticated_user["user_principal_id"] |
1077 | | - if not user_id: |
1078 | | - track_event_if_configured( |
1079 | | - "UserIdNotFound", {"status_code": 400, "detail": "no user"} |
1080 | | - ) |
1081 | | - raise HTTPException(status_code=400, detail="no user") |
1082 | | - |
1083 | | - # Initialize memory context |
1084 | | - kernel, memory_store = await initialize_runtime_and_context("", user_id) |
1085 | | - message_list = await memory_store.get_all_items() |
1086 | | - return message_list |
1087 | | - |
1088 | | - |
1089 | 914 | @app.get("/api/agent-tools") |
1090 | 915 | async def get_agent_tools(): |
1091 | 916 | """ |
|
0 commit comments