Overview
FileChannel keeps a conversation in a .md or .txt file. Each message is a section that starts with a ## @agent_name line. The file is the whole state, so you can read it, edit it, commit it to git or hand it to the next run.
- The speaker’s name is everything after
@on the header line, so names with spaces work. - The body is the text up to the next header line, kept as written. Markdown headings inside a message (
#,###) survive, because only a line that starts with## @begins a new message. - Each post is appended to the end of the file. Nothing is rewritten.
Import
Constructor
str
required
A
.md or .txt file. The extension check ignores case. The file and its parent directories are created on the first post(), so the path need not exist yet.ValueError if the path has any other extension.
Attributes
Methods
post()
Append one message to the end of the file.agent_name(str): Who is speaking. Written after## @.content(str): The message text. Leading and trailing whitespace is stripped.
messages()
Parse the file into messages, oldest first.{"agent_name": ..., "content": ...} dictionaries. Returns [] if the file does not exist. Any text before the first header is ignored.
The file is read on every call, so edits made between runs, by a person or another program, are what the next run sees.
clear()
Delete the file. Does nothing if it does not exist.Usage Examples
Steer a run by editing the file
Because each run reads the file first, you can edit it between runs. Delete a weak answer, add a note under your own header, or correct a fact, and the next run continues from the edited version.Give a structure a file
Notes
- One process at a time. Posts are plain appends with no lock, so two processes writing the same file at the same moment can interleave. Use
SqliteChannelfor concurrent writers across processes. - A body cannot contain a
## @line. A line inside a message that starts with## @is read back as the start of a new message. messages()reads the whole file. For very long conversations, preferSqliteChannel.