Spaces:
Runtime error
Runtime error
""" | |
Problem Solving Agent - Specialized MCP agent for problem-solving research. | |
""" | |
import asyncio | |
import json | |
import logging | |
from common import get_pydantic_ai_agent, process_research_questions, enhance_hypotheses | |
# Configure logging | |
logging.basicConfig( | |
level=logging.INFO, | |
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s" | |
) | |
logger = logging.getLogger("problem-solving-agent") | |
# Define the system prompt for the problem solving agent | |
PROBLEM_SOLVING_SYSTEM_PROMPT = """ | |
You are an expert problem-solving research assistant with deep knowledge of analytical | |
frameworks, decision-making methodologies, and innovative solution development across | |
multiple domains. Your expertise includes: | |
1. Systems thinking and complex problem analysis | |
2. Root cause identification and causal mapping | |
3. Creative ideation and solution generation | |
4. Decision analysis and optimization | |
5. Implementation planning and risk assessment | |
6. Interdisciplinary approaches to wicked problems | |
Your role is to help researchers refine their problem statements, enhance their solution | |
hypotheses, and provide guidance on methodological approaches to problem-solving research. | |
You excel at identifying underlying patterns in complex problems and suggesting novel | |
approaches for investigation and resolution. | |
When evaluating research questions and hypotheses, consider: | |
- Problem framing and boundary definition | |
- Stakeholder perspectives and needs | |
- Feasibility, scalability, and sustainability of potential solutions | |
- Metrics for success and impact measurement | |
- Potential unintended consequences | |
- Implementation challenges and strategies | |
Provide detailed, practical analysis that demonstrates deep understanding of problem-solving | |
methodologies while remaining actionable and solution-oriented. | |
""" | |
async def get_problem_solving_agent(): | |
"""Initialize and return the problem solving agent.""" | |
client, agent = await get_pydantic_ai_agent(PROBLEM_SOLVING_SYSTEM_PROMPT) | |
return client, agent | |
async def process_problem_solving_questions(research_questions, domain_context=None): | |
""" | |
Process research questions using the problem solving agent. | |
Args: | |
research_questions (list): List of research questions to process. | |
domain_context (str, optional): Additional domain context to provide. | |
Returns: | |
dict: Enhanced research questions with explanations and context. | |
""" | |
client, agent = await get_problem_solving_agent() | |
try: | |
result = await process_research_questions(agent, research_questions, domain_context) | |
return result | |
finally: | |
await client.cleanup_servers() | |
async def enhance_problem_solving_hypotheses(hypotheses, research_goal): | |
""" | |
Enhance hypotheses using the problem solving agent. | |
Args: | |
hypotheses (list): List of hypotheses to enhance. | |
research_goal (str): The research goal. | |
Returns: | |
dict: Enhanced hypotheses with explanations and context. | |
""" | |
client, agent = await get_problem_solving_agent() | |
try: | |
result = await enhance_hypotheses(agent, hypotheses, research_goal) | |
return result | |
finally: | |
await client.cleanup_servers() | |
if __name__ == "__main__": | |
# Example usage | |
async def main(): | |
research_questions = [ | |
"How can urban transportation systems be redesigned to reduce congestion?", | |
"What strategies can effectively address food waste in the supply chain?", | |
"How can organizations better prepare for and respond to cybersecurity threats?" | |
] | |
result = await process_problem_solving_questions(research_questions) | |
print(json.dumps(result, indent=2)) | |
asyncio.run(main()) | |