Skip to main content
Glama
workflows.py7.4 kB
"""Enhanced workflow management for AutoGen MCP with latest features.""" from typing import Dict, List, Optional, Sequence, Any, cast import asyncio import json from datetime import datetime import autogen from autogen import ConversableAgent, Agent, GroupChat, GroupChatManager, AssistantAgent, UserProxyAgent from .agents import AgentManager from .config import AgentConfig, ServerConfig class WorkflowManager: """Enhanced workflow manager with support for latest AutoGen features.""" def __init__(self): """Initialize the workflow manager.""" self._workflows = {} self._workflow_templates = { "code_generation": self._code_generation_workflow, "research": self._research_workflow, "analysis": self._analysis_workflow, "creative_writing": self._creative_writing_workflow, "problem_solving": self._problem_solving_workflow, "code_review": self._code_review_workflow, } def add_workflow(self, name: str, config: Dict[str, Any]) -> None: """Add a workflow configuration.""" self._workflows[name] = config def get_workflow(self, name: str) -> Optional[Dict[str, Any]]: """Get a workflow configuration.""" return self._workflows.get(name) def list_workflows(self) -> List[str]: """List all available workflows.""" return list(self._workflows.keys()) async def execute_workflow( self, workflow_name: str, input_data: Dict[str, Any], output_format: str = "json", quality_checks: bool = False ) -> Dict[str, Any]: """Execute a predefined workflow with enhanced features.""" if workflow_name in self._workflow_templates: return await self._workflow_templates[workflow_name]( input_data, output_format, quality_checks ) elif workflow_name in self._workflows: return await self._execute_custom_workflow( self._workflows[workflow_name], input_data, output_format, quality_checks ) else: raise ValueError(f"Unknown workflow: {workflow_name}") async def _code_generation_workflow( self, input_data: Dict[str, Any], output_format: str, quality_checks: bool ) -> Dict[str, Any]: """Enhanced code generation workflow.""" task = input_data.get("task", "") language = input_data.get("language", "python") requirements = input_data.get("requirements", []) # Return a structured result without actually creating agents # In a full implementation, you would create and execute agents here result = { "workflow": "code_generation", "task": task, "language": language, "timestamp": datetime.now().isoformat(), "stages": [ { "stage": "architecture", "result": f"Designed architecture for {task} in {language}" }, { "stage": "implementation", "result": f"Generated {language} code with requirements: {requirements}" } ], "format": output_format, "quality_checks": quality_checks } return result async def _research_workflow( self, input_data: Dict[str, Any], output_format: str, quality_checks: bool ) -> Dict[str, Any]: """Enhanced research workflow.""" topic = input_data.get("topic", "") depth = input_data.get("depth", "detailed") result = { "workflow": "research", "topic": topic, "depth": depth, "timestamp": datetime.now().isoformat(), "stages": [ { "stage": "research", "result": f"Researched topic: {topic} with {depth} analysis" }, { "stage": "analysis", "result": f"Analyzed findings for {topic}" } ], "format": output_format, "quality_checks": quality_checks } return result async def _analysis_workflow( self, input_data: Dict[str, Any], output_format: str, quality_checks: bool ) -> Dict[str, Any]: """Data analysis workflow.""" return { "workflow": "analysis", "input": input_data, "result": "Analysis workflow executed", "format": output_format, "timestamp": datetime.now().isoformat() } async def _creative_writing_workflow( self, input_data: Dict[str, Any], output_format: str, quality_checks: bool ) -> Dict[str, Any]: """Creative writing workflow.""" return { "workflow": "creative_writing", "input": input_data, "result": "Creative writing workflow executed", "format": output_format, "timestamp": datetime.now().isoformat() } async def _problem_solving_workflow( self, input_data: Dict[str, Any], output_format: str, quality_checks: bool ) -> Dict[str, Any]: """Problem solving workflow.""" return { "workflow": "problem_solving", "input": input_data, "result": "Problem solving workflow executed", "format": output_format, "timestamp": datetime.now().isoformat() } async def _code_review_workflow( self, input_data: Dict[str, Any], output_format: str, quality_checks: bool ) -> Dict[str, Any]: """Code review workflow.""" code = input_data.get("code", "") language = input_data.get("language", "auto-detect") focus_areas = input_data.get("focus_areas", ["security", "performance", "readability"]) result = { "workflow": "code_review", "language": language, "focus_areas": focus_areas, "timestamp": datetime.now().isoformat(), "reviews": [ { "reviewer": "security_reviewer", "result": f"Security review completed for {language} code" }, { "reviewer": "performance_reviewer", "result": f"Performance review completed for {language} code" }, { "reviewer": "style_reviewer", "result": f"Style review completed for {language} code" } ], "format": output_format } return result async def _execute_custom_workflow( self, workflow_config: Dict[str, Any], input_data: Dict[str, Any], output_format: str, quality_checks: bool ) -> Dict[str, Any]: """Execute a custom workflow based on configuration.""" return { "workflow": workflow_config.get("name", "custom"), "type": workflow_config.get("type", "unknown"), "agents": workflow_config.get("agents", []), "input": input_data, "result": "Custom workflow executed", "format": output_format, "timestamp": datetime.now().isoformat() }

Implementation Reference

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/DynamicEndpoints/Autogen_MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server