feat: add agent tool integrations, KB query tracking, and reranking support#211
feat: add agent tool integrations, KB query tracking, and reranking support#211amirasaran merged 4 commits intodevelopmentfrom
Conversation
…upport Backend: - Add `enable_as_tool`, `tool_function_name`, and `tool_description` fields to `Agent` model to support nested agent tool calling. - Create `KnowledgeBaseQuery` model and APIs to track search queries, their status, and retrieval costs. - Update `RetrievalSetting` model to include `reranker_model_config` and `retrieval_cost`. - Update billing/plan services and signals to account for knowledge base query usage. - Generate new migrations for agent and knowledge base models. - Update `poetry.lock` dependencies. Frontend: - Add `AgentFormToolConfigSection` and `useAgentToolConfig` hook to allow users to configure agents as tools. - Add new `AgentIntegrationsPage` for managing agent tool integrations. - Add `QueryLogsPage` to display knowledge base query history and statuses. - Update `KnowledgeBaseNewPage` and `RetrievalSettingsManager` to support reranker configurations. - Add pricing information components (`KnowledgeBasePricingInfo`, `RetrievalSettingPricingInfo`) for better cost transparency. - Add `fill-translations.cjs` utility script for automated translation management and update all 10 locale JSON files. - Update TypeScript types (`agent.ts`, `knowledge.ts`, `usage_history.ts`) to reflect backend schema changes. - Update App routing and DashboardLayout sidebar navigation for the new pages.
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
|||||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||||||||||||||||||||||
- Add `.windsurf/rules/snyk_rules.md` to gitignore for auto-generated Snyk security rules - Remove debug print statement from `RetrievalSetting.save()` method
…ve reliability - Add missing dependencies to useCallback and useEffect hooks in AgentFormPage and AgentDetailPage - Destructure formState and toolConfig objects to use individual state values directly - Wrap fetchAgent in useCallback with proper dependencies - Fix useVariableDetection timer callback to avoid stale closure - Add fallback to existing instance values in AgentListSerializer validation for tool_function_name and tool_description
Co-authored-by: qodo-code-review[bot] <151058649+qodo-code-review[bot]@users.noreply.github.com>
User description
Description
Backend:
enable_as_tool,tool_function_name, andtool_descriptionfields toAgentmodel to support nested agent tool calling.KnowledgeBaseQuerymodel and APIs to track search queries, their status, and retrieval costs.RetrievalSettingmodel to includereranker_model_configandretrieval_cost.poetry.lockdependencies.Frontend:
AgentFormToolConfigSectionanduseAgentToolConfighook to allow users to configure agents as tools.AgentIntegrationsPagefor managing agent tool integrations.QueryLogsPageto display knowledge base query history and statuses.KnowledgeBaseNewPageandRetrievalSettingsManagerto support reranker configurations.KnowledgeBasePricingInfo,RetrievalSettingPricingInfo) for better cost transparency.fill-translations.cjsutility script for automated translation management and update all 10 locale JSON files.agent.ts,knowledge.ts,usage_history.ts) to reflect backend schema changes.PR Type
Enhancement
Description
Add agent tool configuration support with
enable_as_tool,tool_function_name, andtool_descriptionfields to enable nested agent tool callingImplement knowledge base query tracking with
KnowledgeBaseQuerymodel to monitor search queries, their status, and retrieval costsAdd reranker model configuration support to
RetrievalSettingwith automatic cost calculationIntegrate credit validation and usage tracking for knowledge base queries through billing/plan services and signals
Create new pages for agent integrations management (
AgentIntegrationsPage) and knowledge base query logs (QueryLogsPage)Add agent API documentation component with code examples for cURL, Python, and Node.js
Implement pricing information components (
KnowledgeBasePricingInfo,RetrievalSettingPricingInfo) for cost transparencyAdd translation fill utility script and update all 10 locale JSON files (en, fr, de, it, es, pt, ar, fa, ja, zh) with new feature translations
Update TypeScript types and API endpoints to reflect backend schema changes
Enhance UI components with improved retrieval settings form, agent tool configuration UI, and disabled state support
Update app routing and dashboard navigation for new pages and features
Diagram Walkthrough
File Walkthrough
30 files
useAgentToolConfig.ts
New hook for agent tool configuration managementfrontend/src/hooks/useAgentToolConfig.ts
interactions
enableAsTool,toolFunctionName, andtoolDescriptionstatemanagement
saveToolConfigfunction to persist changes viaagentApi.update()API errors
knowledgeBase.ts
Knowledge base query API endpointsfrontend/src/services/api/knowledgeBase.ts
listQueries()method to fetch paginated knowledge base queryhistory with filtering
getQuery()method to retrieve individual query detailsstatus,page,pageSize, andknowledgeBaseUuidknowledge.ts
TypeScript types for retrieval settings and query trackingfrontend/src/types/knowledge.ts
reranker_model_configfield toRetrievalSettinginterfaceretrieval_costfield to track costs per retrievalQueryStatusenum with states: new, processing, finished, failedKnowledgeBaseQueryinterface for tracking query history with costand status
agent.ts
Agent tool configuration TypeScript typesfrontend/src/types/agent.ts
enable_as_tool,tool_function_name, andtool_descriptionfieldsto
AgentinterfaceAgentUpdateRequestwith the same three tool configurationfields
usage_history.ts
Usage history content type for knowledge base queriesfrontend/src/types/usage_history.ts
KnowledgeBaseQuerytoContentTypeenum for usage trackingindex.ts
Export agent tool config hookfrontend/src/hooks/index.ts
useAgentToolConfighookmodels.py
Knowledge base query tracking and retrieval cost modelsbackend/knowledge_base/models.py
QUERY_STATUS_NEW,QUERY_STATUS_PROCESSING,QUERY_STATUS_FINISHED,QUERY_STATUS_FAILED)reranker_model_configJSONField toRetrievalSettingmodelretrieval_costPositiveIntegerField toRetrievalSettingmodel_calculate_retrieval_cost()method to compute costs basedon provider configuration
save()method to auto-calculate retrieval cost before savingKnowledgeBaseQuerymodel to track query history with status,results count, and cost
views.py
Query tracking and credit validation in knowledge base retrievalbackend/knowledge_base/views.py
query()endpoint to createKnowledgeBaseQueryrecords fortracking
TeamPlanServiceFINISHED/FAILED)
KnowledgeBaseQueryViewSetfor listing and retrieving query historyserializers.py
Agent tool configuration validation in serializersbackend/agent/serializers.py
AgentListSerializerenable_as_toolrequiringtool_function_nameand
tool_descriptionother agents
validate_tool_agent_uuid()to verify agent is enabled as tooland published
models.py
Agent tool configuration model fieldsbackend/agent/models.py
enable_as_tool,tool_function_name, andtool_descriptionfieldsto
AgentmodelAgentAsToolcached properties to use configured tool name anddescription
name,key, anddescriptionproperties to prioritize toolconfiguration
services.py
Credit calculation for knowledge base queriesbackend/plan/services.py
KnowledgeBaseQueryhandling toget_calculat_needed_credits()method
KnowledgeBaseQueryhandling toget_actual_credits()methodserializers.py
Serializers for retrieval settings and query historybackend/knowledge_base/serializers.py
reranker_model_configandretrieval_costfields toRetrievalSettingSerializerretrieval_costread-onlyKnowledgeBaseQuerySerializerfor query history with read-onlystatus and cost fields
signals.py
Signal handler for knowledge base query credit trackingbackend/plan/signals.py
KnowledgeBaseQuerypost_save to track creditusage
FAILED
filters.py
Filter class for knowledge base query historybackend/knowledge_base/filters.py
KnowledgeBaseQueryFilterfor filtering queries by status andknowledge base UUID
RetrievalSettingForm.tsx
Improved retrieval settings form UI and embedding requirementsfrontend/src/components/knowledge/RetrievalSettingForm.tsx
then hybrid and vector search
when embeddings are not configured
sections
DashboardLayout.tsx
Added query logs navigation to dashboard layoutfrontend/src/layouts/DashboardLayout.tsx
(
/dashboard/logs/queries)MagnifyingGlassIconfor the queries navigation itemQueryLogsPage.tsx
Add knowledge base query logs page with filtering and paginationfrontend/src/pages/dashboard/QueryLogsPage.tsx
filtering by status
detail display
error messages
knowledgeBaseApi.listQueries()and breadcrumbnavigation
AgentFormHeader.tsx
Add agent tool configuration UI to form headerfrontend/src/components/agent/form/AgentFormHeader.tsx
enableAsToolfeature(only visible when agent is published)
toolFunctionNameandtoolDescriptionwith validationKnowledgeBaseNewPage.tsx
Simplify KB creation form and adjust defaultsfrontend/src/pages/dashboard/knowledge-base/KnowledgeBaseNewPage.tsx
retrieval_typefromHybridSearchtoFullTextSearchsemantic)
explanation of default values
KnowledgeBasePricingInfocomponentAgentFormPage.tsx
Integrate agent tool configuration management in formfrontend/src/pages/dashboard/AgentFormPage.tsx
useAgentToolConfighook for managing agent tool configurationstate
enable_as_tooltoggle flag changesprops to header
tempAgentobject to include tool configuration fieldsAgentIntegrationsPage.tsx
Add agent integrations page with API documentationfrontend/src/pages/dashboard/AgentIntegrationsPage.tsx
webhooks)
AgentApiDocumentationcomponentonly)
AgentFormToolConfigSection.tsx
Add agent tool configuration form section componentfrontend/src/components/agent/form/AgentFormToolConfigSection.tsx
fields
toolFunctionNameandtoolDescriptioninputs only when enabledagentUsageCount)KnowledgeBasePricingInfo.tsx
Add retrieval operation pricing display to KB pricing infofrontend/src/components/knowledge/KnowledgeBasePricingInfo.tsx
retrievalType,rerankerEnabled, and provider typesWaterCrawl providers
operations
retrievalType,rerankerEnabled,rerankerProviderTypeAgentApiDocumentation.tsx
Add agent API documentation component with code examplesfrontend/src/components/agent/AgentApiDocumentation.tsx
Node.js
parameter
language
RetrievalSettingPricingInfo.tsx
Add retrieval setting pricing information componentfrontend/src/components/knowledge/RetrievalSettingPricingInfo.tsx
retrieval settings
retrievalType,rerankerEnabled, and providertypes
message
AgentDetailPage.tsx
Update agent detail page integrations navigationfrontend/src/pages/dashboard/AgentDetailPage.tsx
integrations page
disabledstate to integrations button when agent is not published/dashboard/agents/{agentId}/integrationsrouteUsageHistoryPage.tsx
Add knowledge base query tracking to usage historyfrontend/src/pages/dashboard/UsageHistoryPage.tsx
KnowledgeBaseQuerycontent type to usage history filtersOptionCard.tsx
Add disabled state support to option card componentfrontend/src/components/shared/OptionCard.tsx
disabledprop to prevent card selectionopacity-60andcursor-not-allowedstyles when disabledAgentFormAgentToolsSection.tsx
Filter and display agent tool descriptions in agent tools sectionfrontend/src/components/agent/form/AgentFormAgentToolsSection.tsx
enable_as_tool === truetool_descriptionfrom agent if available, fallback to status labelagentToolstoagentsAsToolsRetrievalSettingsManager.tsx
Display retrieval costs in retrieval settings cardsfrontend/src/components/knowledge/RetrievalSettingsManager.tsx
retrieval_costvaluetop_k6 files
0005_knowledgebasequery.py
Database migration for knowledge base query modelbackend/knowledge_base/migrations/0005_knowledgebasequery.py
KnowledgeBaseQuerymodel with all fields andrelationships
0003_alter_apispecparameters_tool_parameter_type_and_more.py
Database migration for agent model field updatesbackend/agent/migrations/0003_alter_apispecparameters_tool_parameter_type_and_more.py
APISpecParameters,MCPServer, andMCPServerParameters0004_retrievalsetting_reranker_model_config_and_more.py
Database migration for retrieval setting enhancementsbackend/knowledge_base/migrations/0004_retrievalsetting_reranker_model_config_and_more.py
reranker_model_configandretrieval_costfields to
RetrievalSetting0004_agent_enable_as_tool_agent_tool_description_and_more.py
Database migration for agent tool configurationbackend/agent/migrations/0004_agent_enable_as_tool_agent_tool_description_and_more.py
enable_as_tool,tool_description, andtool_function_namefields toAgentmodelurls.py
URL routing for knowledge base query endpointsbackend/knowledge_base/urls.py
KnowledgeBaseQueryViewSetrouter for query historyendpoints
App.tsx
Add routes for query logs and agent integrations pagesfrontend/src/App.tsx
QueryLogsPageroute at/dashboard/logs/queriesAgentIntegrationsPageroute at/dashboard/agents/:agentId/integrations10 files
it.json
Italian locale translations for new featuresfrontend/public/locales/it.json
information
fr.json
French locale translations for new featuresfrontend/public/locales/fr.json
tracking
de.json
German locale translations for new featuresfrontend/public/locales/de.json
costs
information
en.json
English locale translations for new featuresfrontend/public/locales/en.json
information
fa.json
Comprehensive Persian locale updates for agent tools and query logsfrontend/public/locales/fa.json
(
enableAsTool,enableAsToolDescription,toolFunctionName,toolFunctionNameHint, etc.)pluralization support
webhook translations
queryHistory,queryLogs,queryLogsDesc,queryText,resultsCount,retrievalCost)cards,configure,confirm,error,false,open,saving,search,stop,true)ja.json
Complete Japanese locale additions for agent tools and queriesfrontend/public/locales/ja.json
(
enableAsTool,enableAsToolDescription,toolFunctionName, etc.)pluralization
translations
cards,configure,confirm,error,false,open,saving,search,stop,true)explanations
es.json
Spanish locale updates for agent tools and knowledge base queriesfrontend/public/locales/es.json
(
enableAsTool,enableAsToolDescription,toolFunctionName,toolFunctionNameHint, etc.)inconsistencies
explanations
ar.json
Arabic locale additions for agent tools and query featuresfrontend/public/locales/ar.json
Arabic pluralization
explanations
pt.json
Portuguese locale updates for agent tools and queriesfrontend/public/locales/pt.json
explanations
zh.json
Chinese locale additions for agent tools and query logsfrontend/public/locales/zh.json
(
enableAsTool,enableAsToolDescription,toolFunctionName, etc.)explanations
1 files
fill-translations.cjs
Add translation fill utility script for locale managementfrontend/scripts/fill-translations.cjs
English locale
en.jsonand identifies empty/null values in target languagefiles