from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool import datetime import requests import pytz import yaml from tools.final_answer import FinalAnswerTool from typing import Dict, Optional import json from Gradio_UI import GradioUI # Below is an example of a tool that does nothing. Amaze us with your creativity ! @tool def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type #Keep this format for the description / args / args description but feel free to modify the tool """A tool that does nothing yet Args: arg1: the first argument arg2: the second argument """ return "What magic will you build ?" @tool def get_payroll_laws(country: str, specific_area: Optional[str] = None) -> str: """Retrieves payroll laws and regulations from the specified country's tax office portal Args: country: The country name or ISO code (e.g., 'USA', 'United Kingdom', 'Germany') specific_area: Optional specific area of payroll law (e.g., 'tax_rates', 'social_security', 'minimum_wage', 'overtime') Returns: A formatted string containing payroll law information for the specified country """ # Mapping of countries to their tax office portals (for reference) tax_portals = { 'USA': 'https://www.irs.gov', 'UK': 'https://www.gov.uk/government/organisations/hm-revenue-customs', 'Germany': 'https://www.bzst.de', 'France': 'https://www.impots.gouv.fr', 'Canada': 'https://www.canada.ca/en/revenue-agency', 'Australia': 'https://www.ato.gov.au', 'India': 'https://www.incometax.gov.in', 'Japan': 'https://www.nta.go.jp', 'Singapore': 'https://www.iras.gov.sg', 'Netherlands': 'https://www.belastingdienst.nl' } # Normalize country input country = country.upper().strip() # Since we cannot directly scrape government websites without proper authorization, # this is a demonstration structure that would return general payroll law information # In production, you would integrate with official APIs or authorized data sources try: # Example structure of payroll laws data # In production, this would fetch from actual APIs or databases payroll_info = { 'USA': { 'tax_rates': { 'federal_income_tax': 'Progressive rates: 10%, 12%, 22%, 24%, 32%, 35%, 37%', 'social_security': '6.2% (employee), 6.2% (employer) on wages up to $160,200 (2023)', 'medicare': '1.45% (employee), 1.45% (employer), additional 0.9% for high earners' }, 'minimum_wage': 'Federal: $7.25/hour (varies by state)', 'overtime': 'Time and a half for hours over 40 per week (FLSA)', 'payroll_frequency': 'Varies: weekly, bi-weekly, semi-monthly, or monthly', 'withholding_requirements': 'Form W-4 for federal withholding', 'reporting': 'Quarterly Form 941, Annual Forms W-2 and W-3', 'portal': tax_portals.get('USA', 'N/A') }, 'UK': { 'tax_rates': { 'income_tax': 'Personal allowance: £12,570, Basic rate: 20%, Higher rate: 40%, Additional rate: 45%', 'national_insurance': 'Class 1: 12% on £12,570-£50,270, 2% above', 'employer_ni': '13.8% on earnings above £175/week' }, 'minimum_wage': 'National Living Wage: £10.42/hour (23+), varies by age', 'pension': 'Auto-enrollment minimum: 8% (3% employer, 5% employee)', 'payroll_frequency': 'Weekly or monthly', 'paye_system': 'Real Time Information (RTI) reporting required', 'reporting': 'Full Payment Submission (FPS) with each payroll', 'portal': tax_portals.get('UK', 'N/A') }, 'GERMANY': { 'tax_rates': { 'income_tax': 'Progressive: 0-45% based on income brackets', 'solidarity_surcharge': '5.5% of income tax (for high earners)', 'church_tax': '8-9% of income tax (if applicable)' }, 'social_insurance': { 'pension': '18.6% (9.3% each)', 'health': '14.6% + additional (split equally)', 'unemployment': '2.4% (1.2% each)', 'long_term_care': '3.05% (varies by state and children)' }, 'minimum_wage': '€12/hour (as of 2023)', 'payroll_frequency': 'Monthly standard', 'reporting': 'DEÜV electronic reporting system', 'portal': tax_portals.get('Germany', 'N/A') } } # Check if country data is available if country not in payroll_info: # For countries not in our example data, provide a template response return f"""Payroll Laws for {country}: Unfortunately, detailed payroll law information for {country} is not currently available in this system. To obtain accurate payroll laws for {country}, please: 1. Visit the official tax authority website: {tax_portals.get(country, 'Please search for the official tax office portal')} 2. Consult with a local payroll specialist or tax advisor 3. Check international payroll service providers for country-specific guides Key areas to research: - Income tax rates and brackets - Social security contributions - Mandatory benefits and insurance - Minimum wage requirements - Overtime regulations - Payroll reporting requirements - Payment frequency regulations Note: Payroll laws change frequently. Always verify current regulations with official sources.""" # Get country data country_data = payroll_info[country] # Build response based on specific area or all information if specific_area: if specific_area in country_data: info = country_data[specific_area] return f"""Payroll Laws for {country} - {specific_area.replace('_', ' ').title()}: {json.dumps(info, indent=2) if isinstance(info, dict) else info} Source Portal: {country_data.get('portal', 'N/A')} Note: This information is for reference only. Please verify with official sources for the most current regulations.""" else: return f"Specific area '{specific_area}' not found. Available areas: {', '.join(country_data.keys())}" # Return all payroll information result = f"""Comprehensive Payroll Laws for {country}: {'='*50}""" for category, details in country_data.items(): if category != 'portal': result += f"\n\n{category.replace('_', ' ').upper()}:" if isinstance(details, dict): for key, value in details.items(): result += f"\n • {key.replace('_', ' ').title()}: {value}" else: result += f"\n {details}" result += f"\n\n{'='*50}" result += f"\nOfficial Portal: {country_data.get('portal', 'N/A')}" result += "\n\n⚠️ IMPORTANT: This information is for reference purposes only. Payroll laws change frequently." result += "\nAlways consult official government sources or qualified professionals for current regulations." return result except Exception as e: return f"""Error retrieving payroll laws for {country}: {str(e)} Please try: 1. Checking the country name/code is correct 2. Specifying a valid area: 'tax_rates', 'social_security', 'minimum_wage', 'overtime' 3. Consulting the official tax portal directly For production use, this tool would need: - API integration with official government data sources - Regular updates to reflect law changes - Proper authentication and compliance with data usage policies""" # Example usage with your HuggingFace model setup if __name__ == "__main__": # Test the tool print(get_payroll_laws("USA")) print("\n" + "="*70 + "\n") print(get_payroll_laws("UK", "tax_rates")) print("\n" + "="*70 + "\n") print(get_payroll_laws("Germany", "social_insurance")) # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder: # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud' model = HfApiModel( max_tokens=2096, temperature=0.5, model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded custom_role_conversions=None, ) # Import tool from Hub image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True) with open("prompts.yaml", 'r') as stream: prompt_templates = yaml.safe_load(stream) agent = CodeAgent( model=model, tools=[final_answer], ## add your tools here (don't remove final answer) max_steps=6, verbosity_level=1, grammar=None, planning_interval=None, name=None, description=None, prompt_templates=prompt_templates ) GradioUI(agent).launch()