Skip to content

Bot File Structure

Every Flexus bot follows a consistent file structure. This guide explains each file and when changes require reinstallation.

Directory Layout

mybot/
__init__.py # Makes it a Python package
mybot_bot.py # Runtime: main loop, tool handlers
mybot_prompts.py # System prompts for each expert
mybot_install.py # Marketplace registration script
mybot-1024x1536.webp # Marketplace card image (required)
mybot-256x256.webp # Avatar/icon (required)
forms/ # Optional: custom HTML forms
report.html
settings.html

File Descriptions

mybot_bot.py — Runtime Code

This is the main file that runs your bot. It contains:

  • Tool definitions — CloudTool objects defining your tools
  • Tool handlers@rcx.on_tool_call decorated functions
  • Event handlers — Message, thread, task, ERP update handlers
  • Main loop — The bot’s event processing loop
  • Startup logic — Connections to MongoDB, integrations setup
mybot_bot.py
import asyncio
from flexus_client_kit import ckit_client, ckit_bot_exec, ckit_cloudtool, ckit_shutdown
from mybot import mybot_install
BOT_NAME = "mybot"
BOT_VERSION = "1.0.0"
# Define tools
MY_TOOL = ckit_cloudtool.CloudTool(
strict=True,
name="my_tool",
description="Does something useful",
parameters={
"type": "object",
"properties": {
"input": {"type": "string", "description": "The input to process"},
},
"required": ["input"],
"additionalProperties": False,
},
)
TOOLS = [MY_TOOL]
async def mybot_main_loop(fclient, rcx):
# Get merged setup (defaults + user overrides)
setup = ckit_bot_exec.official_setup_mixing_procedure(
mybot_install.mybot_setup_schema,
rcx.persona.persona_setup
)
# Tool handler
@rcx.on_tool_call(MY_TOOL.name)
async def handle_my_tool(toolcall, args):
result = process_input(args["input"])
return f"Processed: {result}"
# Event handlers (optional)
@rcx.on_updated_message
async def on_message(msg):
pass # React to new messages
@rcx.on_updated_task
async def on_task(task):
pass # React to kanban task changes
# Main loop
try:
while not ckit_shutdown.shutdown_event.is_set():
await rcx.unpark_collected_events(sleep_if_no_work=10.0)
finally:
# Cleanup
pass
def main():
scenario_fn = ckit_bot_exec.parse_bot_args()
fclient = ckit_client.FlexusClient(
ckit_client.bot_service_name(BOT_NAME, BOT_VERSION),
endpoint="/v1/jailed-bot"
)
asyncio.run(ckit_bot_exec.run_bots_in_this_group(
fclient,
marketable_name=BOT_NAME,
marketable_version_str=BOT_VERSION,
bot_main_loop=mybot_main_loop,
inprocess_tools=TOOLS,
scenario_fn=scenario_fn,
install_func=mybot_install.install,
))
if __name__ == "__main__":
main()

Changes require: Bot restart (automatic in dev mode)

mybot_prompts.py — System Prompts

Contains system prompts for each expert. Keeping prompts separate makes them easier to maintain and version.

mybot_prompts.py
from flexus_simple_bots import prompts_common
SYSTEM_PROMPT_DEFAULT = """You are MyBot, a helpful assistant that...
## Your Capabilities
- You can process user input using the `my_tool` tool
- You can read and write policy documents
## How to Work
1. When the user asks for help, use your tools
2. Always explain what you're doing
3. If unsure, ask for clarification
""" + prompts_common.PROMPT_POLICY_DOCUMENTS + prompts_common.PROMPT_KANBAN
# Additional expert prompts (if needed)
SYSTEM_PROMPT_ANALYST = """You are an analytical expert that..."""

Changes require: Reinstallation (python mybot_install.py --ws=xxx)

mybot_install.py — Marketplace Registration

Defines everything needed to register the bot in the marketplace:

mybot_install.py
import json
from flexus_client_kit import ckit_bot_install
from flexus_client_kit.ckit_bot_install import FMarketplaceExpertInput
from flexus_simple_bots import prompts_common
from mybot import mybot_bot, mybot_prompts
# Setup schema — defines configurable options
mybot_setup_schema = {
"API_KEY": {
"bs_type": "string_long",
"bs_default": "",
"bs_group": "api",
"bs_description": "Your API key for the external service",
},
"auto_process": {
"bs_type": "bool",
"bs_default": True,
"bs_group": "behavior",
"bs_description": "Automatically process incoming tasks",
},
}
# Tools as JSON for experts
tools_json = json.dumps([t.openai_style_tool() for t in mybot_bot.TOOLS])
def install(ws_id: str):
return ckit_bot_install.marketplace_upsert_dev_bot(
ws_id=ws_id,
marketable_name="mybot",
marketable_version="1.0.0",
marketable_title1="My Bot",
marketable_title2="A helpful bot that does useful things",
marketable_occupation="Assistant",
marketable_author="Your Name",
marketable_description="""
My Bot is designed to help you with...
## Features
- Feature 1
- Feature 2
## Requirements
- API key from service X
""",
marketable_typical_group="Assistants / General",
marketable_tags=["helper", "automation"],
marketable_setup_schema=json.dumps(mybot_setup_schema),
marketable_picture_big_b64=ckit_bot_install.load_image_b64(__file__, "mybot-1024x1536.webp"),
marketable_picture_small_b64=ckit_bot_install.load_image_b64(__file__, "mybot-256x256.webp"),
marketable_experts=[
("default", FMarketplaceExpertInput(
fexp_system_prompt=mybot_prompts.SYSTEM_PROMPT_DEFAULT,
fexp_app_capture_tools=tools_json,
)),
],
marketable_schedule=[
prompts_common.SCHED_TASK_SORT_10M,
prompts_common.SCHED_TODO_5M,
],
marketable_forms=ckit_bot_install.load_form_bundles(__file__), # Load forms/ directory
)
if __name__ == "__main__":
ckit_bot_install.main_install_dev_bot(install)

Changes require: Reinstallation

Image Files

Two images are required:

FileSizePurpose
mybot-1024x1536.webp1024x1536 pxMarketplace detail card
mybot-256x256.webp256x256 pxAvatar in sidebar, chat
Image Requirements
  • Format must be WEBP
  • Sizes must be exact (1024x1536 and 256x256)
  • Big image should be under 300KB
  • Avatar should have transparent or white background

forms/ Directory (Optional)

Custom HTML forms for editing policy documents:

forms/
report.html # Form for {"report": {"meta": {...}, ...}} documents
settings.html # Form for {"settings": {"meta": {...}, ...}} documents

Form filename must match the document’s top-level key.

See Custom Forms for details.

Change Summary

FileWhen ChangedAction Required
_bot.pyTool handlers, main loopRestart bot
_prompts.pySystem promptsReinstall
_install.pySetup schema, experts, schedulesReinstall
ImagesAny changeReinstall
forms/*.htmlForm templatesReinstall

Development Workflow

  1. Start developing:

    Terminal window
    # Install to marketplace first
    python mybot_install.py --ws=your_workspace_id
    # Then run the bot
    python mybot_bot.py
  2. Make runtime changes (_bot.py):

    • Bot auto-restarts in dev mode
    • Or manually restart: Ctrl+C and run again
  3. Make prompt/config changes (_prompts.py, _install.py):

    Terminal window
    # Reinstall to update marketplace/experts
    python mybot_install.py --ws=your_workspace_id
  4. Test with scenarios:

    Terminal window
    python mybot_bot.py --scenario mybot/mybot__s1.yaml

Next Steps