|
| 1 | +# Domain Context Solution |
| 2 | + |
| 3 | +This example demonstrates how to solve domain context issues in multi-agent systems using existing PraisonAI features. |
| 4 | + |
| 5 | +## Problem |
| 6 | + |
| 7 | +In hierarchical multi-agent workflows, tools often default to generic values like "example.com" instead of using user-specified domains. This happens because domain context doesn't automatically reach the tool execution level. |
| 8 | + |
| 9 | +## Solution: 4-Layer Context Approach |
| 10 | + |
| 11 | +This solution uses four existing PraisonAI features to ensure domain context is properly maintained: |
| 12 | + |
| 13 | +### 1. **Custom Tool Wrappers** |
| 14 | +```python |
| 15 | +def create_domain_aware_tools(target_domain: str): |
| 16 | + def query_fofa(query: str = None) -> dict: |
| 17 | + if query is None or query == "example.com": |
| 18 | + query = target_domain |
| 19 | + # Tool implementation with domain injection |
| 20 | +``` |
| 21 | + |
| 22 | +### 2. **Agent Instructions** |
| 23 | +```python |
| 24 | +agent = Agent( |
| 25 | + instructions=f""" |
| 26 | + CRITICAL DOMAIN CONTEXT: You are working exclusively with the domain '{domain}'. |
| 27 | + All operations, tool calls, and analysis must focus on this specific domain. |
| 28 | + Never use example.com or generic examples - always use {domain}. |
| 29 | + """, |
| 30 | + tools=domain_tools |
| 31 | +) |
| 32 | +``` |
| 33 | + |
| 34 | +### 3. **Task Context Parameter** |
| 35 | +```python |
| 36 | +task = Task( |
| 37 | + description=f"Analyze domain {domain}", |
| 38 | + context=[domain_context.get_context()], # Pass domain context |
| 39 | + agent=agent |
| 40 | +) |
| 41 | +``` |
| 42 | + |
| 43 | +### 4. **Shared Memory** |
| 44 | +```python |
| 45 | +agents = PraisonAIAgents( |
| 46 | + agents=[agent1, agent2], |
| 47 | + tasks=[task1, task2], |
| 48 | + memory=True, # Enable shared memory for context |
| 49 | + memory_config={ |
| 50 | + "provider": "rag", |
| 51 | + "config": {"collection_name": f"{domain}_analysis"} |
| 52 | + } |
| 53 | +) |
| 54 | +``` |
| 55 | + |
| 56 | +## Usage |
| 57 | + |
| 58 | +```python |
| 59 | +from domain_context_solution import main |
| 60 | + |
| 61 | +# Set your target domain |
| 62 | +domain = "your-domain.com" |
| 63 | + |
| 64 | +# Run the hierarchical workflow |
| 65 | +main() |
| 66 | +``` |
| 67 | + |
| 68 | +## Key Benefits |
| 69 | + |
| 70 | +- ✅ **No Core SDK Changes** - Uses only existing framework features |
| 71 | +- ✅ **Multi-Layer Reliability** - Context maintained through multiple mechanisms |
| 72 | +- ✅ **Domain-Specific Results** - Tools focus on specified domain |
| 73 | +- ✅ **Backward Compatible** - Doesn't break existing functionality |
| 74 | +- ✅ **Scalable Pattern** - Works for any domain or context type |
| 75 | + |
| 76 | +## Files |
| 77 | + |
| 78 | +- `domain-context-solution.py` - Complete working solution |
| 79 | +- `README-domain-context.md` - This documentation |
| 80 | + |
| 81 | +This pattern can be adapted for any context passing scenario in PraisonAI multi-agent systems. |
0 commit comments