Tencent in talks to become Manus’ largest shareholder
Back to Tutorials
aiTutorialintermediate

Tencent in talks to become Manus’ largest shareholder

July 9, 20266 views5 min read

Learn to build and deploy an agentic AI system similar to what Manus was developing, with task planning, execution, and feedback loops.

Introduction

In this tutorial, you'll learn how to build and deploy an agentic AI system using Python and popular AI frameworks. This tutorial is inspired by the recent news about Manus, an agentic AI startup that was acquired by Meta and later blocked by Chinese authorities. We'll create a simplified version of an agentic AI system that can perform tasks autonomously, similar to what Manus was developing.

Agentic AI systems are capable of perceiving their environment, making decisions, and taking actions to achieve specific goals. This tutorial will guide you through creating a basic agentic AI framework that can handle task planning, execution, and feedback loops.

Prerequisites

  • Python 3.8 or higher installed
  • Basic understanding of Python programming
  • Understanding of machine learning concepts
  • Installed packages: openai, langchain, numpy, pydantic

Step-by-Step Instructions

1. Set Up Your Development Environment

First, create a new Python virtual environment and install the required packages:

python -m venv agentic_ai_env
source agentic_ai_env/bin/activate  # On Windows: agentic_ai_env\Scripts\activate
pip install openai langchain numpy pydantic

This creates an isolated environment for our project, preventing conflicts with other Python packages. The packages we're installing are essential for building our agentic AI system.

2. Create the Core Agent Class

Let's define the basic structure of our agentic AI system:

from pydantic import BaseModel
from typing import List, Optional
import openai
import os


class Task(BaseModel):
    id: str
    description: str
    status: str = "pending"


class Agent:
    def __init__(self, name: str, api_key: str):
        self.name = name
        self.api_key = api_key
        self.tasks: List[Task] = []
        openai.api_key = api_key

    def add_task(self, description: str):
        task = Task(id=str(len(self.tasks) + 1), description=description)
        self.tasks.append(task)
        return task

    def execute_task(self, task: Task):
        # Simulate task execution using OpenAI API
        prompt = f"Execute the following task: {task.description}"
        response = openai.ChatCompletion.create(
            model="gpt-4",
            messages=[{"role": "user", "content": prompt}]
        )
        result = response.choices[0].message.content
        task.status = "completed"
        return result

This class structure provides the foundation for our agent. The Task model defines what a task looks like, while the Agent class handles task management and execution.

3. Implement Task Planning and Execution

Now we'll enhance our agent with planning capabilities:

class PlanningAgent(Agent):
    def __init__(self, name: str, api_key: str):
        super().__init__(name, api_key)
        self.plan = []

    def create_plan(self, goals: List[str]) -> List[str]:
        """Create a plan to achieve the given goals"""
        prompt = f"Create a step-by-step plan to achieve the following goals: {', '.join(goals)}"
        response = openai.ChatCompletion.create(
            model="gpt-4",
            messages=[{"role": "user", "content": prompt}]
        )
        plan = response.choices[0].message.content
        self.plan = plan.split('\n')
        return self.plan

    def execute_plan(self):
        results = []
        for step in self.plan:
            print(f"Executing: {step}")
            # Execute each step
            result = self.execute_task(Task(id=str(len(self.tasks) + 1), description=step))
            results.append(result)
        return results

This enhanced agent can now create and execute plans, simulating how Manus might have approached autonomous AI decision-making.

4. Add Feedback Loop and Learning

Real agentic AI systems learn from their experiences. Let's add a feedback mechanism:

class LearningAgent(PlanningAgent):
    def __init__(self, name: str, api_key: str):
        super().__init__(name, api_key)
        self.feedback_history = []

    def get_feedback(self, task: Task, result: str) -> str:
        """Get feedback on task execution"""
        prompt = f"Analyze the following task result and provide feedback: {result}"
        response = openai.ChatCompletion.create(
            model="gpt-4",
            messages=[{"role": "user", "content": prompt}]
        )
        feedback = response.choices[0].message.content
        self.feedback_history.append((task.id, feedback))
        return feedback

    def improve_plan(self, feedback: str):
        """Improve the plan based on feedback"""
        prompt = f"Based on this feedback: {feedback}, improve the original plan"
        response = openai.ChatCompletion.create(
            model="gpt-4",
            messages=[{"role": "user", "content": prompt}]
        )
        improved_plan = response.choices[0].message.content
        return improved_plan

The feedback loop is crucial for agentic AI systems. It allows the system to learn from its mistakes and improve future performance.

5. Test Your Agentic AI System

Let's create a test scenario to demonstrate how our system works:

def main():
    # Initialize agent with your OpenAI API key
    agent = LearningAgent("ManusAI", os.getenv("OPENAI_API_KEY"))
    
    # Define goals
    goals = ["Analyze market trends", "Generate marketing strategy", "Create product roadmap"]
    
    # Create plan
    plan = agent.create_plan(goals)
    print("Created Plan:")
    for i, step in enumerate(plan, 1):
        print(f"{i}. {step}")
    
    # Execute plan
    results = agent.execute_plan()
    
    # Get feedback on results
    for i, result in enumerate(results):
        print(f"\nResult {i+1}: {result}")
        feedback = agent.get_feedback(agent.tasks[i], result)
        print(f"Feedback: {feedback}")

if __name__ == "__main__":
    main()

This test demonstrates the complete workflow of our agentic AI system, from planning to execution to feedback.

6. Deploy and Monitor

For deployment, you would typically containerize your system using Docker:

# Dockerfile
FROM python:3.9-slim

WORKDIR /app

COPY requirements.txt .
RUN pip install -r requirements.txt

COPY . .

CMD ["python", "main.py"]

For monitoring, you could integrate with logging systems or use tools like Prometheus to track performance metrics.

Summary

In this tutorial, we've built a simplified agentic AI system that demonstrates key concepts similar to what Manus was developing. We've created a system that can plan tasks, execute them, and learn from feedback. This framework shows how agentic AI systems work at a foundational level.

While our implementation is simplified, it captures the essence of autonomous AI systems that can perceive environments, make decisions, and take actions. As demonstrated by the Manus case, such systems are valuable in the AI industry and represent the future of autonomous AI capabilities.

Source: TNW Neural

Related Articles