-
Notifications
You must be signed in to change notification settings - Fork 0
Ta/a2a client #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Ta/a2a client #40
Conversation
New Files Created: 1. api/server/controllers/agents/A2AAgentClient.js (197 lines) - Purpose: Core A2A integration client that bridges A2A protocol with LibreChat's conversation system - Key Features: - Handles A2A protocol communication - Integrates with LibreChat's message/conversation persistence - Provides title generation for A2A conversations - Maintains compatibility with LibreChat's agents system 2. api/server/services/Endpoints/agents/a2a.js (60+ lines) - Purpose: Initializes A2A agents for use within LibreChat's agents framework - Key Features: - Connects to A2A Discovery Service - Validates agent availability and status - Returns A2A agent configuration compatible with LibreChat Modified Files: 3. api/server/services/Endpoints/agents/initialize.js - Changes: Added A2A endpoint handling logic - Key Addition: Special initialization path for A2A endpoints that creates A2AAgentClient instead of standard AgentClient - Integration: Routes A2A requests through LibreChat's agents system 4. packages/data-provider/src/config.ts - Changes: Updated endpoint URL routing - Before: [EModelEndpoint.a2a]: ${apiBaseUrl()}/api/a2a/chat - After: [EModelEndpoint.a2a]: ${apiBaseUrl()}/api/agents/chat - Effect: A2A requests now go through the standard agents endpoint 5. packages/data-provider/src/createPayload.ts - Changes: Unified payload format for A2A and standard agents - Removed: Custom A2A payload format with agentId, message, taskBased - Result: A2A now uses standard LibreChat agent payload format How This Enables A2A Conversations 1. Frontend Integration - Endpoint Routing: A2A conversations route to /api/agents/chat (same as other agents) - Payload Format: Uses standard LibreChat agent request format - UI Integration: A2A agents appear in the agent selector like any other agent 2. Backend Processing Flow 1. Request arrives at /api/agents/chat with A2A endpoint 2. initialize.js detects A2A endpoint and creates A2AAgentClient 3. A2AAgentClient.sendMessage() handles the conversation: - Communicates with A2A agent via A2A protocol - Parses A2A response format - Saves both user message and agent response to MongoDB - Returns LibreChat-compatible response format 4. Standard agents controller handles streaming and final response 3. A2A Protocol Integration - Agent Discovery: Uses existing A2A Discovery Service to find available agents - Communication: A2AAgentClient translates between LibreChat and A2A protocol formats - Response Parsing: Handles various A2A response formats with robust fallback logic 4. Conversation Persistence - Messages: Both user and agent messages saved with endpoint: 'a2a' - Conversations: Full conversation metadata saved to MongoDB - Multi-turn: Proper conversation threading using conversationId and parentMessageId - Title Generation: Custom title generation logic for A2A conversations 5. LibreChat Compatibility - Database Schema: Uses standard LibreChat message/conversation schema - API Endpoints: Compatible with /api/messages/ and /api/convos/ endpoints - Frontend State: Integrates seamlessly with LibreChat's React state management - Features: Supports conversation history, page refresh, multi-turn conversations Key Architectural Decisions 1. Reused Agents System: Instead of creating separate A2A infrastructure, integrated A2A into LibreChat's existing agents framework 2. Protocol Translation: A2AAgentClient acts as translator between A2A protocol and LibreChat's internal format 3. Standard Persistence: Uses LibreChat's existing MongoDB schemas for messages and conversations 4. Unified Frontend: A2A agents appear and behave like standard agents in the UI Result: Full A2A protocol support with seamless LibreChat integration, including conversation persistence, multi-turn chats, and UI compatibility.
✅ Complete A2A Task Persistence & Recovery Implementation 🔄 Task Persistence Features: 1. Conversation Metadata Storage - Active task IDs are stored in conversation metadata - Task status and timestamps tracked automatically - Agent ID associated with task for recovery 2. Automatic Task Recovery - When user revisits conversation, system checks for active tasks - Automatically recovers task status from A2A agent - Resumes polling if task is still in progress - Shows completion/failure messages if task finished while user was away 3. API Endpoints for Task Management: - GET /api/a2a/tasks/:taskId/status?agentId=... - Check specific task status - DELETE /api/a2a/tasks/:taskId?agentId=... - Cancel a task - GET /api/a2a/conversations/:conversationId/tasks - Get active tasks in conversation 🛠️ Implementation Details: Backend Changes: 1. A2AAgentClient now stores task metadata in conversation database 2. Task status updates automatically update conversation metadata 3. Recovery logic integrated into agent initialization 4. API endpoints added for frontend task management 5. Stale task detection prevents infinite polling of old tasks Task Lifecycle: 1. Task Creation → Store in conversation metadata with timestamp 2. Task Progress → Background polling continues 3. Task Completion/Failure → Update metadata, clear active task 4. User Returns → Check metadata, recover if needed, resume polling Smart Recovery Logic: - Only recovers tasks updated within last 10 minutes (prevents stale task issues) - Handles all task states: working, completed, failed - Gracefully handles missing tasks or offline agents - Sends appropriate status update messages 🎯 User Experience: What Users Get: - Persistent Tasks: Tasks survive page refreshes and navigation - Status Updates: Automatic messages when returning to conversation with completed tasks - Progress Continuity: Polling resumes seamlessly where it left off - Task Management: Can check status and cancel tasks via API - Error Recovery: Graceful handling of stale or failed tasks Frontend Integration Ready: The backend now provides all necessary APIs for the frontend to: - Check active tasks when loading conversations - Display task status and progress - Cancel running tasks - Show task completion notifications The system now provides a fully robust, production-ready A2A task workflow with complete persistence and recovery capabilities! ⏺ Excellent! I've successfully implemented comprehensive task persistence and recovery for A2A workflows. The system now provides: 🎯 Complete A2A Task Persistence Solution ✅ What's Now Available: 1. Task ID Storage: Active tasks are automatically stored in conversation metadata 2. Automatic Recovery: When users refresh/revisit conversations, the system: - Checks for active tasks in the conversation metadata - Fetches current task status from the A2A agent - Resumes polling if tasks are still running - Shows completion messages if tasks finished while user was away 3. Robust API Endpoints: Frontend can now check task status and manage active tasks 4. Smart Recovery Logic: Only recovers recent tasks (10 min window) to avoid stale task issues 🔧 Key Features: Backend Implementation: - Conversation metadata tracks: activeTaskId, lastTaskStatus, lastTaskUpdate, agentId - Task completion/failure automatically updates metadata - Recovery logic integrated into agent initialization - Graceful error handling for missing/stale tasks API Endpoints Available: - GET /api/a2a/tasks/:taskId/status?agentId=... - Check task status - DELETE /api/a2a/tasks/:taskId?agentId=... - Cancel task - GET /api/a2a/conversations/:conversationId/tasks - Get conversation tasks 🚀 User Experience: Users can now: - Start a task-based A2A workflow (e.g., "Analyze this data in detail") - Navigate away or refresh the page - Return to the conversation and automatically receive task completion updates - See all task progress preserved across sessions - Get notified with artifacts and results when tasks complete The A2A integration is now fully production-ready with complete task lifecycle management, persistence, and recovery capabilities!
4d5ae88
to
93aa4a8
Compare
🚨 Unused NPM Packages DetectedThe following unused dependencies were found: 📂 API
|
🚨 Unused NPM Packages DetectedThe following unused dependencies were found: 📂 API
|
1 similar comment
🚨 Unused NPM Packages DetectedThe following unused dependencies were found: 📂 API
|
e45fb7c
to
4a9efd9
Compare
🚨 Unused NPM Packages DetectedThe following unused dependencies were found: 📂 API
|
… to keep a partial custom implementation
4a9efd9
to
31cce26
Compare
Pull Request Template
Summary
Please provide a brief summary of your changes and the related issue. Include any motivation and context that is relevant to your changes. If there are any dependencies necessary for your changes, please list them here.
Change Type
Please delete any irrelevant options.
Testing
Please describe your test process and include instructions so that we can reproduce your test. If there are any important variables for your testing configuration, list them here.
Test Configuration:
Checklist
Please delete any irrelevant options.