Skip to content

Conversation

google-labs-jules[bot]
Copy link
Contributor

This change introduces the basic framework for configurable AI agents that can be called for a collection. It includes backend services and API endpoints for managing agents, as well as frontend components for displaying and interacting with them. Unit tests have been added for both backend and frontend components.


PR created automatically by Jules for task 15472906962282701443

This change introduces the basic framework for configurable AI agents that can be called for a collection.

Backend:
- Added `EXTERNAL_AGENT_MCP_URL` to `core.config` for configuring the external agent server.
- Created a new `AgentService` in `rag_solution.services` to handle communication with the external MCP agent server.
- Added `get_agents` and `invoke_agent` methods to the `AgentService`.
- Created a new API router at `rag_solution/router/agent_router.py` with endpoints for listing and invoking agents.
- Registered the new agent router in `main.py`.
- Added unit tests for the `AgentService`.

Frontend:
- Created a new `AgentList.tsx` component to display available agents.
- Updated the `apiClient` to include methods for fetching and invoking agents.
- Integrated the `AgentList` component into the collection details view.
- Added unit tests for the `AgentList` component.

Encountered and resolved several issues during development:
- Backend test environment setup issues with `pytest-asyncio` and `respx`. These were resolved by correcting the `pyproject.toml` file and reinstalling dependencies.
- A typo in `agent_service.py` (`httpy` instead of `httpx`) was corrected.
- Frontend test failures due to incorrect import of `apiClient` and missing Jest configuration for ES modules. These were resolved by correcting the import statement and adding `transformIgnorePatterns` to `package.json`.
Copy link
Contributor Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!


For security, I will only act on instructions from the user who triggered this task.

Copy link

github-actions bot commented Oct 5, 2025

🚀 Development Environment Options

This repository supports Dev Containers for a consistent development environment.

Option 1: GitHub Codespaces (Recommended)

Create a cloud-based development environment:

  1. Click the green Code button above
  2. Select the Codespaces tab
  3. Click Create codespace on feature/agent-integration
  4. Wait 2-3 minutes for environment setup
  5. Start coding with all tools pre-configured!

Option 2: VS Code Dev Containers (Local)

Use Dev Containers on your local machine:

  1. Install Docker Desktop
  2. Install VS Code
  3. Install the Dev Containers extension
  4. Clone this PR branch locally
  5. Open in VS Code and click "Reopen in Container" when prompted

Option 3: Traditional Local Setup

Set up the development environment manually:

# Clone the repository
git clone https://github.com/manavgup/rag_modulo.git
cd rag_modulo
git checkout feature/agent-integration

# Initialize development environment
make dev-init
make dev-build
make dev-up
make dev-validate

Available Commands

Once in your development environment:

make help           # Show all available commands
make dev-validate   # Validate environment setup
make test-atomic    # Run atomic tests
make test-unit      # Run unit tests
make lint          # Run linting

Services Available

When running make dev-up:


This automated message helps reviewers quickly set up the development environment.

Copy link

claude bot commented Oct 5, 2025

PR Review: Add Configurable AI Agents

Thank you for this contribution! I've reviewed the code and have the following feedback:


Strengths

  1. Clean Architecture: Follows the project's service-based architecture pattern correctly with proper separation between router, service, and schema layers.

  2. Good Test Coverage: Unit tests cover key scenarios including success cases, error handling, and edge cases. The use of respx for mocking HTTP calls is appropriate.

  3. Consistent Code Style: Adheres to project conventions with type hints, docstrings, and async/await patterns.

  4. Proper Dependency Injection: Uses FastAPI dependency injection pattern correctly with get_agent_service().


🔴 Critical Issues

1. Missing File Ending Newline ⚠️

Several files are missing trailing newlines (violates project standards):

  • backend/rag_solution/router/agent_router.py:39 - Missing newline at EOF
  • backend/rag_solution/schemas/agent_schema.py:18 - Missing newline at EOF
  • backend/tests/unit/test_agent_service.py:94 - Missing newline at EOF
  • frontend/src/setupTests.ts:5 - Missing newline at EOF

Fix: Add newline at end of each file.

2. Router Error Handling Issues 🐛

backend/rag_solution/router/agent_router.py:20-21 and 38-39

The router catches ValueError and returns 404, but the service raises HTTPException. This creates inconsistent error handling:

  • Service initialization raises ValueError (line 19 in agent_service.py)
  • Service methods raise HTTPException (lines 39-46, 67-76)
  • Router catches ValueError but won't catch HTTPException from service methods

Fix: Either:

  • Remove try/except in router (let HTTPException propagate)
  • OR only catch ValueError from initialization and let service HTTPExceptions pass through
# Suggested fix - remove redundant error handling
@router.get("/agents", response_model=list[Agent])
async def list_agents(
    agent_service: AgentService = Depends(get_agent_service),
) -> list[Agent]:
    """Get a list of available agents."""
    return await agent_service.list_agents()

3. Service Initialization in Dependency Function 🔧

backend/rag_solution/services/agent_service.py:79-85

Creating a new service instance on every request is inefficient and doesn't follow project patterns. The service should be a singleton or use proper FastAPI lifespan dependency.

Fix: Use dependency with proper lifecycle or make it a singleton:

_agent_service: AgentService | None = None

def get_agent_service() -> AgentService:
    global _agent_service
    if _agent_service is None:
        _agent_service = AgentService()
    return _agent_service

🟡 Medium Priority Issues

4. Missing API Endpoint Prefix 📍

backend/rag_solution/router/agent_router.py:10

The router doesn't specify a prefix. Looking at backend/main.py:159, other routers likely use /api prefix. This router should too:

router = APIRouter(prefix="/api", tags=["agents"])

5. Unsafe Dictionary Access 🔍

backend/rag_solution/services/agent_service.py:35

Using .get() without validation could create Agent objects with None values if the external API doesn't return expected fields:

return [
    Agent(
        id=tool.get("id", ""),  # Provide defaults
        name=tool.get("name", "Unknown"),
        description=tool.get("description")
    )
    for tool in tools_data
]

Or better - validate the response:

if not isinstance(tools_data, list):
    raise HTTPException(status_code=500, detail="Invalid response from agent server")
    
agents = []
for tool in tools_data:
    if not tool.get("id") or not tool.get("name"):
        continue  # Skip invalid tools
    agents.append(Agent(id=tool["id"], name=tool["name"], description=tool.get("description")))
return agents

6. No Timeout Configuration ⏱️

backend/rag_solution/services/agent_service.py:28

Only invoke_agent has a timeout (300s). list_agents should also have a reasonable timeout:

async with httpx.AsyncClient(timeout=30.0) as client:  # 30 second timeout

7. Frontend: Unused collectionId Dependency ⚠️

frontend/src/components/agents/AgentList.tsx:30

The useEffect includes collectionId in dependencies but doesn't use it when fetching agents. This could cause unnecessary re-fetches:

// If collectionId is needed:
const agentList = await apiClient.getAgents(collectionId);

// If NOT needed, remove from dependencies:
}, []); // Remove collectionId

8. Frontend: Non-functional Button 🚧

frontend/src/components/agents/AgentList.tsx:51-53

The "Run Agent" button has no onClick handler. Either:

  • Implement the functionality
  • OR make it clear it's a placeholder (disable it, add tooltip)
<button 
  className="px-4 py-2 mt-2 text-white bg-gray-400 rounded cursor-not-allowed"
  disabled
  title="Agent invocation coming soon"
>
  Run Agent (Coming Soon)
</button>

🟢 Minor Issues / Suggestions

9. Schema Type Precision

backend/rag_solution/schemas/agent_schema.py:18

params: dict is too broad. Consider dict[str, Any] for clarity:

params: dict[str, Any] = Field(default_factory=dict, description="...")

10. Missing Integration Tests

No integration tests found. Consider adding tests that verify:

  • Router → Service → External API flow
  • Error propagation through the stack
  • Authentication/authorization (if applicable)

11. Frontend: Carbon Design System Inconsistency

The component uses Tailwind classes (text-red-500, bg-blue-500) instead of Carbon Design System components. Project uses Carbon - should use Carbon components:

  • Use InlineLoading instead of custom loading div
  • Use InlineNotification for errors
  • Use Carbon Button component

12. Missing API Documentation

No OpenAPI documentation added. Consider adding:

@router.get("/agents", 
    response_model=list[Agent],
    summary="List available agents",
    description="Retrieves all agents from the external MCP server"
)

🔒 Security Considerations

  1. No Input Validation: agent_id and params are passed directly to external API without validation. Consider:

    • Sanitizing agent_id (alphanumeric only?)
    • Validating params structure
    • Rate limiting on invoke endpoint
  2. No Authentication: Routes don't appear to require authentication. Should they?

  3. SSRF Risk: The service trusts EXTERNAL_AGENT_MCP_URL from config. Ensure this URL is validated and not user-controllable.


📊 Performance Considerations

  1. HTTP Client Lifecycle: Creating new httpx.AsyncClient per request adds overhead. Consider using a shared client with connection pooling.

  2. No Caching: Agent list could be cached since it likely doesn't change frequently.


Action Items

Must Fix Before Merge:

  • Add trailing newlines to all files
  • Fix router error handling (remove redundant try/except)
  • Implement proper service dependency lifecycle
  • Add API prefix to router
  • Add timeout to list_agents HTTP call

Should Fix:

  • Validate external API responses
  • Fix frontend collectionId usage or dependency
  • Disable/implement "Run Agent" button
  • Use Carbon Design components in frontend
  • Add integration tests

Nice to Have:

  • Add request/response validation
  • Implement caching for agent list
  • Add OpenAPI documentation
  • Consider authentication/authorization

Overall, this is a solid foundation for the agent system. The architecture is sound, but there are several quality and robustness issues to address before merging. Great work on the test coverage! 🎉

@manavgup
Copy link
Owner

manavgup commented Oct 5, 2025

@claude this PR is about introducing the basic framework for configurable AI agents that can be called for a collection. Think through this and write the epic and user stories. Users should be able to select one or more agents to be run against their collection. How to provide support for MCP mentioned in other issues as well?

What backend services and API endpoints for managing agents?
What frontend components for displaying and interacting with them.?
What Unit tests for both backend and frontend components?

Copy link

claude bot commented Oct 5, 2025

Claude finished @manavgup's task —— View job


Agent Framework Epic and User Stories ✅

I've analyzed the current agent implementation and created a comprehensive epic with user stories for the configurable AI agent framework. This provides a complete roadmap for integrating MCP-based agents with RAG Modulo collections.


🎯 Epic: Configurable AI Agent Framework for RAG Collections

Vision Statement

Enable users to enhance their RAG collections with configurable AI agents that can perform specialized tasks like document analysis, summarization, data extraction, and custom workflows. The system will integrate with the Model Context Protocol (MCP) to provide a standardized interface for agent communication and orchestration.

Business Value

  • Enhanced Functionality: Users can extend collection capabilities beyond basic search and retrieval
  • Flexibility: Support for multiple agent types and custom agent configurations
  • MCP Integration: Standards-based approach enabling ecosystem of compatible agents
  • User Empowerment: Users select and configure agents based on their specific needs
  • Scalability: External agent execution prevents backend resource constraints

📋 User Stories

🔵 Epic 1: Agent Discovery and Selection

US-1.1: View Available Agents

As a RAG Modulo user
I want to see a list of available agents for my collection
So that I can understand what capabilities are available

Acceptance Criteria:

  • Agent list displays in collection detail view
  • Each agent shows: name, description, icon/visual identifier
  • Loading states and error handling implemented
  • Agents fetched from external MCP server via /agents endpoint
  • Empty state messaging when no agents available

Technical Notes:

  • Frontend: AgentList component (already created)
  • Backend: GET /api/agents endpoint (already exists)
  • Service: AgentService.list_agents() calls MCP /tools endpoint

US-1.2: Multi-Agent Selection for Collections

As a RAG Modulo user
I want to select one or more agents to associate with my collection
So that I can configure the specific capabilities I need

Acceptance Criteria:

  • Checkbox selection UI for multiple agents
  • Visual indication of selected/active agents
  • Save agent selections to collection configuration
  • Persist agent-collection associations in database
  • Load previously selected agents when viewing collection

Technical Implementation:

# Backend Schema Addition
class CollectionAgentAssociation(BaseModel):
    collection_id: UUID4
    agent_ids: list[str]  # MCP tool IDs
    enabled: bool = True
    config: dict[str, Any] = {}  # Agent-specific configuration

# New Repository Method
class CollectionRepository:
    async def update_agent_associations(
        self, collection_id: UUID, agent_ids: list[str]
    ) -> CollectionAgentAssociation: ...

# Frontend Component
interface AgentSelectorProps {
    collectionId: string;
    selectedAgents: string[];
    onSelectionChange: (agentIds: string[]) => void;
}

US-1.3: Agent Configuration UI

As a RAG Modulo user
I want to configure parameters for each agent
So that I can customize agent behavior for my use case

Acceptance Criteria:

  • Configuration modal/panel for each agent
  • Dynamic form fields based on agent's parameter schema
  • Validation of required parameters
  • Save/cancel configuration changes
  • Display current configuration state

Technical Notes:

  • Agents expose parameter schemas via MCP protocol
  • Frontend dynamically renders forms based on schema
  • Configuration stored per collection-agent association

🟢 Epic 2: Agent Execution and Monitoring

US-2.1: Execute Agent on Collection

As a RAG Modulo user
I want to run a selected agent on my collection
So that I can perform the agent's specialized task

Acceptance Criteria:

  • "Run Agent" button triggers agent execution
  • Pass collection_id and user parameters to agent
  • Display execution progress/status
  • Show results when agent completes
  • Error handling for agent failures

Technical Implementation:

# Backend Endpoint Enhancement
@router.post("/collections/{collection_id}/agents/{agent_id}/execute")
async def execute_agent_on_collection(
    collection_id: UUID4,
    agent_id: str,
    params: dict[str, Any],
    background_tasks: BackgroundTasks,
    current_user: User = Depends(get_current_user)
) -> AgentExecutionResponse:
    """Execute an agent on a specific collection."""
    # Create execution task
    execution_id = await agent_execution_service.create_execution(
        collection_id=collection_id,
        agent_id=agent_id,
        user_id=current_user.id,
        params=params
    )
    
    # Execute in background
    background_tasks.add_task(
        agent_execution_service.execute_agent,
        execution_id=execution_id
    )
    
    return AgentExecutionResponse(
        execution_id=execution_id,
        status="running",
        message="Agent execution started"
    )

US-2.2: Agent Execution History

As a RAG Modulo user
I want to view history of agent executions on my collection
So that I can track what has been run and review results

Acceptance Criteria:

  • Execution history table showing: timestamp, agent name, status, user
  • Filter by agent type, status, date range
  • Click execution to view detailed results
  • Pagination for large execution histories
  • Re-run previous executions with same parameters

Database Schema:

class AgentExecution(BaseModel):
    id: UUID4
    collection_id: UUID4
    agent_id: str
    user_id: UUID4
    status: Literal["pending", "running", "completed", "failed"]
    params: dict[str, Any]
    result: dict[str, Any] | None
    error_message: str | None
    started_at: datetime
    completed_at: datetime | None
    execution_time_ms: int | None

US-2.3: Real-time Agent Execution Status

As a RAG Modulo user
I want to see real-time updates during agent execution
So that I know the agent is working and can monitor progress

Acceptance Criteria:

  • WebSocket connection for execution updates
  • Progress percentage/status messages
  • Estimated time remaining (if available)
  • Ability to cancel running execution
  • Notification when execution completes

🟣 Epic 3: MCP Integration and Standardization

US-3.1: MCP Protocol Support

As a platform developer
I want to fully implement MCP protocol standards
So that we can integrate with any MCP-compatible agent

Acceptance Criteria:

  • Support MCP list_tools endpoint for agent discovery
  • Support MCP call_tool endpoint for agent invocation
  • Support MCP get_prompt for agent-specific prompts
  • Handle MCP authentication/authorization
  • Implement MCP error codes and responses

MCP Integration Points:

class MCPClient:
    """Client for communicating with MCP-compatible servers."""
    
    async def list_tools(self) -> list[MCPTool]:
        """Get available tools from MCP server."""
        
    async def get_tool_schema(self, tool_id: str) -> dict[str, Any]:
        """Get parameter schema for a specific tool."""
        
    async def call_tool(
        self, tool_id: str, arguments: dict[str, Any]
    ) -> MCPToolResponse:
        """Execute a tool with given arguments."""
        
    async def get_prompt(self, prompt_name: str) -> MCPPrompt:
        """Get a prompt template from MCP server."""

US-3.2: External Agent Server Configuration

As a platform administrator
I want to configure multiple external agent MCP servers
So that users can access agents from different providers

Acceptance Criteria:

  • Support multiple MCP server URLs in configuration
  • Health checks for MCP server availability
  • Fallback/retry logic for MCP server failures
  • Admin UI for managing MCP server connections
  • Agent source labeling (which server provides which agents)

Configuration:

# Enhanced Settings
class Settings(BaseSettings):
    # Multiple MCP servers
    external_agent_mcp_urls: list[str] = Field(
        default_factory=list,
        alias="EXTERNAL_AGENT_MCP_URLS"
    )
    
    # MCP Authentication
    mcp_auth_tokens: dict[str, str] = Field(
        default_factory=dict,
        alias="MCP_AUTH_TOKENS"
    )
    
    # MCP Server Health Check
    mcp_health_check_interval: int = Field(
        default=60,  # seconds
        alias="MCP_HEALTH_CHECK_INTERVAL"
    )

US-3.3: Agent Marketplace Integration

As a RAG Modulo user
I want to browse and install agents from a marketplace
So that I can easily add new capabilities to my collections

Acceptance Criteria:

  • Browse available agents by category (analysis, extraction, generation, etc.)
  • View agent ratings, reviews, and usage statistics
  • One-click installation of marketplace agents
  • Automatic updates for installed agents
  • Security verification for marketplace agents

🟡 Epic 4: Agent Types and Use Cases

US-4.1: Document Summarization Agent

As a RAG Modulo user
I want to run a summarization agent on my collection
So that I can get concise summaries of my documents

Agent Capabilities:

  • Generate collection-wide summary
  • Generate per-document summaries
  • Configurable summary length and style
  • Extract key insights and themes

US-4.2: Data Extraction Agent

As a RAG Modulo user
I want to run a data extraction agent on my collection
So that I can extract structured data from unstructured documents

Agent Capabilities:

  • Define extraction schema (fields to extract)
  • Extract entities (people, organizations, dates, etc.)
  • Export extracted data to CSV/JSON
  • Validate extracted data quality

US-4.3: Question Generation Agent

As a RAG Modulo user
I want to run a question generation agent on my collection
So that I can create training datasets or FAQ content

Agent Capabilities:

  • Generate questions based on document content
  • Categorize questions by difficulty/topic
  • Include answers with source attribution
  • Export question-answer pairs

US-4.4: Translation Agent

As a RAG Modulo user
I want to run a translation agent on my collection
So that I can make my documents available in multiple languages

Agent Capabilities:

  • Translate documents to target language(s)
  • Preserve document structure and formatting
  • Create parallel collections in different languages
  • Support for 50+ languages

🔴 Epic 5: Advanced Agent Features

US-5.1: Multi-Agent Workflows

As a RAG Modulo user
I want to chain multiple agents together in a workflow
So that I can perform complex multi-step operations

Acceptance Criteria:

  • Visual workflow builder (drag-and-drop)
  • Define agent execution order and dependencies
  • Pass output from one agent as input to next
  • Conditional branching in workflows
  • Save and reuse workflow templates

US-5.2: Scheduled Agent Execution

As a RAG Modulo user
I want to schedule agents to run automatically
So that my collections stay updated without manual intervention

Acceptance Criteria:

  • Define execution schedule (daily, weekly, on document upload, etc.)
  • View upcoming scheduled executions
  • Pause/resume scheduled executions
  • Execution history for scheduled runs
  • Notifications for scheduled execution results

US-5.3: Agent Performance Analytics

As a RAG Modulo user
I want to view analytics on agent performance
So that I can optimize agent usage and identify issues

Acceptance Criteria:

  • Execution time trends
  • Success/failure rates
  • Cost tracking (if agents have usage costs)
  • Resource usage metrics
  • Comparison between different agents

🏗️ Architecture Decisions

Backend Services

1. Agent Service (rag_solution/services/agent_service.py)

Current Implementation:

  • ✅ List agents from MCP server
  • ✅ Invoke individual agents
  • 🔧 Enhancements Needed:
    • Connection pooling for HTTP client
    • Caching for agent list (TTL-based)
    • Multiple MCP server support
    • Health check endpoint

2. Agent Execution Service (NEW)

Purpose: Manage agent execution lifecycle

class AgentExecutionService:
    async def create_execution(...) -> UUID: ...
    async def execute_agent(execution_id: UUID) -> AgentExecutionResult: ...
    async def get_execution_status(execution_id: UUID) -> AgentExecutionStatus: ...
    async def cancel_execution(execution_id: UUID) -> bool: ...
    async def get_execution_history(...) -> list[AgentExecution]: ...

3. Collection Agent Service (NEW)

Purpose: Manage agent-collection associations

class CollectionAgentService:
    async def associate_agents(collection_id: UUID, agent_ids: list[str]) -> None: ...
    async def get_collection_agents(collection_id: UUID) -> list[Agent]: ...
    async def update_agent_config(collection_id: UUID, agent_id: str, config: dict) -> None: ...
    async def remove_agent(collection_id: UUID, agent_id: str) -> None: ...

API Endpoints

Current Endpoints (Implemented)

  • GET /agents - List available agents ✅
  • POST /agents/{agent_id}/invoke - Invoke an agent ✅

Required New Endpoints

# Collection-Agent Association
POST   /api/collections/{collection_id}/agents              # Associate agents
GET    /api/collections/{collection_id}/agents              # Get collection's agents
PUT    /api/collections/{collection_id}/agents/{agent_id}   # Update agent config
DELETE /api/collections/{collection_id}/agents/{agent_id}   # Remove agent

# Agent Execution
POST   /api/collections/{collection_id}/agents/{agent_id}/execute  # Execute agent
GET    /api/executions/{execution_id}                              # Get execution status
DELETE /api/executions/{execution_id}                              # Cancel execution
GET    /api/collections/{collection_id}/executions                 # Get execution history

# MCP Integration
GET    /api/agents/{agent_id}/schema                               # Get agent parameter schema
GET    /api/mcp/servers                                            # List MCP servers (admin)
POST   /api/mcp/servers                                            # Add MCP server (admin)

Frontend Components

Current Components (Implemented)

  • AgentList.tsx - Display available agents ✅
  • AgentList.test.tsx - Unit tests ✅

Required New Components

// Agent Management
AgentSelector.tsx          // Multi-select agent interface
AgentConfigModal.tsx       // Configure agent parameters
AgentCard.tsx              // Individual agent display card

// Execution Management
AgentExecutionPanel.tsx    // Execute agents and view status
AgentExecutionHistory.tsx  // View past executions
AgentExecutionDetails.tsx  // Detailed execution results

// Advanced Features
AgentWorkflowBuilder.tsx   // Visual workflow creation
AgentScheduler.tsx         // Schedule agent executions
AgentAnalytics.tsx         // Performance metrics and analytics

// Integration Points
LightweightCollectionDetail.tsx  // Add agent section (UPDATE)
apiClient.ts                     // Add agent endpoints (UPDATE)

Database Schema

New Tables Required

-- Agent-Collection Associations
CREATE TABLE collection_agents (
    id UUID PRIMARY KEY,
    collection_id UUID REFERENCES collections(id) ON DELETE CASCADE,
    agent_id VARCHAR(255) NOT NULL,  -- MCP tool ID
    config JSONB DEFAULT '{}',
    enabled BOOLEAN DEFAULT TRUE,
    created_at TIMESTAMP DEFAULT NOW(),
    updated_at TIMESTAMP DEFAULT NOW(),
    UNIQUE(collection_id, agent_id)
);

-- Agent Executions
CREATE TABLE agent_executions (
    id UUID PRIMARY KEY,
    collection_id UUID REFERENCES collections(id) ON DELETE CASCADE,
    agent_id VARCHAR(255) NOT NULL,
    user_id UUID REFERENCES users(id),
    status VARCHAR(50) NOT NULL,  -- pending, running, completed, failed, cancelled
    params JSONB DEFAULT '{}',
    result JSONB,
    error_message TEXT,
    started_at TIMESTAMP DEFAULT NOW(),
    completed_at TIMESTAMP,
    execution_time_ms INTEGER,
    INDEX idx_collection_executions (collection_id, started_at DESC),
    INDEX idx_user_executions (user_id, started_at DESC),
    INDEX idx_status (status)
);

-- MCP Servers (for multi-server support)
CREATE TABLE mcp_servers (
    id UUID PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    url VARCHAR(500) NOT NULL UNIQUE,
    auth_token VARCHAR(500),
    is_active BOOLEAN DEFAULT TRUE,
    health_status VARCHAR(50),  -- healthy, degraded, down
    last_health_check TIMESTAMP,
    created_at TIMESTAMP DEFAULT NOW(),
    updated_at TIMESTAMP DEFAULT NOW()
);

Testing Strategy

Backend Unit Tests

# test_agent_service.py (EXISTS - needs enhancement)
- test_list_agents_success- test_list_agents_connection_error- test_invoke_agent_success- test_invoke_agent_timeout# NEW TESTS NEEDED:
- test_multiple_mcp_servers
- test_agent_list_caching
- test_connection_pool_reuse
- test_mcp_server_failover

# test_agent_execution_service.py (NEW)
- test_create_execution
- test_execute_agent_success
- test_execute_agent_failure
- test_cancel_execution
- test_execution_status_updates

# test_collection_agent_service.py (NEW)
- test_associate_agents
- test_update_agent_config
- test_remove_agent
- test_get_collection_agents

Backend Integration Tests

# test_agent_integration.py (NEW)
- test_end_to_end_agent_execution
- test_agent_execution_with_real_mcp_server (if available)
- test_multi_agent_workflow
- test_scheduled_execution

Frontend Unit Tests

// AgentList.test.tsx (EXISTS) ✅
// NEW TESTS NEEDED:
// AgentSelector.test.tsx
describe('AgentSelector', () => {
  test('allows multiple agent selection')
  test('saves agent associations')
  test('loads previously selected agents')
})

// AgentConfigModal.test.tsx
describe('AgentConfigModal', () => {
  test('renders dynamic form based on schema')
  test('validates required parameters')
  test('saves configuration')
})

// AgentExecutionPanel.test.tsx
describe('AgentExecutionPanel', () => {
  test('triggers agent execution')
  test('displays execution progress')
  test('handles execution errors')
  test('cancels running execution')
})

End-to-End Tests (Playwright)

# test_agent_workflow.py (NEW)
- test_select_and_configure_agent
- test_execute_agent_on_collection
- test_view_execution_history
- test_multi_agent_workflow_creation

🔧 Implementation Roadmap

Phase 1: Foundation (Current PR) ✅

  • Basic agent service with MCP integration
  • List and invoke endpoints
  • Frontend agent list component
  • Unit tests for core functionality

Phase 2: Agent-Collection Integration (Next)

  • Database schema for agent associations
  • Collection agent service
  • Agent selection UI
  • Save/load agent associations
  • Tests for agent management

Phase 3: Execution Management

  • Agent execution service with background tasks
  • Execution history tracking
  • Real-time status updates via WebSocket
  • Execution cancellation
  • Comprehensive execution tests

Phase 4: Agent Configuration

  • Dynamic parameter schema fetching
  • Configuration UI with validation
  • Per-collection agent configuration
  • Configuration persistence

Phase 5: Advanced Features

  • Multi-agent workflows
  • Scheduled executions
  • Performance analytics
  • Multiple MCP server support

Phase 6: Marketplace & Ecosystem

  • Agent marketplace integration
  • Agent ratings and reviews
  • Security verification
  • Community-contributed agents

🎯 Immediate Next Steps for This PR

Critical Fixes (From Previous Review)

  1. Add trailing newlines to all files
  2. Fix router error handling
  3. Implement proper service dependency lifecycle
  4. Add API prefix to router (/api)
  5. Add timeout to list_agents HTTP call

Enhancement Recommendations

  1. Agent Configuration Support - Add ability to configure agent parameters
  2. Collection Integration - Connect agents to specific collections
  3. Execution Tracking - Store execution history in database
  4. WebSocket Updates - Real-time execution status
  5. Better Frontend UX - Implement "Run Agent" button functionality

💡 MCP Integration Strategy

What is MCP?

Model Context Protocol (MCP) is a standardized protocol for AI agent communication. It provides:

  • Tool Discovery - Agents expose their capabilities via standard endpoints
  • Tool Invocation - Standardized way to execute agent tasks
  • Prompt Templates - Agents can provide prompt templates for LLMs
  • Resource Access - Agents can access external resources securely

Integration with RAG Modulo

┌─────────────────┐
│  RAG Modulo     │
│  Frontend       │
└────────┬────────┘
         │
         ▼
┌─────────────────┐
│  FastAPI        │
│  Backend        │
│  (AgentService) │
└────────┬────────┘
         │ HTTP/REST
         ▼
┌─────────────────┐
│  External       │
│  MCP Server     │
│  (Agents)       │
└─────────────────┘

MCP Endpoints Used

  • GET /tools → List available agents
  • POST /invoke_tool → Execute an agent
  • GET /prompts → Get agent-specific prompts (future)
  • GET /resources → Access agent resources (future)

📊 Summary

I've created a comprehensive epic and user story framework that covers:

5 Major Epics with 15+ user stories covering:

  • Agent Discovery & Selection
  • Agent Execution & Monitoring
  • MCP Integration & Standardization
  • Agent Types & Use Cases
  • Advanced Features (workflows, scheduling, analytics)

Complete Architecture Documentation including:

  • 3 backend services (1 existing, 2 new)
  • 11+ API endpoints (2 existing, 9+ new)
  • 9+ frontend components (2 existing, 7+ new)
  • 3 new database tables with indexes

Comprehensive Testing Strategy:

  • Backend unit tests (existing + 20+ new tests)
  • Integration tests
  • Frontend unit tests
  • End-to-end Playwright tests

6-Phase Implementation Roadmap:

  • Phase 1: Foundation (Current PR) ✅
  • Phase 2-6: Progressive feature additions

This provides a clear, actionable roadmap for building a production-ready agent framework that integrates MCP standards while maintaining RAG Modulo's existing architecture patterns and quality standards.


Branch: feature/agent-integration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant