Skip to content

Commit 9530572

Browse files
committed
fix: postgres chat history in conversational agent
1 parent 7ee22a3 commit 9530572

File tree

2 files changed

+8
-24
lines changed

2 files changed

+8
-24
lines changed

apps/server/agents/conversational/conversational.py

-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ def run(
2626
prompt: str,
2727
history: PostgresChatMessageHistory,
2828
human_message_id: str,
29-
run_id: UUID,
30-
sender_user_id: str,
3129
run_logs_manager: RunLogsManager,
3230
pre_retrieved_context: str,
3331
):

apps/server/services/chat.py

+8-22
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ def process_chat_message(
211211
settings=settings,
212212
team_id=team_id,
213213
parent_id=parent_id,
214+
history=history,
214215
run_id=run.id,
215216
run_logs_manager=run_logs_manager,
216217
)
@@ -527,31 +528,20 @@ def run_conversational_agent(
527528
settings: AccountSettings,
528529
run_id: UUID,
529530
run_logs_manager: RunLogsManager,
531+
history: PostgresChatMessageHistory,
530532
team_id: Optional[UUID] = None,
531533
parent_id: Optional[UUID] = None,
532534
):
533-
history = PostgresChatMessageHistory(
534-
session_id=session_id,
535-
sender_account_id=sender_account_id,
536-
sender_user_id=sender_user_id,
537-
sender_name=sender_name,
538-
parent_id=parent_id,
539-
team_id=team_id,
540-
agent_id=agent_with_configs.agent.id,
541-
chat_id=None,
542-
run_id=run_id,
543-
)
544-
545-
datasources = (
535+
data_sources = (
546536
db.session.query(DatasourceModel)
547537
.filter(DatasourceModel.id.in_(agent_with_configs.configs.datasources))
548538
.all()
549539
)
550540

551541
tool_callback_handler = run_logs_manager.get_tool_callback_handler()
552542

553-
datasource_tools = get_datasource_tools(
554-
datasources,
543+
data_source_tools = get_datasource_tools(
544+
data_sources,
555545
settings,
556546
provider_account,
557547
agent_with_configs,
@@ -570,12 +560,12 @@ def run_conversational_agent(
570560
pre_retrieved_context = ""
571561

572562
if agent_with_configs.configs.source_flow == DataSourceFlow.PRE_RETRIEVAL.value:
573-
if len(datasource_tools) != 0:
574-
pre_retrieved_context = datasource_tools[0]._run(prompt)
563+
if len(data_source_tools) != 0:
564+
pre_retrieved_context = data_source_tools[0]._run(prompt)
575565

576566
tools = agent_tools
577567
else:
578-
tools = datasource_tools + agent_tools
568+
tools = data_source_tools + agent_tools
579569

580570
conversational = ConversationalAgent(sender_name, provider_account, session_id)
581571
return conversational.run(
@@ -586,17 +576,13 @@ def run_conversational_agent(
586576
prompt,
587577
history,
588578
human_message_id,
589-
run_id,
590-
sender_user_id,
591579
run_logs_manager,
592580
pre_retrieved_context,
593581
)
594582

595583

596584
def create_and_send_chat_message(
597585
session_id: str,
598-
# account: AccountModel,
599-
# sender_user: UserModel,
600586
sender_name: str,
601587
sender_user_id: str,
602588
sender_account_id: str,

0 commit comments

Comments
 (0)