ragflow/api/apps
0xsatoshi99 697f8138b6 feat: add trace logging for agent completions API (Issue #10081)
Implement comprehensive trace logging system for agent execution that
returns step-by-step execution traces in API responses.

New modules:
- agent/trace/trace_models.py: Data models for trace events, sessions,
  LLM calls, retrievals, and tool calls
- agent/trace/trace_collector.py: Real-time trace event collection with
  subscriber pattern for streaming
- agent/trace/trace_formatter.py: Multiple formatters (streaming, compact,
  detailed) for different output needs
- api/db/services/trace_service.py: Service layer for trace persistence,
  retrieval, and analysis
- api/apps/trace_app.py: REST API endpoints for trace management

Features:
- Real-time trace streaming via SSE
- Multiple trace verbosity levels (minimal, standard, detailed, debug)
- Component execution timing and bottleneck detection
- LLM call tracking with token counts
- Retrieval operation logging with chunk details
- Tool call tracing with arguments and results
- Trace session persistence in Redis
- Analysis and recommendations based on trace data

API Endpoints:
- GET /traces - List trace sessions
- GET /traces/<task_id> - Get trace session
- GET /traces/<task_id>/events - Get filtered events
- GET /traces/<task_id>/summary - Get trace summary
- GET /traces/<task_id>/analysis - Analyze trace
- GET /traces/<task_id>/stream - Stream trace events
- DELETE /traces/<task_id> - Delete trace
- POST /traces/cleanup - Cleanup old traces
- POST /agents/<agent_id>/completions/trace - Completion with trace

Closes #10081
2025-12-03 18:08:14 +01:00
..
auth Refa: make RAGFlow more asynchronous (#11601) 2025-12-01 14:24:06 +08:00
sdk Update since 'File manager' is renamed to 'File' (#11698) 2025-12-03 18:32:15 +08:00
__init__.py Refa: make RAGFlow more asynchronous (#11601) 2025-12-01 14:24:06 +08:00
api_app.py Refa: make RAGFlow more asynchronous (#11601) 2025-12-01 14:24:06 +08:00
canvas_app.py Refa: make RAGFlow more asynchronous (#11601) 2025-12-01 14:24:06 +08:00
chunk_app.py Refa: make RAGFlow more asynchronous 2 (#11689) 2025-12-03 14:19:53 +08:00
connector_app.py Refa: make RAGFlow more asynchronous 2 (#11689) 2025-12-03 14:19:53 +08:00
conversation_app.py Refa: make RAGFlow more asynchronous 2 (#11689) 2025-12-03 14:19:53 +08:00
dialog_app.py Refa: make RAGFlow more asynchronous (#11601) 2025-12-01 14:24:06 +08:00
document_app.py Refa: make RAGFlow more asynchronous 2 (#11689) 2025-12-03 14:19:53 +08:00
evaluation_app.py Feat: RAG evaluation (#11674) 2025-12-03 17:00:58 +08:00
file2document_app.py Fix: file manager KB link issue. (#11648) 2025-12-02 12:14:27 +08:00
file_app.py Refa: make RAGFlow more asynchronous 2 (#11689) 2025-12-03 14:19:53 +08:00
kb_app.py Refa: make RAGFlow more asynchronous 2 (#11689) 2025-12-03 14:19:53 +08:00
langfuse_app.py Refa: make RAGFlow more asynchronous (#11601) 2025-12-01 14:24:06 +08:00
llm_app.py Refa: make RAGFlow more asynchronous (#11601) 2025-12-01 14:24:06 +08:00
mcp_server_app.py Refa: make RAGFlow more asynchronous (#11601) 2025-12-01 14:24:06 +08:00
plugin_app.py Feat: Alter flask to Quart for async API serving. (#11275) 2025-11-18 17:05:16 +08:00
search_app.py Refa: make RAGFlow more asynchronous (#11601) 2025-12-01 14:24:06 +08:00
system_app.py Feat: Alter flask to Quart for async API serving. (#11275) 2025-11-18 17:05:16 +08:00
tenant_app.py Refa: make RAGFlow more asynchronous (#11601) 2025-12-01 14:24:06 +08:00
trace_app.py feat: add trace logging for agent completions API (Issue #10081) 2025-12-03 18:08:14 +01:00
user_app.py Refa: make RAGFlow more asynchronous (#11601) 2025-12-01 14:24:06 +08:00