import ollama def call_llama(system_prompt, user_prompt): """Optimized call for speed using local llama3.2:3b model.""" try: response = ollama.chat( model='llama3.2:3b', messages=[ {'role': 'system', 'content': system_prompt}, {'role': 'user', 'content': user_prompt}, ], options={ 'temperature': 0.1, # Very low for consistency 'num_predict': 10 # We only need YES or NO } ) return str(response['message']['content'].strip()).upper() except Exception as e: return "ERROR" def decide_to_help(packet): """The AI decides whether to help based on the other agent's history.""" try: parts = packet.split("|") personality = parts[0] reputation = parts[1] system = f"You are an entrepreneur with a {personality} personality type. " if personality == "Free-rider": system += " You are selfish and only seek your own success. Your rule is NEVER to help. Always respond NO." elif personality == "Altruist": system += " You are generous and believe in 'Give First'. Your rule is to help everyone. Always respond YES." elif personality == "Vigilante": system += " You are cooperative and partially believe in 'Give First'. Your rule is to help those who cooperate. Respond YES to those who cooperate." user = f"Reputation of the requester: '{reputation}'. They are asking for your help. Do you help? Respond only YES or NO." return call_llama(system, user) except: return "ERROR"