Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions backend/src/agents/retriever_rag.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def rag_initialize(self) -> None:
self.tool_descriptions = ""
for tool in self.tools:
text_desc = render_text_description([tool])
text_desc.replace("(query: str) -> Tuple[str, list[str], list[str]]", " ")
text_desc = text_desc.replace("(query: str) -> Tuple[str, list[str], list[str]]", " ")
self.tool_descriptions += text_desc + "\n\n"

def rag_agent(self, state: AgentState) -> dict[str, list[Any]]:
Expand Down Expand Up @@ -159,12 +159,14 @@ def rag_agent(self, state: AgentState) -> dict[str, list[Any]]:
)
return {"tools": []}

tool_calls: list[str] = []
if "tool_names" in str(response):
tool_calls = response.get("tool_names", []) # type: ignore
for tool in tool_calls:
if tool not in self.tool_names:
raw_tool_calls = response.get("tool_names", []) # type: ignore
for tool in raw_tool_calls:
if tool in self.tool_names:
tool_calls.append(tool)
else:
logging.warning(f"Tool {tool} not found in tool list.")
tool_calls.remove(tool)
else:
logging.warning(str(response))
logging.warning("Tool selection failed. Returning empty tool list.")
Expand Down
11 changes: 9 additions & 2 deletions backend/src/api/routers/conversations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import logging
from collections import OrderedDict
from dotenv import load_dotenv

from typing import Any
Expand Down Expand Up @@ -217,7 +218,9 @@ def parse_agent_output(output: list) -> tuple[str, list[ContextSource], list[str
rg.initialize()


chat_history: dict[UUID, list[dict[str, str]]] = {}
MAX_IN_MEMORY_CONVERSATIONS = 1000

chat_history: OrderedDict[UUID, list[dict[str, str]]] = OrderedDict()


def get_history_str(db: Session | None, conversation_uuid: UUID | None) -> str:
Expand Down Expand Up @@ -274,6 +277,8 @@ async def get_agent_response(

conversation_uuid = uuid4()
if conversation_uuid not in chat_history:
if len(chat_history) >= MAX_IN_MEMORY_CONVERSATIONS:
chat_history.popitem(last=False)
chat_history[conversation_uuid] = []

inputs = {
Expand Down Expand Up @@ -369,6 +374,8 @@ async def get_response_stream(user_input: UserInput, db: Session | None) -> Any:

conversation_uuid = uuid4()
if conversation_uuid not in chat_history:
if len(chat_history) >= MAX_IN_MEMORY_CONVERSATIONS:
chat_history.popitem(last=False)
chat_history[conversation_uuid] = []

inputs = {
Expand Down Expand Up @@ -405,7 +412,7 @@ async def get_response_stream(user_input: UserInput, db: Session | None) -> Any:

if msg:
chunks.append(str(msg))
yield str(msg) + "\n\n"
yield str(msg) + "\n\n"

urls = list(set(urls))
yield f"Sources: {', '.join(urls)}\n\n"
Expand Down