Skip to content

tonycao/MiniAgent

Repository files navigation

MiniAgent Logo

MiniAgent Framework

A simple but powerful agent framework that utilizes LLMs for task planning and execution using the ReACT (Reasoning, Acting, and Observing) framework.

Features

  • Intelligent Planning: Breaks down complex tasks into smaller, manageable pieces
  • ReACT Framework: Implements Reasoning → Acting → Observing cycle for iterative problem solving
  • Tool Integration: Built-in tools for web search, browser automation, and more
  • LLM Integration: Uses OpenAI's GPT models for reasoning and planning
  • Extensible: Easy to add new tools and capabilities

Installation

  1. Clone the repository
  2. Install dependencies:
    pip install -r requirements.txt
  3. Set up environment variables:
    cp env_example.txt .env
    # Edit .env with your OpenAI API key

Quick Installation

# Install the package
pip install -e .

# Set up environment
cp env_example.txt .env
# Edit .env with your OpenAI API key

Quick Start

Using Python

from miniagent import Agent

# Initialize the agent
agent = Agent()

# Give the agent a task
result = agent.run("Research the latest developments in AI and summarize the key findings")
print(result)

Using Command Line

# Run a simple task
python -m miniagent.cli "Search for the current weather in New York"

# Run demos
python -m miniagent.cli --demo

# List available tools
python -m miniagent.cli --list-tools

Architecture

Core Components

  1. Planner: Breaks down tasks into subtasks
  2. ReACT Engine: Manages the reasoning, acting, and observing cycle
  3. Tool Manager: Handles tool execution and results
  4. LLM Interface: Communicates with language models

Available Tools

  • Web Search: Search the internet for information
  • Browser Automation: Navigate and interact with web pages
  • File Operations: Read and write files
  • Text Processing: Analyze and summarize text

Usage Examples

Basic Task Execution

agent = Agent()
result = agent.run("Find the current weather in New York")

Complex Task with Planning

agent = Agent()
result = agent.run("""
    Research the top 5 AI companies in 2024, 
    analyze their business models, and create a summary report
""")

File Operations

agent = Agent()
result = agent.run("""
    Create a file with information about Python programming,
    then read and analyze the content
""")

Web Scraping

agent = Agent()
result = agent.run("""
    Navigate to https://example.com,
    extract the main content, and summarize it
""")

Configuration

The framework can be configured through environment variables:

  • OPENAI_API_KEY: Your OpenAI API key (required)
  • OPENAI_MODEL: Model to use (default: gpt-4)
  • MAX_ITERATIONS: Maximum ReACT iterations (default: 10)
  • TEMPERATURE: LLM temperature for creativity (default: 0.1)
  • ENABLE_WEB_SEARCH: Enable web search tool (default: true)
  • ENABLE_BROWSER: Enable browser automation (default: true)
  • ENABLE_FILE_OPS: Enable file operations (default: true)
  • BROWSER_HEADLESS: Run browser in headless mode (default: true)
  • BROWSER_TIMEOUT: Browser timeout in seconds (default: 30)

Extending the Framework

Adding New Tools

from miniagent.tools import BaseTool

class MyCustomTool(BaseTool):
    name = "my_custom_tool"
    description = "Description of what this tool does"
    
    def execute(self, **kwargs):
        # Your tool logic here
        return {"result": "tool output"}

Custom Planning Strategies

from miniagent.planner import BasePlanner

class MyCustomPlanner(BasePlanner):
    def plan(self, task: str) -> List[str]:
        # Your planning logic here
        return ["step1", "step2", "step3"]

Testing

Run the test suite to verify everything works:

python test_agent.py

Development

To set up the development environment:

# Install in development mode
pip install -e .

# Run tests
python test_agent.py

# Run demos
python demo.py

License

MIT License

About

a minimal agent framework

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages