Guide to Domain-Specific Training
# Define domain in JSON { "domain": "customer_service", "description": """Handle customer inquiries and complaints with: 1. Professional and empathetic responses 2. Clear problem resolution steps 3. Proper escalation procedures 4. Follow-up mechanisms""", "examples": [ { "scenario": "Customer complains about late delivery", "expected_handling": "..." } ] }
# Create comprehensive domain definition domain_config = { "domain": "medical_diagnosis", "description": """Assist in medical diagnosis by: 1. Gathering relevant patient information 2. Analyzing symptoms systematically 3. Suggesting possible diagnoses 4. Recommending next steps Key requirements: - Follow medical guidelines - Maintain patient privacy - Show diagnostic reasoning - Highlight urgent cases""", "constraints": [ "Never provide final diagnosis", "Always recommend professional consultation", "Maintain HIPAA compliance", "Flag emergency situations" ], "evaluation_criteria": { "accuracy": { "weight": 0.4, "metrics": [ "Correct symptom interpretation", "Appropriate recommendations", "Guidelines compliance" ] }, "communication": { "weight": 0.3, "metrics": [ "Clear explanations", "Professional tone", "Patient-friendly language" ] }, "safety": { "weight": 0.3, "metrics": [ "Risk assessment", "Emergency recognition", "Privacy protection" ] } } }
# Create domain-specific agent async def create_domain_expert(domain_config): # Generate specialized prompt prompt = await evolution.make_base_agent_prompt_template( domain=domain_config["domain"], description=domain_config["description"] ) # Add constraints for constraint in domain_config["constraints"]: prompt += f"\nIMPORTANT: {constraint}" # Create agent return Agent(AgentConfig( llm_config=llm_config, prompt_template=prompt )) # Create multiple specialists specialists = [] for domain in domains: expert = await create_domain_expert(domain) specialists.append(expert)
# Generate domain-specific test cases async def create_test_suite(domain_config): # Create specialized adversary adversary = await evolution.build_adversary( domain=domain_config["domain"], description=f"""Generate challenging scenarios that test: {domain_config['evaluation_criteria']}""" ) # Create specialized judge judge = await evolution.build_judge( domain=domain_config["domain"], description=f"""Evaluate responses based on: {json.dumps(domain_config['evaluation_criteria'], indent=2)}""" ) return { "adversary": adversary, "judge": judge } # Create test suites test_suites = {} for domain in domains: test_suites[domain["domain"]] = await create_test_suite(domain)
# Test agents in their domains async def evaluate_domain_performance(agent, domain_config): test_suite = test_suites[domain_config["domain"]] # Run interactions history = await evolution.run_interaction( agent, test_suite["adversary"] ) # Get domain-specific score score = await evolution.get_agent_score( history, test_suite["judge"] ) return { "score": score, "history": history } # Evaluate all specialists results = {} for domain, specialist in zip(domains, specialists): results[domain["domain"]] = await evaluate_domain_performance( specialist, domain )