Skip to main content

Python chatbot framework with multi-platform channels and LLM agent loop

Project description

motosan-chat (Python)

motosan-chat is a Python chatbot framework with a unified event model, channel adapters, and an LLM agent loop with tool-calling support.

This package mirrors the Rust-side architecture and provides a Python-first developer experience for building multi-platform chatbots.

Features

  • Core runtime: Bot, Thread, IncomingEvent, and Channel protocol
  • Agent runtime: AgentLoop, LlmClient, message/tool-call chain model
  • Tool system: ToolDef, ToolResult, ToolContext, @tool decorator
  • Channels:
    • Web (FastAPI + SSE)
    • Telegram (polling adapter)
    • LINE (webhook adapter)
    • Discord (gateway adapter)
  • AI adapter: MotosanAiClient for motosan-ai

Installation

pip install motosan-chat

Optional extras:

pip install "motosan-chat[web]"
pip install "motosan-chat[telegram]"
pip install "motosan-chat[line]"
pip install "motosan-chat[discord]"
pip install "motosan-chat[ai]"
pip install "motosan-chat[full]"

Quick Start

from motosan_chat import Bot
from motosan_chat.channels import WebChannel


async def handler(thread):
    await thread.send(f"echo: {thread.event.content}")


channel = WebChannel()
bot = Bot.builder().channel(channel).handler(handler).build()
await bot.run()

Agent + Tools

from motosan_chat import AgentLoop, Message, ToolContext, ToolResult, tool


@tool(
    name="get_weather",
    description="Get weather by city",
    schema={"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]},
)
async def get_weather(args: dict, ctx: ToolContext) -> ToolResult:
    return ToolResult.text(f"Sunny in {args['city']}")


loop_ = AgentLoop(tools=[get_weather])
# result = await loop_.run(llm_client, thread, [Message.user("weather in Tokyo?")])

Development

uv sync --extra full --extra dev
uv run ruff check motosan_chat/ tests/
uv run pytest tests/ -v

Publishing

Build and verify package locally:

uv build
uv publish --dry-run

GitHub Actions publish workflow is triggered by tags that match python-v*.

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

motosan_chat-0.2.0.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

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

motosan_chat-0.2.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file motosan_chat-0.2.0.tar.gz.

File metadata

  • Download URL: motosan_chat-0.2.0.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","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 motosan_chat-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b3e0139fee30778f013b310f836ea701f6f29b18a90c32782db798cb723ffb43
MD5 9eeddc17fa75d40d09f65a1be8f49c64
BLAKE2b-256 f380a2856184d205fbc7a311a058ec0128cc7f59df423d9f8feab5efee16c451

See more details on using hashes here.

File details

Details for the file motosan_chat-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: motosan_chat-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","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 motosan_chat-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0e1c6ffbc759f15f9c902aa1ab00231eb020b7cbd59cab6d8c79a4af86467f45
MD5 c1b5971a1d2dd3b0c22d22e3306e30e0
BLAKE2b-256 0c540be95ea8fc97b6e31d09dbf8e9f6eaf80748e388ff6f78dd8365a4ade4af

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