Skip to content

Commit c630963

Browse files
authored
fix(rag): improve rag error message when docling is not enabled (#1432)
Signed-off-by: Radek Ježek <[email protected]>
1 parent 9f8e2be commit c630963

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

agents/rag/src/rag/helpers/vectore_store.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ async def extract_file(file: File) -> None:
5555
extraction = await file.get_extraction()
5656
final_status = extraction.status
5757
if final_status == "failed":
58-
raise RuntimeError(f"Extraction for file {file_id} has failed: {extraction.model_dump_json()}")
58+
raise RuntimeError(
59+
f"Extraction for file {file.filename} has failed. \n"
60+
f"Make sure you have docling enabled (`agentstack start --set docling.enabled=true`)"
61+
)
5962
if final_status != "completed":
6063
raise TimeoutError("Text extraction is not finished yet")
6164

apps/agentstack-sdk-py/src/agentstack_sdk/server/agent.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import asyncio
55
import inspect
6+
import json
67
from asyncio import CancelledError
78
from collections.abc import AsyncGenerator, AsyncIterator, Callable, Generator
89
from contextlib import AbstractAsyncContextManager, AsyncExitStack, asynccontextmanager
@@ -43,6 +44,7 @@
4344
from agentstack_sdk.server.logging import logger
4445
from agentstack_sdk.server.store.context_store import ContextStore
4546
from agentstack_sdk.server.utils import cancel_task, close_queue
47+
from agentstack_sdk.util.utils import extract_messages
4648

4749
AgentFunction: TypeAlias = Callable[[], AsyncGenerator[RunYield, RunYieldResume]]
4850
AgentFunctionFactory: TypeAlias = Callable[
@@ -453,7 +455,8 @@ def with_context(message: Message | None = None) -> Message | None:
453455
await task_updater.cancel()
454456
except Exception as ex:
455457
logger.error("Error when executing agent", exc_info=ex)
456-
await task_updater.failed(task_updater.new_agent_message(parts=[Part(root=TextPart(text=str(ex)))]))
458+
msg = json.dumps(extract_messages(ex), indent=2)
459+
await task_updater.failed(task_updater.new_agent_message(parts=[Part(root=TextPart(text=msg))]))
457460
finally: # cleanup
458461
await cancel_task(cancellation_task)
459462
is_cancelling = bool(current_task.cancelling())

apps/agentstack-sdk-py/src/agentstack_sdk/util/utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,10 @@ async def parse_stream(response: httpx.Response) -> AsyncIterator[dict[str, Any]
2929
async for line in response.aiter_lines():
3030
if line:
3131
yield json.loads(re.sub("^data:", "", line).strip())
32+
33+
34+
def extract_messages(exc: BaseException) -> list[tuple[str, str]]:
35+
if isinstance(exc, BaseExceptionGroup):
36+
return [(exc_type, msg) for e in exc.exceptions for exc_type, msg in extract_messages(e)]
37+
else:
38+
return [(type(exc).__name__, str(exc))]

0 commit comments

Comments
 (0)