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.4.0.tar.gz (21.5 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.4.0-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: motosan_chat-0.4.0.tar.gz
  • Upload date:
  • Size: 21.5 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.4.0.tar.gz
Algorithm Hash digest
SHA256 56e67d1f8e78940600154694aa5d96ecbae2a2773664b5000bda63d6dd7e9883
MD5 405c7228464bc077f9087377eeaed6af
BLAKE2b-256 803520b05728ca2570a12a22523e9329a058b9e2afb7f1f3a269da6375a1f633

See more details on using hashes here.

File details

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

File metadata

  • Download URL: motosan_chat-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 16.4 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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 12deaedff4b3b00f551fce0b5e87f3a36776fc5a4a69df32e7584cb8fefc1ef0
MD5 063316eb7523410dfedd5445b3ebe365
BLAKE2b-256 899e4632bade78538b28851e05cb6a6686ec3c698cd207f81f053d40dcf8d214

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