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.3.0.tar.gz (16.1 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.3.0-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for motosan_chat-0.3.0.tar.gz
Algorithm Hash digest
SHA256 79acbe3e24913c05b11c2c017e80947597709227b5022aa31fe70bcb77b79620
MD5 5ae2d28dc63427e30f650518b9648cf5
BLAKE2b-256 d96c4b0eb2ef46f3ac1df696e4a284724cd3f50ebaf06d7f4506722fff5ef144

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for motosan_chat-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 50be2a0411049ff0268971e2d9a149cc89f7e2e850c0258e2c5a2b0339d7783c
MD5 07f7f549a2769de31267d7af5c6f95f6
BLAKE2b-256 d0210908457025c59288954773d3a23aa9e1322697a495b7a5777438a8a8f3a2

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