Skip to main content

A lightweight multi-agent framework with ReAct reasoning, tool dispatch, and MCP integration

Project description

SimAgentPlg

A lightweight multi-agent framework with ReAct reasoning, tool dispatch, and MCP integration.

Features

  • ReAct Agent — ReAct (Reasoning + Acting) loop with multi-turn tool calling
  • Chat Agent — simple conversational agent with multi-turn history support
  • Tool Dispatch — convention-over-configuration: define do_{tool_name} methods, auto-routed via reflection
  • MCP Integration — pluggable MCP server manager for external tool providers
  • Skill System — skill-based prompt injection for domain-specific behaviors
  • Built-in Bash Executor — async sandboxed bash execution with timeout, output truncation, and blacklist filtering
  • Stateless Execution — each runtime() call starts with a clean context; history is caller-managed
  • OpenAI-compatible — works with any OpenAI-compatible API (DeepSeek, etc.)

Installation

pip install simagentplg

Or with uv:

uv pip install simagentplg

Quick Start

Set up your environment variables (.env):

CHAT_MODEL=deepseek-chat
MODEL_API_KEY=sk-xxxxxxxx
MODEL_URL=https://api.deepseek.com
LLM_TIMEOUT=30

Chat Agent

from simagentplg import ChatLoop

loop = ChatLoop()
result = await loop.runtime(task="介绍一下你自己")

# With multi-turn history
history = [
    {"role": "user", "content": "今天天气不错"},
    {"role": "assistant", "content": "是啊,适合出去走走"},
]
result = await loop.runtime(task="我们去哪", history=history)

ReAct Agent

from simagentplg import ReactLoop

loop = ReactLoop()
result = await loop.runtime(task="帮我写一个Python脚本打印当前时间")

The ReAct agent supports built-in tools (like bash_run) and any MCP tools configured in mcp_config.json.

MCP Configuration

Place an mcp_config.json alongside your ReactLoop:

{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": ["-y", "@anthropic/mcp-playwright"]
    }
  }
}

Architecture

LLMConfig (BaseHandler, ABC)
├── ChatLoop         — stateless conversational agent
├── ReactLoop        — ReAct reasoning + tool dispatch
│   ├── MCP tools    — external tools via MCP protocol
│   ├── Skill system — domain-specific prompt injection
│   └── Local tools  — built-in bash_run, extensible
└── (future) PlanLoop / ExecuteLoop

Tool Dispatch Flow

LLM calls "bash_run"
    → BaseHandler.dispatch("bash_run", args)
        → hasattr(self, "do_bash_run")?  YES
            → await self.do_bash_run(args)  ← local tool
        → NO
            → "未知工具" → MCP fallback  ← external tool

Adding a Local Tool

  1. Define the tool schema in tool_schema.py:
LOCAL_TOOLS = [
    {
        "type": "function",
        "function": {
            "name": "calculator",
            "description": "Evaluate a math expression",
            "parameters": {
                "type": "object",
                "properties": {
                    "expression": {"type": "string", "description": "Math expression"}
                },
                "required": ["expression"]
            }
        }
    }
]
  1. Add the do_calculator method in LLMConfig:
async def do_calculator(self, args: dict) -> StepOutcome:
    result = eval(args["expression"])
    return StepOutcome(data=result, next_prompt="\n")

All agents automatically inherit the new tool.

API

ChatLoop

loop = ChatLoop(temperature=0.7)
await loop.runtime(*, task, system_prompt=None, history=None) -> str | None

ReactLoop

loop = ReactLoop()
await loop.runtime(*, task, system_prompt=None, history=None) -> str | None

StepOutcome

@dataclass
class StepOutcome:
    data: Any              # tool return value
    next_prompt: str | None  # None = task complete
    should_exit: bool      # True = force exit

Requirements

  • Python >= 3.12
  • fastmcp >= 3.4.2
  • openai >= 2.41.0
  • python-dotenv >= 1.2.2

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simagentplg-0.1.2.tar.gz (81.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simagentplg-0.1.2-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

Details for the file simagentplg-0.1.2.tar.gz.

File metadata

  • Download URL: simagentplg-0.1.2.tar.gz
  • Upload date:
  • Size: 81.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for simagentplg-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f5f72e8bbbda521666e0c07aff9c3cbc998410d49a3f9a5ed7c669d2d1d367f4
MD5 9b647925103b699df46e659b7d2a4857
BLAKE2b-256 dd117479f9fc4458f41ff4ece5cd7ef12bfd315310a62568038142afb9b867e6

See more details on using hashes here.

File details

Details for the file simagentplg-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: simagentplg-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 18.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for simagentplg-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6a7699478857946724c1a4085ec8ac5bd37853cb82d1951c8128585a14c5a1ee
MD5 c194bfce33955a03e32c4a322660cc1d
BLAKE2b-256 ad5db1fc5e4a43a9de70e5a99c42a8d7d98a067f6cde2f010c889d481f8d73e3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page