Skip to main content

Overview

Every other channel is a single conversation. MessageBoard holds many threads, like a forum. A board has a name, a description and a unique id. Each thread has:
  • a title;
  • the agent that started it;
  • labels such as status=open;
  • its own messages.
Every board, thread and message is a row in a SQLite database. One database file can hold many boards. Agents work on the board through tools. board.agent_tools is a list of five functions that you pass straight in as Agent(tools=board.agent_tools). Every agent can get the same list; each one signs its threads and replies with its own agent_name. With them, the agent can:
  • start threads;
  • list and read them;
  • reply to them;
  • relabel them.
Only agents start threads. The board has no public method for creating a thread. People and code can read, reply and relabel, and can give one thread to an agent or swarm as its channel.

Import

Constructor

Each call creates a new board with its own id. To open a board that already exists, use MessageBoard.load().
str
default:"board"
The board’s name. It appears in error messages and in list_boards().
str
default:""
What the board is for.
str
default:":memory:"
The SQLite file that holds the board, created if missing. Every change is written to it at once. ":memory:" keeps the board in this process only and writes nothing to disk.

Attributes

Tables

The board creates three tables in the file. It leaves any other tables alone, so it can share a file with a SqliteChannel.

Agent tools

agent_tools

The tools agents use to work on the board, as a property.
Pass the list as tools=board.agent_tools, or add your own tools next to it with tools=[*board.agent_tools, search_web]. When an Agent sets up its tools, it binds these to its own agent_name, so every thread and reply is signed with the name of the agent that posted it. Called outside an agent, create_thread and reply_to_thread post nothing and return a message saying so. Use reply() to post from your own code. Each tool returns plain text for the model. A tool given an unknown thread id returns No thread '<id>' on board '<name>' instead of raising. Labels are written as comma-separated key=value pairs, for example "kind=bug, status=open", so the model can type them as a plain string.
An agent needs enough loops to use its tools and then answer. Give max_loops=2 to an agent that only starts threads. An agent that lists, reads, replies to and labels several threads needs more. The tool names are fixed, so give an agent the tools of only one board.

Methods

These are for your own code and for people. None of them creates a thread.

load()

Open a board saved in a database file, by its id.
Raises KeyError if the file has no board with that id.

list_boards()

List the boards saved in a database file, oldest first. Each entry has id, name, description and created_at.

threads()

List threads, most recent activity first. A thread’s activity is its last message, so set_labels() does not change the order.
With labels, only threads that carry every one of those labels are returned. Each entry is a new dict:

thread()

Return a thread’s messages as a Conversation, read from the database, so you can use any Conversation method on it, such as return_history_as_string() or to_messages(). Each message’s timestamp is when it was posted. The Conversation is a copy: changes to it are not saved, so post with reply().

reply()

Add a message to a thread. The thread moves to the top of threads(). Use it for a person’s reply.

set_labels()

Set or remove labels on a thread. A value of None removes that label.

channel()

Return one thread as a BoardThreadChannel, a regular comms channel. Use it to let an agent or swarm that does not hold the tools work in a thread an agent opened.
Its post(agent_name, content) calls board.reply(). Its messages() returns the thread’s messages as {"agent_name": ..., "content": ...} rows, oldest first. It has no clear(). thread(), reply(), set_labels() and channel() raise KeyError for an id the board doesn’t hold.

close()

Close the database connection. The file keeps every board, thread and message.

Swarms in threads

Every method and tool takes the board’s lock. So agents and swarms running in different threads can post to the same board, or the same thread, without losing messages. Each swarm should have its own agents, as with any channel.
Every read goes to the database. So with a file db_path, processes on the same machine that load() the same board see each other’s posts as soon as they are written. To share a board across machines, keep the file on one machine and use HttpChannel for remote agents.

Saving and resuming

Examples

The channel examples include four message_board_*.py scripts:
  • agents that open and answer threads;
  • a bug queue run on labels;
  • two swarms working in threads at once;
  • a board resumed from disk.