Skip to content

Commit 6601162

Browse files
authored
Fix agent endpoint (#1981)
1 parent 4575485 commit 6601162

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

py/core/main/api/v3/retrieval_router.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ async def stream_generator():
418418
return response
419419

420420
@self.router.post(
421-
"/retrieval/rag_agent",
421+
"/retrieval/agent",
422422
dependencies=[Depends(self.rate_limit_dependency)],
423423
summary="RAG-powered Conversational Agent",
424424
openapi_extra={

py/core/main/services/retrieval_service.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def convert_nonserializable_objects(obj):
6060
new_obj = {}
6161
for key, value in obj.items():
6262
# Convert key to string if it is a UUID or not already a string.
63-
new_key = str(key) if not isinstance(key, str) else key
63+
new_key = key if isinstance(key, str) else str(key)
6464
new_obj[new_key] = convert_nonserializable_objects(value)
6565
return new_obj
6666
elif isinstance(obj, list):
@@ -104,10 +104,8 @@ def dump_collector(collector: SearchResultsCollector) -> list[dict[str, Any]]:
104104

105105
def tokens_count_for_message(message, encoding):
106106
"""Return the number of tokens used by a single message."""
107-
tokens_per_message = 3
107+
num_tokens = 3
108108

109-
num_tokens = 0
110-
num_tokens += tokens_per_message
111109
if message.get("function_call"):
112110
num_tokens += len(encoding.encode(message["function_call"]["name"]))
113111
num_tokens += len(
@@ -1136,8 +1134,8 @@ def _parse_user_and_collection_filters(
11361134
filters: dict[str, Any],
11371135
):
11381136
### TODO - Come up with smarter way to extract owner / collection ids for non-admin
1139-
filter_starts_with_and = filters.get("$and", None)
1140-
filter_starts_with_or = filters.get("$or", None)
1137+
filter_starts_with_and = filters.get("$and")
1138+
filter_starts_with_or = filters.get("$or")
11411139
if filter_starts_with_and:
11421140
try:
11431141
filter_starts_with_and_then_or = filter_starts_with_and[0][
@@ -1262,8 +1260,15 @@ async def _build_aware_system_instruction(
12621260
else self.config.agent.agent_static_prompt
12631261
)
12641262

1263+
# TODO: This should just be enforced in the config
1264+
if model is None:
1265+
raise R2RException(
1266+
status_code=400,
1267+
message="Model not provided for system instruction",
1268+
)
1269+
12651270
if ("gemini" in model or "claude" in model) and reasoning_agent:
1266-
prompt_name = prompt_name + "_prompted_reasoning"
1271+
prompt_name = f"{prompt_name}_prompted_reasoning"
12671272

12681273
if use_system_context or reasoning_agent:
12691274
doc_context_str = await self._build_documents_context(

0 commit comments

Comments
 (0)