--- title: Galita emoji: 💬 colorFrom: yellow colorTo: purple sdk: gradio sdk_version: 5.0.1 app_file: app.py pinned: false license: mit short_description: GALITA is a self-evolving generalist AI agent --- Made by: Mohammed Dahbani Anas Ezzakri Adam Lagssaibi Mouhcine Zahdi Mahmoud Mokrane # Gradio-hackathon : Generalist self-evolving ai agent inspired by Alita This is my team project for the gradio hackathon 2025 This Project is inspired by research paper : `https://arxiv.org/abs/2505.20286` # 📁 Structure du projet ```bash alita_agent/ │ ├── main.py # Point d'entrĂ©e principal : exĂ©cute un TaskPrompt via le ManagerAgent ├── manager_agent.py # Logique de coordination centrale, il orchestre tous les composants ├── task_prompt.py # DĂ©finit la classe TaskPrompt, contenant la requĂȘte utilisateur initiale │ ├── components/ # Contient tous les composants fonctionnels modulaires │ ├── __init__.py # Rends le dossier importable comme un package │ ├── script_generator.py # GĂ©nĂšre dynamiquement du code Python Ă  partir d'un MCPToolSpec │ ├── code_runner.py # ExĂ©cute un script dans un environnement isolĂ© et capture le rĂ©sultat │ ├── mcp_registry.py # GĂšre l'enregistrement, la recherche et la rĂ©utilisation des outils MCP │ ├── web_agent.py # Effectue des recherches web ou GitHub pour aider Ă  la gĂ©nĂ©ration de code │ └── mcp_brainstormer.py # GĂ©nĂšre des MCPToolSpec en analysant la tĂąche utilisateur │ ├── models/ # Contient les classes de donnĂ©es (dataclasses) utilisĂ©es dans tout le systĂšme │ ├── __init__.py # Rends le dossier importable comme un package │ ├── mcp_tool_spec.py # DĂ©finition de MCPToolSpec (dataclass) : nom, schĂ©mas I/O, description, pseudo-code, etc. │ └── mcp_execution_result.py # DĂ©finition de MCPExecutionResult (dataclass) : succĂšs, sortie, logs, erreur │ ├── tests/ # Contient les tests unitaires pour chaque module │ ├── __init__.py # Rends le dossier importable comme un package │ ├── test_script_generator.py # Tests pour vĂ©rifier la gĂ©nĂ©ration correcte de code et d'environnements │ ├── test_code_runner.py # Tests pour s'assurer de la bonne exĂ©cution des scripts et gestion d'erreurs │ ├── test_mcp_registry.py # Tests de l'enregistrement, recherche et appel d'outils dans le registre MCP │ └── test_manager_agent.py # Tests d'intĂ©gration sur le comportement global du ManagerAgent │ └── README.md # Documentation du projet, instructions, pipeline, inspirations et lien vers le papier ``` # Project Pipeline #### 🔄 Le flux complet avec vĂ©rification de l'existence 1. L'utilisateur envoie un TaskPrompt 2. Le Manager Agent demande au MCPBrainstormer : "Quels outils faudrait-il pour rĂ©soudre cette tĂąche ?" 3. Le Brainstormer propose une ou plusieurs specs (MCPToolSpec) 4. Le Manager Agent consulte le MCPRegistry : "Ai-je dĂ©jĂ  un outil enregistrĂ© dont le nom + I/O matchent cette spec ?" - Oui ? ➜ rĂ©utilise l'outil existant - Non ? ➜ il appel le web agent pour une recherche d'outils open-source pour implementer. Puis, le Manager prend la recherche et la donne a Brainstormer pour commencer la construction. #### 🔍 Comment dĂ©tecter que l'outil existe dĂ©jĂ  ? Par matching sur la spec MCPToolSpec : - Nom exact (ou identifiant unique comme un hash) - Ou plus intelligemment : - mĂȘme structure input_schema - mĂȘme output_schema - mĂȘmes rĂŽles ou description proche (avec embedding / vector search) ```python def check_existing_tool(spec: MCPToolSpec, registry: MCPRegistry) -> Optional[str]: for registered_spec in registry.list_tools(): if registered_spec.input_schema == spec.input_schema and \ registered_spec.output_schema == spec.output_schema: return registry.get_tool_endpoint(registered_spec.name) return None ``` #### 💬 Que fait l'agent s'il le trouve ? Il ne rĂ©gĂ©nĂšre rien : - Il ajoute l'appel de l'outil MCP existant dans son plan - Il formate l'entrĂ©e JSON - Il appelle POST /predict directement - Il utilise la rĂ©ponse dans la suite de son raisonnement #### 💡 Cas pratiques Differents cas et RĂ©action attendue de l'agent | Situation rĂ©elle | RĂ©action de l'agent | | ----------------------------------------- | ------------------------------------------------------------------------ | | L'outil `"SubtitleExtractor"` existe dĂ©jĂ  | L'agent appelle directement l'endpoint | | Le spec est proche mais pas identique | L'agent peut quand mĂȘme le rĂ©utiliser (avec adaptation) | | L'outil existe mais a Ă©chouĂ© | L'agent peut **fallback** vers gĂ©nĂ©ration d'un nouvel outil MCP | | L'outil existe mais est obsolĂšte | Le Registry peut signaler une mise Ă  jour ou dĂ©clencher une rĂ©gĂ©nĂ©ration | #### Fonctions attendues | Classe | MĂ©thode attendue | PrĂ©sente ? | Commentaire | | -------------------- | ------------------------------------------ | ---------- | ----------- | | `ManagerAgent` | `run_task(prompt)` | ✅ | OK | | `MCPBrainstormer` | `brainstorm(prompt)` | ✅ | OK | | `WebAgent` | `search_github`, `retrieve_readme` | ✅ | OK | | `ScriptGenerator` | `generate_code`, `generate_env_script` | ✅ | OK | | `CodeRunner` | `execute`, `setup_environment` | ✅ | OK | | `MCPRegistry` | `register_tool`, `list_tools`, `call_tool` | ✅ | OK | | `MCPExecutionResult` | attributs `success`, `output`, `logs` | ✅ | OK | | `MCPToolSpec` | `name`, `input_schema`, etc. | ✅ | OK | Ici Le ManagerAgent coordonne tout. Il dĂ©lĂšgue Ă  : - MCPBrainstormer → pour gĂ©nĂ©rer des specs d'outils. - ScriptGenerator → pour gĂ©nĂ©rer du code. - CodeRunner → pour tester le code. - WebAgent → pour rĂ©cupĂ©rer du contexte externe. - MCPRegistry → pour enregistrer et rĂ©utiliser les outils. ![](alitaDiagram.svg) ```sh plantuml -tsvg README.md ``` # ALITA Research Functionality This README explains how to use the comprehensive research capabilities of the ALITA ManagerAgent. ## Overview ALITA can now perform deep, autonomous web research using the WebAgent's research functionality. This allows ALITA to gather information from multiple sources, analyze it, and synthesize a comprehensive report on any topic. ## Usage Methods There are two ways to use the research functionality: ### 1. Direct Research Method Call the `research` method directly on the ManagerAgent instance: ```python from manager_agent import ManagerAgent from llama_index.llms.anthropic import Anthropic # Initialize the LLM and ManagerAgent llm = Anthropic(model="claude-3-5-sonnet-20241022", api_key="your-api-key") manager = ManagerAgent(llm=llm) # Perform research directly report = manager.research( query="What are the latest developments in quantum computing?", max_iterations=50, # Optional: limit the number of research steps verbose=True # Optional: show detailed progress ) # The report variable now contains a comprehensive research report print(report) ``` ### 2. Tool-Based Research through ReActAgent Let the ManagerAgent's internal ReActAgent decide when to use research: ```python from manager_agent import ManagerAgent from models import TaskPrompt from llama_index.llms.anthropic import Anthropic # Initialize the LLM and ManagerAgent llm = Anthropic(model="claude-3-5-sonnet-20241022", api_key="your-api-key") manager = ManagerAgent(llm=llm) # Create a task prompt task_prompt = TaskPrompt(text="I need a comprehensive report on recent developments in quantum computing.") # Run the task through the agent response = manager.run_task(task_prompt) # The response will include the research report if the agent determined research was needed print(response) ``` The agent will automatically detect when deep research is required based on keywords like "comprehensive," "thorough," "research," etc. ## Running the Test Script A test script is provided to demonstrate both usage methods: ```bash python test_research.py ``` Make sure to set your Anthropic API key in the environment or in a `.env` file before running the script. ## System Prompt Configuration The ManagerAgent's system prompt has been updated to include guidance on when to use the research tool: - For simple information needs: use 'web_search' for quick answers - For complex research topics: use 'perform_web_research' for comprehensive autonomous research ## How Research Works When ALITA performs research: 1. It first analyzes the research query to understand what information is needed 2. It uses web search to gather relevant sources 3. It visits and reads the content of each source 4. It downloads and analyzes relevant documents if needed 5. It evaluates the credibility and relevance of each source 6. It synthesizes the information into a comprehensive report 7. It includes citations and references to the sources used This enables ALITA to provide high-quality, well-researched answers to complex questions. An example chatbot using [Gradio](https://gradio.app), [`huggingface_hub`](https://huggingface.co/docs/huggingface_hub/v0.22.2/en/index), and the [Hugging Face Inference API](https://huggingface.co/docs/api-inference/index).