import logging
# Setup logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
class NipunAdapter:
"""
A simple agent that supports basic text echoing and modulo evaluations.
"""
def __init__(self):
"""Initialize the adapter instance."""
logger.info("[NipunAdapter] Initialized.")
def analyze_prompt(self, text):
"""
Process the input text.
If the input is in the form 'a%b', it computes a modulo b.
Otherwise, it echoes the input.
Args:
text (str): Input text to analyze.
Returns:
str: Processed result or error message.
"""
logger.info(f"[NipunAdapter] Analyzing prompt: {text}")
if "%" in text:
try:
left, right = text.split("%")
left = left.strip()
right = right.strip()
if left.isdigit() and right.isdigit():
result = int(left) % int(right)
return f"The result of {left} % {right} is: {result}"
else:
return "Error: Invalid numbers for modulo operation."
except Exception as e:
logger.error(f"[NipunAdapter] Modulo error: {e}")
return f"Error evaluating modulo: {e}"
# Default fallback
return f"The answer to this question is: {text}"
def run(self, text):
"""
Run the agent logic on the provided text.
Args:
text (str): Input to process.
Returns:
str: Output from analyze_prompt.
"""
return self.analyze_prompt(text)
def connect(self):
"""
Dummy method to simulate connecting to a service.
Returns:
bool: Always returns True for simulation.
"""
logger.info("[NipunAdapter] Connect called.")
return True
def disconnect(self):
"""
Dummy method to simulate disconnecting from a service.
Returns:
bool: Always returns True for simulation.
"""
logger.info("[NipunAdapter] Disconnect called.")
return True
# ✅ Standalone test
if __name__ == "__main__":
adapter = NipunAdapter()
print(adapter.analyze_prompt("25%4")) # Should return 1
print(adapter.analyze_prompt("Hello World")) # Should echo the input
adapter.connect()
adapter.disconnect()