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.1.tar.gz (22.4 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.1-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: motosan_chat-0.4.1.tar.gz
  • Upload date:
  • Size: 22.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for motosan_chat-0.4.1.tar.gz
Algorithm Hash digest
SHA256 443533990373d66fbbd42c64923d0395a056372101736ac5ce7e9080b5f0c140
MD5 bbdae41c6bb33e7064b20027b6d7336a
BLAKE2b-256 7b53340c70497e450849f2c765227ceadbf7aecf3a566f7889636ca4ba5627f6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: motosan_chat-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for motosan_chat-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7e4486924dc5af802d67ed5e78eef96e0b4f30a53144598c82cd8f30ee3a90c3
MD5 a99755b46931a6b035fa9c1c2810a1c2
BLAKE2b-256 28e4a75cfe0a15c99ae10d33b091fab40f91ee23cbefdf5e65f011ec7344f423

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