Skip to content

Commit fd63db6

Browse files
committed
feat: added distributed a2a implementation with specific config endpoints, added specialized agent cards and 2 new agent capabilities
1 parent bcf461a commit fd63db6

File tree

6 files changed

+1028
-100
lines changed

6 files changed

+1028
-100
lines changed

agentic_rag/README.md

Lines changed: 267 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,112 @@ python local_rag_agent.py --query "How to implement a queue?" --collection "Repo
458458

459459
The agentic_rag system now includes full support for the Agent2Agent (A2A) protocol, enabling seamless communication and collaboration with other AI agents. This integration transforms the system into an interoperable agent that can participate in multi-agent workflows and ecosystems.
460460

461+
### 3.0 Distributed Chain of Thought Architecture
462+
463+
The system implements a **distributed multi-agent Chain of Thought (CoT)** architecture where each specialized agent can run on separate servers and communicate via the A2A protocol. This enables:
464+
465+
- **True Distributed Processing**: Each agent (Planner, Researcher, Reasoner, Synthesizer) can run on different servers
466+
- **Scalable Agent Deployment**: Deploy agents independently based on resource requirements
467+
- **Agent-to-Agent Communication**: All communication happens via A2A protocol using agent IDs and remote URLs
468+
- **Load Balancing**: Distribute workload across multiple servers for better performance
469+
470+
#### Distributed Architecture Diagram
471+
472+
```
473+
┌─────────────────────────────────────────────────────────────────────┐
474+
│ User Query via Gradio │
475+
└────────────────────────────┬────────────────────────────────────────┘
476+
477+
478+
┌──────────────────────┐
479+
│ A2A Orchestrator │
480+
│ (localhost:8000) │
481+
└──────────────────────┘
482+
483+
┌────────────────┼────────────────┐
484+
│ │ │
485+
▼ ▼ ▼
486+
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
487+
│ Planner Agent │ │Researcher Agent │ │ Reasoner Agent │
488+
│ Agent ID: │ │ Agent ID: │ │ Agent ID: │
489+
│planner_agent_v1 │ │researcher_a_v1 │ │reasoner_a_v1 │
490+
│ │ │ │ │ │
491+
│ URL: http:// │ │ URL: http:// │ │ URL: http:// │
492+
│ localhost:8000 │ │ localhost:8000 │ │ localhost:8000 │
493+
│ OR │ │ OR │ │ OR │
494+
│ server1:8001 ◄──┼──► server2:8002 ◄──┼──► server3:8003 │
495+
└─────────────────┘ └─────────────────┘ └─────────────────┘
496+
497+
498+
┌─────────────────┐
499+
│Synthesizer Agent│
500+
│ Agent ID: │
501+
│synthesizer_a_v1 │
502+
│ │
503+
│ URL: http:// │
504+
│ localhost:8000 │
505+
│ OR │
506+
│ server4:8004 │
507+
└─────────────────┘
508+
509+
510+
┌──────────────────┐
511+
│ Final Answer │
512+
│ to User │
513+
└──────────────────┘
514+
```
515+
516+
#### How Distributed Communication Works
517+
518+
1. **Agent Discovery**: Agents register their capabilities and endpoints with the A2A registry
519+
2. **Agent Addressing**: Each agent is addressable via `{base_url}/a2a` + `agent_id`
520+
3. **Remote Communication**:
521+
- Orchestrator sends A2A request to: `http://server1:8001/a2a`
522+
- Request body includes: `{"method": "agent.query", "params": {"agent_id": "planner_agent_v1", ...}}`
523+
- Agent processes and returns result via A2A response
524+
4. **Sequential Flow**: Planner → Researcher → Reasoner → Synthesizer (each via A2A protocol)
525+
526+
#### Configuration for Distributed Deployment
527+
528+
To deploy agents on different servers, update `config.yaml`:
529+
530+
```yaml
531+
AGENT_ENDPOINTS:
532+
planner_url: http://server1.example.com:8001
533+
researcher_url: http://server2.example.com:8002
534+
reasoner_url: http://server3.example.com:8003
535+
synthesizer_url: http://server4.example.com:8004
536+
```
537+
538+
**Local Development** (default):
539+
```yaml
540+
AGENT_ENDPOINTS:
541+
planner_url: http://localhost:8000
542+
researcher_url: http://localhost:8000
543+
reasoner_url: http://localhost:8000
544+
synthesizer_url: http://localhost:8000
545+
```
546+
547+
#### Specialized Agent Cards
548+
549+
Each specialized agent has its own agent card describing its capabilities:
550+
551+
| Agent ID | Name | Role | Capability |
552+
|----------|------|------|------------|
553+
| `planner_agent_v1` | Strategic Planner | Problem decomposition | Breaks queries into 3-4 actionable steps |
554+
| `researcher_agent_v1` | Information Researcher | Knowledge gathering | Searches vector stores and extracts findings |
555+
| `reasoner_agent_v1` | Logic & Reasoning | Logical analysis | Applies reasoning to draw conclusions |
556+
| `synthesizer_agent_v1` | Information Synthesizer | Response generation | Combines steps into coherent final answer |
557+
558+
#### Benefits of Distributed Architecture
559+
560+
1. **Resource Optimization**: Deploy resource-intensive agents (Researcher) on GPU servers, lighter agents on CPU servers
561+
2. **Fault Tolerance**: If one agent fails, others continue functioning
562+
3. **Independent Scaling**: Scale specific agents based on load (e.g., multiple Researcher instances)
563+
4. **Technology Flexibility**: Each agent can use different LLM backends (GPT-4, Claude, Ollama, etc.)
564+
5. **Security Isolation**: Sensitive operations can run in isolated environments
565+
6. **Geographic Distribution**: Deploy agents closer to data sources for lower latency
566+
461567
### 3.1 Why A2A Protocol Implementation?
462568

463569
**Enhanced Interoperability**: The A2A protocol enables the agentic_rag system to communicate with other AI agents using a standardized protocol, breaking down silos between different AI systems and frameworks.
@@ -488,10 +594,12 @@ The system supports the following A2A protocol methods:
488594

489595
- `document.query`: Query documents using RAG with intelligent routing
490596
- `document.upload`: Process and store documents in vector database
597+
- `agent.query`: **NEW** - Query specialized CoT agents (Planner, Researcher, Reasoner, Synthesizer) for distributed reasoning
491598
- `task.create`: Create long-running tasks for complex operations
492599
- `task.status`: Check status of running tasks
493600
- `task.cancel`: Cancel running tasks
494601
- `agent.discover`: Discover other agents and their capabilities
602+
- `agent.register`: Register new agents with the A2A registry
495603
- `agent.card`: Get agent capability information
496604
- `health.check`: System health and status check
497605

@@ -570,10 +678,86 @@ curl -X POST http://localhost:8000/a2a \
570678
"id": "4"
571679
}'
572680
681+
# Discover specialized CoT agents
682+
curl -X POST http://localhost:8000/a2a \
683+
-H "Content-Type: application/json" \
684+
-d '{
685+
"jsonrpc": "2.0",
686+
"method": "agent.discover",
687+
"params": {
688+
"capability": "agent.query"
689+
},
690+
"id": "5"
691+
}'
692+
573693
# Get agent card
574694
curl -X GET http://localhost:8000/agent_card
575695
```
576696
697+
#### 3.4.4 Specialized Agent Query (Distributed CoT)
698+
699+
```bash
700+
# Query the Planner Agent
701+
curl -X POST http://localhost:8000/a2a \
702+
-H "Content-Type: application/json" \
703+
-d '{
704+
"jsonrpc": "2.0",
705+
"method": "agent.query",
706+
"params": {
707+
"agent_id": "planner_agent_v1",
708+
"query": "How does machine learning work?"
709+
},
710+
"id": "6"
711+
}'
712+
713+
# Query the Researcher Agent
714+
curl -X POST http://localhost:8000/a2a \
715+
-H "Content-Type: application/json" \
716+
-d '{
717+
"jsonrpc": "2.0",
718+
"method": "agent.query",
719+
"params": {
720+
"agent_id": "researcher_agent_v1",
721+
"query": "How does machine learning work?",
722+
"step": "Understand the basic concept of ML"
723+
},
724+
"id": "7"
725+
}'
726+
727+
# Query the Reasoner Agent
728+
curl -X POST http://localhost:8000/a2a \
729+
-H "Content-Type: application/json" \
730+
-d '{
731+
"jsonrpc": "2.0",
732+
"method": "agent.query",
733+
"params": {
734+
"agent_id": "reasoner_agent_v1",
735+
"query": "How does machine learning work?",
736+
"step": "Analyze the key components",
737+
"context": [{"content": "Research findings about ML algorithms..."}]
738+
},
739+
"id": "8"
740+
}'
741+
742+
# Query the Synthesizer Agent
743+
curl -X POST http://localhost:8000/a2a \
744+
-H "Content-Type: application/json" \
745+
-d '{
746+
"jsonrpc": "2.0",
747+
"method": "agent.query",
748+
"params": {
749+
"agent_id": "synthesizer_agent_v1",
750+
"query": "How does machine learning work?",
751+
"reasoning_steps": [
752+
"ML is a subset of AI...",
753+
"It uses algorithms to learn from data...",
754+
"Key components include training and inference..."
755+
]
756+
},
757+
"id": "9"
758+
}'
759+
```
760+
577761
### 3.5 Testing A2A Implementation
578762
579763
The A2A implementation includes comprehensive tests covering all functionality:
@@ -601,9 +785,11 @@ The test suite includes:
601785
- **Error Handling**: Error condition testing
602786
- **Model Validation**: Data model testing
603787
604-
### 3.6 A2A Agent Card
788+
### 3.6 A2A Agent Cards
605789
606-
The system publishes its capabilities through an agent card:
790+
The system publishes its capabilities through agent cards. There is a main agent card for the RAG system and individual cards for each specialized CoT agent:
791+
792+
#### Main RAG Agent Card
607793
608794
```json
609795
{
@@ -617,6 +803,15 @@ The system publishes its capabilities through an agent card:
617803
"description": "Query documents using RAG with context retrieval",
618804
"input_schema": { ... },
619805
"output_schema": { ... }
806+
},
807+
{
808+
"name": "agent.query",
809+
"description": "Query specialized CoT agents for distributed reasoning",
810+
"input_schema": {
811+
"agent_id": "planner_agent_v1 | researcher_agent_v1 | reasoner_agent_v1 | synthesizer_agent_v1",
812+
...
813+
},
814+
"output_schema": { ... }
620815
}
621816
],
622817
"endpoints": {
@@ -626,25 +821,90 @@ The system publishes its capabilities through an agent card:
626821
}
627822
```
628823
629-
### 3.7 Benefits of A2A Integration
824+
#### Specialized Agent Cards
825+
826+
Each CoT agent has its own card accessible via agent discovery:
827+
828+
```bash
829+
# Discover all specialized agents
830+
curl -X POST http://localhost:8000/a2a \
831+
-H "Content-Type: application/json" \
832+
-d '{"jsonrpc": "2.0", "method": "agent.discover", "params": {"capability": "agent.query"}, "id": "1"}'
833+
```
834+
835+
This returns agent cards for:
836+
- **Planner Agent** (`planner_agent_v1`): Problem decomposition and strategic planning
837+
- **Researcher Agent** (`researcher_agent_v1`): Information gathering from vector stores
838+
- **Reasoner Agent** (`reasoner_agent_v1`): Logical reasoning and analysis
839+
- **Synthesizer Agent** (`synthesizer_agent_v1`): Final answer synthesis
840+
841+
### 3.7 Using A2A Chat Interface in Gradio
842+
843+
The Gradio interface includes an **A2A Chat Interface** tab that allows you to interact with the distributed CoT agents:
844+
845+
1. **Navigate to A2A Chat Interface tab** in the Gradio UI
846+
2. **Enable "Use Chain of Thought"** checkbox to activate distributed CoT reasoning
847+
3. **Ask a question** and watch as it orchestrates through all specialized agents:
848+
- 🎯 Planner breaks down the query
849+
- 🔍 Researcher gathers information for each step
850+
- 🤔 Reasoner applies logical analysis
851+
- 📝 Synthesizer combines into final answer
852+
4. **View step-by-step progress** as each agent processes via A2A protocol
853+
854+
**Prerequisites**:
855+
- A2A server must be running (`python main.py` on port 8000)
856+
- Specialized agents are automatically registered on server startup
857+
- All communication happens via A2A protocol (HTTP + JSON-RPC 2.0)
858+
859+
**Example Query Flow**:
860+
```
861+
User: "What is machine learning?"
862+
↓ (A2A: agent.query → planner_agent_v1)
863+
Planner: Creates 4 steps
864+
↓ (A2A: agent.query → researcher_agent_v1) × 4
865+
Researcher: Gathers info for each step
866+
↓ (A2A: agent.query → reasoner_agent_v1) × 4
867+
Reasoner: Analyzes each step
868+
↓ (A2A: agent.query → synthesizer_agent_v1)
869+
Synthesizer: Combines into final answer
870+
871+
User: Receives comprehensive answer with sources
872+
```
873+
874+
### 3.8 Benefits of A2A Integration
630875
631876
1. **Interoperability**: Seamless communication with other A2A-compliant agents
632877
2. **Scalability**: Support for complex multi-agent workflows
633878
3. **Standardization**: Industry-standard communication protocol
634879
4. **Discovery**: Automatic agent and capability discovery
635880
5. **Security**: Built-in authentication and authorization
636881
6. **Future-Proofing**: Compatibility with evolving agent ecosystems
882+
7. **Distributed Processing**: Each agent can run on separate infrastructure
883+
8. **Load Balancing**: Distribute workload across multiple servers
884+
885+
### 3.9 Configuration
886+
887+
**A2A Endpoint Configuration** (for distributed deployment):
637888
638-
### 3.8 Configuration
889+
Edit `config.yaml` to specify agent endpoints:
890+
891+
```yaml
892+
AGENT_ENDPOINTS:
893+
planner_url: http://localhost:8000 # or remote server
894+
researcher_url: http://localhost:8000 # or remote server
895+
reasoner_url: http://localhost:8000 # or remote server
896+
synthesizer_url: http://localhost:8000 # or remote server
897+
```
639898
640-
No additional configuration is required for A2A functionality. The system automatically:
899+
**Basic A2A functionality** requires no additional configuration. The system automatically:
641900
642901
- Initializes A2A handlers on startup
643-
- Registers available capabilities
902+
- Registers main RAG agent and specialized CoT agents
644903
- Starts task management services
645904
- Enables agent discovery
905+
- Loads agent endpoint URLs from config
646906
647-
### 3.9 Troubleshooting
907+
### 3.10 Troubleshooting
648908
649909
#### Common Issues
650910

0 commit comments

Comments
 (0)