Threads and conversations¶
octomate.managers.thread ¶
The thread chat ledger: threads, their messages, bindings to model messages, handoffs, and history search.
BindRefusal ¶
Bases: ValueError
A bind refused by policy — a thread that is not work, or one already bound —
carrying the sentence a model may be told and correct from. A ValueError
still, so nothing that never told the two apart changes.
Source code in octomate/managers/thread.py
ThreadManager ¶
Bases: Manager, Locks[ThreadKey]
Owns durable thread chat ledger persistence.
Source code in octomate/managers/thread.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 | |
ensure
async
¶
ensure(
address_or_key: ChannelAddress | ThreadKey,
*,
project: Project | None = None,
title: str | None = None,
) -> Thread
The thread this key names, created if it is new.
A key names a surface, so it resolves the thread nobody opened. A chat room's sub-threads share its address and are reached by id, through it.
A channel-supplied title refreshes the surface's stored name, including
existing groups and DMs previously named from an opening line.
project attributes a thread being created and is ignored for one that
already exists: a thread's project is frozen once the row is written, so
declaring a project later attributes new threads rather than rewriting old
ones. It is not part of the key either — the key is what the thread's history
is filed under, and attribution must never move it.
Only a thread and a native thread can take one; naming a project for a DM or a group chat raises rather than dropping it silently.
Source code in octomate/managers/thread.py
open_sub_thread
async
¶
The thread one kick in parent does its work in.
A dm and a group chat have no end, so a conversation held against one would
accumulate for as long as the chat room does. Answering happens in a thread
of its own instead, and everything a thread already governs governs it — one
conversation per agent, runs continuing one by one. Only the chat everyone
sees stays on the chat room, which is what surface resolves back to.
Opened, never looked up: a sub-thread has no address of its own to be found by, and each kick wants its own. A redelivered event therefore opens a second — that is a duplicate to stop where it is made, in the ledger, not here.
Source code in octomate/managers/thread.py
enter
async
¶
The thread a turn arriving at this surface does its work in.
A thread and a native thread are a piece of work already, so the turn runs in the one the key names. A dm and a group chat are not — they have no end, and a conversation held against one would accumulate for as long as the chat room does — so the turn runs in a sub-thread opened inside the chat room instead.
current is the thread the turn is already in, and it is kept when this
surface is the chat room that thread was opened in: an agent taking the
conversation over in place is still answering the same kick, and a second
sub-thread would split one answer across two model contexts.
Source code in octomate/managers/thread.py
surface
async
¶
The surface this thread is on: itself, or the chat room it was opened in.
A sub-thread has none of its own — no address, no chat ledger, no prompt cursor — so this is the one place the split between where a run happens and where it is seen gets made. Nesting is one level, so it never walks.
Source code in octomate/managers/thread.py
fork_title
staticmethod
¶
What a fork of source, from thread, is first called: what the source
goes by, the name its runtime gave the session or else the thread's title.
None when it goes by nothing, and the fork takes a name the way a new thread
does.
Source code in octomate/managers/thread.py
rename
async
¶
Give the thread the name the runtime running it grabbed for itself.
Unlike the opening line store_message falls back to, this is a name for
the work rather than for how it was asked for, so it overwrites — and goes
on overwriting, because the runtime revises it as the session goes on. A
name with nothing in it is not one, and leaves the thread as it was.
A group's main chat keeps its platform name, and a DM keeps the bot's
name; only their work sub-threads take generated titles.
Source code in octomate/managers/thread.py
bind
async
¶
Attribute a thread that is in no project to project, once.
The one exception to a project being written when the row is created: a chat thread exists before anyone has said what it is about, so the attribution has to be able to arrive later. It arrives once. A second bind is refused rather than switching — the first project's workspace holds work nobody has reviewed yet, and a thread whose project moved is a record of what it did somewhere it no longer says it was. A different project is a different thread.
A DM and a group chat are refused for the reason ATTRIBUTABLE_KINDS
gives: they outlive every project in them. Both refusals are BindRefusal;
a thread that does not exist is a plain ValueError, a wiring bug.
No workspace is made here. A run's working directory is fixed when its process spawns, so this takes effect on the thread's next turn and the caller has to say so.
Source code in octomate/managers/thread.py
get
async
¶
get(
thread_id: UUID7 | ThreadKey,
*,
with_messages: bool = True,
user_id: UUID7 | None = None,
) -> Thread | None
The thread by primary key, or by the key it is filed under, or None —
its handoffs with the row, its ledger only when asked for. A key never
creates one, unlike ensure.
with_messages=True is the whole ledger, deliberately: it is what a reader
rebuilding a thread wants, and it is unbounded in a room, so a caller after
one row wants find_message and a caller after the recent ones wants
chat_messages_before.
Either way the model ledger stays behind: it hangs off a message, and
related_model_messages is how a caller asks for it — dragging it here
would put a query per message behind every thread read.
user_id restricts access to participation in the thread's own ledger;
messages inherited from another thread grant no access.
Source code in octomate/managers/thread.py
list_threads
async
¶
list_threads(
channel_tentacle_id: str | None = None,
*,
limit: int = 100,
user_id: UUID7 | None = None,
) -> list[Thread]
Threads most recently touched first — one channel's, or every
channel's when channel_tentacle_id is None. Sub-threads are not listed;
the threads a chat room's kicks work in are reached through the chat room.
Handoffs come with the rows (lazy="selectin", one batched pass); the ledgers do not. A listing that loaded them would read every message of every thread it names, and no caller has ever wanted that — the one reader of a thread's messages asks for that thread.
Source code in octomate/managers/thread.py
publish
async
¶
Publish committed thread events to each eligible user's topic.
Resolve registered participants once for the supplied events, without a cache, matching listing and access checks. Inherited history grants no access. Sub-threads are not listed. Token events never call this method.
Source code in octomate/managers/thread.py
store_message
async
¶
Persist a ledger row.
The row is touched, not only appended to. updated_at fires on an update
of the thread and writing to its ledger is not one, so a session being
tailed right now would keep the timestamp it was created with and sink, in
a listing ordered by it, under threads nothing has ever said a word in.
A thread nobody has named takes its name from this row when a person wrote
it. The listing carries no messages, so the first thing said is the only
name a row has until a runtime grabs one of its own (rename).
Source code in octomate/managers/thread.py
record_artifact
async
¶
record_artifact(
thread_id: UUID7,
artifact: Artifact,
*,
sender: UserProfile,
agent_tentacle_id: str,
) -> ThreadArtifact
Commit an artifact and its ledger reference together before publication.
Source code in octomate/managers/thread.py
record_command_outcome
async
¶
Persist an outcome without mutating a caller's receipt snapshot. Under the
thread's lock, only the outcome and the thread's updated_at are written.
Source code in octomate/managers/thread.py
record_inbound
async
¶
record_inbound(
event: MessageEvent,
*,
actor_kind: ChannelActorKind = "human",
agent_tentacle_id: str | None = None,
happened_at: datetime | None = None,
) -> ThreadMessage
Write the event to the thread's ledger, or hand back the row it is already on.
A platform re-sends a message when it misses an ack — Slack does — and the second send is the same message, not a second one. Writing it twice would put a duplicate in everyone's scroll-back, so one delivery is one row and asking again is answered with the row that exists.
Only a message the platform named can be recognised — an event with no
message_id is always recorded, because there is nothing to match it on.
Two deliveries racing this read both reach the insert, and the ledger's
unique key refuses the loser loudly rather than letting it through.
Recording is idempotent; answering is not. A caller that wakes a turn on
what it records asks find_message first, because a row that already exists
is a message somebody is already answering.
Swaps event.sender for its registry row as a side effect, so the
event's sender line resolves the owning identity via event.sender.user.
Pass happened_at only to overrule the event's own clock: a transcript replay
knows when the turn really happened, which a hook-built event cannot carry.
Left out, the event's clock is used, and failing that the moment it arrived —
the row is never undated, because an undated row has no place in the order.
Source code in octomate/managers/thread.py
record_outbound
async
¶
record_outbound(
thread_or_address: Thread | ChannelAddress | ThreadKey,
*,
agent_tentacle_id: str,
segments: list[MessageSegment],
platform_message_id: str | None = None,
reply_id: str = "",
happened_at: datetime | None = None,
sender: UserProfile,
actor_kind: ChannelActorKind = "agent",
message_text: str | None = None,
raw: str = "",
) -> ThreadMessage
Write the agent's reply to the thread's ledger.
Pass happened_at only when something knows better than this moment — a
transcript replay does; an agent answering now does not.
Source code in octomate/managers/thread.py
mark_presented
async
¶
Name the platform message a ledger row was rendered as, once the channel that rendered it knows; a rendering with no id leaves it be.
Source code in octomate/managers/thread.py
redate_message
async
¶
Overrule a ledger row's clock after the fact: a transcript replay knows
when a message really happened, while a row the live hooks wrote was stamped
at receipt — a beat later than the transcript line, which is enough to sort a
run's work above the prompt that caused it. Under the thread's lock, only the
row's happened_at is written.
Source code in octomate/managers/thread.py
pending_prompt_messages
async
¶
pending_prompt_messages(
thread: Thread,
trigger_message_id: UUID7,
active_agent_id: str,
) -> list[ThreadMessage]
Source code in octomate/managers/thread.py
advance_prompt_cursor
async
¶
Source code in octomate/managers/thread.py
record_fork
async
¶
record_fork(
source: Conversation,
target: Thread,
*,
sender: UserProfile,
title: str | None,
) -> Thread
Publish a user-attributed system notice after a successful fork. It names
the source by title, the source's own name that the fork starts with, or by
the source's id when it goes by nothing.
Source code in octomate/managers/thread.py
record_handoff
async
¶
record_handoff(
thread_or_address: Thread | ChannelAddress | ThreadKey,
*,
to_agent_tentacle_id: str,
source_agent_tentacle_id: str | None = None,
to_model: AgentRouteModelName | None = None,
reason: str = "",
hint: str = "",
brief: str = "",
source_conversation_id: UUID7 | None = None,
target_conversation_id: UUID7 | None = None,
source_run_id: str | None = None,
source_model_message_id: UUID7 | None = None,
) -> Handoff
Source code in octomate/managers/thread.py
chat_message
async
¶
The chat message handle names within this person's history — the threads
they have spoken in, on this account or any the registry links to it. A row
id, or the #msg:<id> handle shown beside it: the platform's own id, which
is what a brief written from the other side of a handoff has to cite.
Source code in octomate/managers/thread.py
find_message
async
¶
find_message(
thread_id: UUID7,
platform_message_id: str,
direction: ThreadMessageDirection,
) -> ThreadMessage | None
The row delivered to the thread for one platform message — a turn's prompt, or the reply that answered it. Oldest wins, as scanning the ordered ledger did. A row the thread shows from a ledger a fork froze into it was delivered elsewhere, so it is never this one.
Both halves of the key are indexed. The hooks and tailers ask this per turn, on a ledger with no ceiling, so the row has to be found by the index rather than by reading the room's whole tenure to match one id in Python.
Source code in octomate/managers/thread.py
record_native_prompt
async
¶
record_native_prompt(
address: ChannelAddress,
*,
message_id: str,
text: str,
sender: UserProfile,
timestamp: datetime,
) -> ThreadMessage
Record a transcript input once, before the run commits.
The native message identity survives reconnects. The caller holds its session lock across this lookup and write; the row grants the stream's owner access to a new thread while its model history is still folding.
Source code in octomate/managers/thread.py
bind_native_run
async
¶
bind_native_run(
address: ChannelAddress,
run: ExternalAgentRun,
*,
prompts: dict[UUID7, UUID7],
answer: str,
sender: UserProfile,
) -> UUID7 | None
Bind transcript prompts and the final reply after the run commits.
Each prompt maps its ledger id to its committed model message id. The caller holds the session lock and publishes run_ended
only after this returns, so a reader can immediately reload the ledger.
Source code in octomate/managers/thread.py
bind_messages
async
¶
bind_messages(
thread_message_ids: list[UUID7],
model_message_id: UUID7,
*,
kind: MessageBindingKind,
run_id: str,
tool_call_id: str | None = None,
) -> list[MessageBinding]
Source code in octomate/managers/thread.py
bind_assistant_replies
async
¶
Source code in octomate/managers/thread.py
search_chat_messages
async
¶
search_chat_messages(
profile: UserProfile,
query: str,
*,
actor_kind: ChannelActorKind | None = None,
limit: int = 10,
) -> list[ThreadMessage]
The messages matching every English term in query across this person's
history — the threads they have spoken in, on this account or any the registry
links to it. Best lexical match first, newest first when scores tie. A
visitor's history is one account's.
Source code in octomate/managers/thread.py
chat_messages_before
async
¶
chat_messages_before(
thread_id: UUID7, anchor_id: UUID7, *, limit: int = 5
) -> list[ThreadMessage]
The rows standing before anchor_id in the thread, oldest last of them
first. Neighbours in the conversation, which is what the ledger's order means —
so the anchor is compared on the same key the rows are sorted by.
Source code in octomate/managers/thread.py
chat_messages_after
async
¶
The rows standing after anchor_id in the thread, oldest first — the mirror
of chat_messages_before, and anchored on the same key.
Source code in octomate/managers/thread.py
messages_page
async
¶
messages_page(
thread_id: UUID7,
cursor: str | None = None,
*,
unbound: bool = False,
limit: int,
) -> Page[ThreadMessage]
The rows the thread shows — its own ledger's, and a forked parent's up to
the cut — a page at a time, newest first, continued from an Arcanus
cursor. Ids are uuid7 and a ledger is appended to, so id order is the
order rows were written in.
unbound keeps to the rows no model message of the thread's own
conversations was built from or answered with: a fork or teleport notice,
or a chat room's talk, whose work runs in sub-threads. Everything else is
read through those model messages, which carry the rows bound to them.
Source code in octomate/managers/thread.py
related_model_messages
async
¶
Source code in octomate/managers/thread.py
history_match_query ¶
An English plain-text query expressed safely in FTS5's query language.
Each whitespace-delimited term is its own quoted phrase, so every term must match while operators and punctuation supplied by a caller stay literal.
Source code in octomate/managers/thread.py
message_text_from_segments ¶
Source code in octomate/managers/thread.py
keyed ¶
The row a key names. A sub-thread shares its chat room's address, so a key names the thread nobody opened — the line the unique index draws.
Source code in octomate/managers/thread.py
shown_by ¶
The messages shown by the threads threads picks out of thread_ledgers:
those delivered to one of their ledgers, up to that ledger's cut.
Source code in octomate/managers/thread.py
in_ledger ¶
in_history_of ¶
The messages shown by threads that received a message from senders.
Inherited messages are readable history, not participation in the destination.
Source code in octomate/managers/thread.py
thread_title ¶
A name for a thread, out of one line of what was said in it.
Whitespace is folded because a directive arrives with its own newlines and a listing has one line to give it. A message with nothing in it names nothing, and the row goes on falling back to its surface.
Source code in octomate/managers/thread.py
octomate.managers.conversation ¶
Agent conversations and their model message history.
request_usage_adapter
module-attribute
¶
ConversationManager ¶
Bases: Manager, Locks[tuple[UUID7, str, str]]
Resolves and persists agent Conversation entities, and owns their model
message history.
A Conversation is one agent's model context within a Thread — not a human
chat log; the user-facing chat ledger is ThreadManager's ThreadMessage
rows. A thread owns one conversation per agent, so the identity is
(thread_id, agent_tentacle_id, subagent_id): every sender in a group thread
keys to the same owning agent's conversation, regardless of who woke it.
Source code in octomate/managers/conversation.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 | |
latest_model
async
¶
Read the last reported model without loading the conversation's history.
Source code in octomate/managers/conversation.py
ensure
async
¶
ensure(
thread_id: UUID7,
*,
agent_tentacle_id: str,
subagent_id: str = "",
parent_conversation_id: UUID7 | None = None,
with_history: bool = True,
) -> Conversation
Resolve the conversation owned by agent_tentacle_id in thread_id,
creating it if it does not yet exist. Its conversation.messages is the
live model history. The owning agent is part of the identity — two agents
in the same thread keep separate conversations — so callers must always
supply it. subagent_id narrows to one subagent's own context; empty is
the agent's long-lived conversation in the thread. A subagent context
names the conversation that spawned it, and only a subagent context may.
with_history=False leaves runs and messages unloaded for callers that
only need identity, permissions, or the native session's resume id.
Source code in octomate/managers/conversation.py
get
async
¶
Resolve a conversation by id — one fresh read; raises on an unknown
id. This is the by-id path for a run addressed at a pre-ensured
conversation (a commissioned accomplice's child context): the caller
ensured it and owns any thread/agent validation. with_history=False
leaves runs and messages unloaded, as on ensure.
Source code in octomate/managers/conversation.py
link_parent_run
async
¶
Stamp a recorded run's place in the run tree, after the fact. The runner stays ignorant of why it ran; the caller that spawned it links the turn to its own run and tool call once the child returns. A run that recorded nothing has no row to link — not an error.
Source code in octomate/managers/conversation.py
subagents
async
¶
The subagent conversations spawned from parent_conversation_id — the
live accomplices a whisper can reach. Rows only; callers resolve a
chosen one through ensure.
Source code in octomate/managers/conversation.py
for_thread
async
¶
The thread's agent conversations, subagents included, each with its runs.
Both message relations here are lazy="selectin", so the plain query would read
every model message the thread ever produced twice over — once under the
conversation and once under the run that owns it. Both are dropped: a reader
after the messages pages through them with messages_page.
Source code in octomate/managers/conversation.py
messages_page
async
¶
messages_page(
thread_id: UUID7,
cursor: str | None = None,
*,
limit: int,
) -> Page[ModelRequest | ModelResponse]
The model messages of the thread's own conversations, newest first, a
page at a time and continued from an Arcanus cursor. Ids are uuid7 and a
run's messages are appended in processing order, so id order preserves
each transcript's sequence across committed turns.
Each carries the chat rows bound to it — the ones a request was built from, the ones a response was delivered as — so a reader has who said what without the prompt's dressing. A subagent's messages stay out: they are its own conversation's, and the spawn call in its parent's run stands for them.
Source code in octomate/managers/conversation.py
usage
async
¶
The tokens the thread's own conversations spent, every response's usage summed. A subagent's are left to its own conversation, as its messages are. Only the usage column is read: summing a thread must not load its parts.
Source code in octomate/managers/conversation.py
thread_id
async
¶
Source code in octomate/managers/conversation.py
record_agent_run
async
¶
record_agent_run(
conversation: Conversation,
run_id: str,
messages: Sequence[ModelMessage],
*,
name: str | None = None,
model_name: str | None = None,
permission_mode: AgentPermissionMode | None = None,
cwd: Path | None = None,
external_id: str | None = None,
native_id: str | None = None,
native_turn_id: str | None = None,
parent_run_id: str | None = None,
parent_tool_call_id: str | None = None,
) -> AgentRun | None
Persist a fresh agent run.
cwd is the directory the run happened in, None when its caller has none.
external_id, when given, updates the conversation's resumable agent
session handle in the same commit (external-runtime agents own their own
session). The parent pair marks a subagent's turn: the run whose tool
call spawned it, and which call it answers.
Source code in octomate/managers/conversation.py
driven_run
async
¶
Find the driven owner of a native turn without loading its messages.
Source code in octomate/managers/conversation.py
record_external_run
async
¶
record_external_run(
conversation: Conversation,
run_id: str,
messages: Sequence[ModelMessage] = (),
*,
name: str | None = None,
model_name: str | None = None,
permission_mode: AgentPermissionMode | None = None,
cwd: Path | None = None,
native_session_id: str,
source: str | None = None,
start_offset: int | None = None,
end_offset: int | None = None,
last_line_uuid: str | None = None,
parent_run_id: str | None = None,
parent_tool_call_id: str | None = None,
) -> ExternalAgentRun | None
Persist a turn of a native runtime's session as the
external variant. cwd is the directory the turn ran in, as the hook or
the transcript reported it. native_session_id doubles as the
conversation's resumable handle (external_id).
A turn already recorded by the driven runtime keeps its original run and messages. Its runtime identity lets native ingest skip the replay without copying it into the native ledger or saving transcript coordinates on it.
The byte range is what marks a turn finished. A run carrying end_offset was
assembled from the transcript and is final, so recording it again — a recovery
overlapping a live tail, or a resume re-covering committed bytes — is a no-op
returning None rather than a primary-key collision. That guard belongs here,
at the durable sink: a caller's in-memory guard only knows the runs it wrote,
never one another tailer already committed.
Omitting messages reserves a run identity without changing an existing run. Native hooks use this so the transcript remains the only message writer.
Completing a reserved run fills its messages in transcript order while preserving its identity. Older incomplete imports may contain provisional messages; the completed transcript replaces those in the same commit.
Source code in octomate/managers/conversation.py
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 | |
persist_run
async
¶
Persist a freshly built run, in the history of the conversation it ran
in. external_id, when given, updates the resumable agent-session handle in
the same commit.
Only the new run and its messages are added, never the caller's whole
conversation graph: re-merging it (prior runs and their message
collections) can make SQLAlchemy believe a message was dropped from a
stale run collection and null its NOT NULL run_id, raising an
IntegrityError.
Source code in octomate/managers/conversation.py
fork
async
¶
fork(
source: Conversation,
target: Conversation,
*,
carry_external_id: bool = False,
external_id: str | None = None,
transcript: Jsonl | None = None,
end_offset: int | None = None,
permission_mode: AgentPermissionMode | None = None,
) -> str | None
Continue source's history in an empty target, in one transaction.
Nothing is copied. The target's history points at the source's runs through
conversation_runs, and its thread shows the source thread's ledgers through
thread_ledgers, each frozen where it stands now: whatever either side says
afterwards is its own. Only the selected conversation receives the
independently forked runtime handle.
A native import passes end_offset, where the transcript's last completed
turn ends (an uploaded snapshot's size by default), to leave out the turns
that end past it and cut the source's ledger before their chat.
carry_external_id moves the existing handle instead, for runtimes whose
continuation requires it. Return the id of the last run the target's history
includes, if any.
Source code in octomate/managers/conversation.py
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 | |
store_transcript
async
¶
store_transcript(
uploaded: UploadFile,
start: int,
*,
conversation: Conversation,
files: FileManager,
owner_id: UUID7,
) -> FileVariant
Persist new bytes of a native conversation's owner-scoped transcript.
Create the first file and conversation reference in one transaction; subsequent uploads append to that file. Never mutate the caller's conversation.
Source code in octomate/managers/conversation.py
set_external_id
async
¶
Bind a conversation to its replacement runtime session.
Source code in octomate/managers/conversation.py
set_permission_mode
async
¶
set_permission_mode(
conversation: Conversation,
mode: AgentPermissionMode | None,
) -> Conversation
Store the approval posture this conversation's agent works under.
Callers selecting a mode validate against the running agent's catalog. Native observers also store modes that are no longer selectable. None clears the selection and lets the agent's configured default decide.
This method only persists the selection. User changes go through the owning agent tentacle, which also updates its live runtime when supported.
Source code in octomate/managers/conversation.py
set_effort
async
¶
Store the reasoning effort this conversation's runs ask for.
Callers validate the level against the route the conversation runs on; None clears it and lets the runtime's own default decide.
Source code in octomate/managers/conversation.py
set_name
async
¶
Store the name the runtime running this session grabbed for itself.
Only a runtime that names its own sessions has one to store, and it revises it as the session goes on, so this overwrites. A name with nothing in it is not one, and leaves the conversation as it was.
Source code in octomate/managers/conversation.py
grant_session_tool
async
¶
Persist an allow for session grant on the conversation, so the tool
auto-approves on later turns.
Source code in octomate/managers/conversation.py
search_messages
async
¶
search_messages(
conversation_id: UUID7,
query: str,
*,
role: Literal["user", "assistant"] | None = None,
limit: int = 10,
) -> list[ModelMessage]
Conversation messages whose message_text contains query
(case-insensitive), ordered chronologically. One polymorphic select spans
both kinds, so an unfiltered search returns user and assistant hits in a
single pass; role narrows it when set. Tool-call/thinking messages carry
no message_text and never match — reach them via
messages_before/messages_after.
Source code in octomate/managers/conversation.py
messages_before
async
¶
messages_before(
conversation_id: UUID7,
anchor_id: UUID7,
*,
limit: int = 5,
) -> list[ModelMessage]
The limit messages immediately preceding anchor_id in the
conversation (all kinds), oldest-first.
Source code in octomate/managers/conversation.py
messages_after
async
¶
messages_after(
conversation_id: UUID7,
anchor_id: UUID7,
*,
limit: int = 5,
) -> list[ModelMessage]
The limit messages immediately following anchor_id in the
conversation (all kinds), oldest-first.
Source code in octomate/managers/conversation.py
related_chat_messages
async
¶
Source code in octomate/managers/conversation.py
own_runs ¶
The runs in the history of the thread's own conversations — its agents', not the subagents' those agents spawned. A fork's history holds the runs it was forked with, so those are its own too.
Source code in octomate/managers/conversation.py
octomate.managers.deferred ¶
Persistence of deferred-action batches — the questions and approvals a run parks for a human — and their resolution from replies.
DeferredActionManager ¶
Bases: Manager
Persists deferred-action batches and resolves them from user replies.
Source code in octomate/managers/deferred.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
create_batch
async
¶
create_batch(
*,
conversation: Conversation,
agent_tentacle_id: str,
run_name: str | None,
source_address: ChannelAddress,
target_address: ChannelAddress,
target_mode: ResponseTargetMode,
decision: SummonDecision | None,
requests: DeferredToolRequests,
response_mode: DeferredResponseMode,
batch_id: UUID7 | None = None,
) -> DeferredActionBatch
Source code in octomate/managers/deferred.py
pending_for_thread
async
¶
The thread's unanswered batches, oldest first, so a channel can re-present waiting questions and approvals when the thread is reloaded.
Source code in octomate/managers/deferred.py
get_batch
async
¶
Source code in octomate/managers/deferred.py
resolve_batch
async
¶
Source code in octomate/managers/deferred.py
mark_action_presented
async
¶
Source code in octomate/managers/deferred.py
mark_batch
async
¶
Source code in octomate/managers/deferred.py
expire_live
async
¶
Expire every live request still pending. Its waiter lived in the process that asked, so after a restart a reply has nowhere to go; expired, the reply is refused rather than accepted and lost.
Source code in octomate/managers/deferred.py
octomate.managers.gateway ¶
Gateway policy: where a conversation can go, decided the same way for every agent.
OctomateSession is one turn's gateway — the route and destination resolution, the
validation of what a spell names, and the typed decision it records for the reflex
graph to act on after the turn. It speaks no pydantic-ai: the Inkling capability
translates its refusals into ModelRetry and its teleport into a deferral, and any
other runtime's adapter translates them into its own tool errors, so every runtime
meets the same policy through its own tool mechanism. GatewayManager is the
in-process registry an external runtime's tool call resolves its driving turn's
session from.
PrivateBlocker
module-attribute
¶
PRIVATE_REFUSALS
module-attribute
¶
PRIVATE_REFUSALS: dict[PrivateBlocker, str] = {
"no_surface": "This channel has no direct messages.",
"already_private": "This conversation is already that user's direct messages, so there is nowhere to move it to.",
"no_user": "This run has no single user whose direct messages could be opened.",
}
GatewayRefusal ¶
Bases: Exception
A spell that cannot proceed as named, with the sentence that teaches the
caller what to name instead. Neutral on purpose: the Inkling capability
re-raises it as ModelRetry, and an MCP surface returns it as a tool error
the model corrects from — one refusal, worded once, for every runtime.
Source code in octomate/managers/gateway.py
OctomateSession
dataclass
¶
One turn's gateway: the policy the spells share, and the decision they record.
Built per turn by whoever drives one — the react node for a driven agent — and read again when the turn ends: a deciding spell stores its typed decision here, and the reflex graph performs the move. The spells themselves are projected onto each runtime's own tool mechanism by a thin adapter that owns nothing but the translation.
Source code in octomate/managers/gateway.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 | |
channels
class-attribute
instance-attribute
¶
conversation_address
class-attribute
instance-attribute
¶
decision
class-attribute
instance-attribute
¶
other_routes
class-attribute
instance-attribute
¶
destination_cache
class-attribute
instance-attribute
¶
allow_here
property
¶
Whether summon here may hand this conversation over in place.
False on a group's main channel, where pinning an owner would route every gated-in message, from any user, to one agent — and false for a native session, which has no conversation Octomate could hand over.
private_blocked_by
property
¶
Why scheme has nowhere to land from this run, or None when it does.
A gateway that knows no channels can reach no direct messages.
lands_privately
property
¶
Whether a landing should open so only its user can read it: this conversation is theirs alone, and moving it should not change that.
operations
async
property
¶
Offer addresses and channel routes without introducing another target type.
summon_unavailable
property
¶
Why this conversation cannot be handed to another agent where it is.
teleport_unavailable
property
¶
Only a stored, owned history can be imported from a native runtime.
publish
async
¶
Put what a served spell did on the nerve, heard on the thread at
address: on the kick's stream when one drives this turn, so the thread
the kick was asked on hears it too unless it is private, else on that
thread alone.
Source code in octomate/managers/gateway.py
destinations
async
¶
Cache optional address suggestions; execution validates its address independently.
Source code in octomate/managers/gateway.py
list_addresses
async
¶
List one level of a connected channel when it is opened, as the requester's linked identity.
A listed address is a suggestion: execution validates the one it is given.
Source code in octomate/managers/gateway.py
is_compatible_agent ¶
A driven source keeps its agent; native history needs a matching importer.
Source code in octomate/managers/gateway.py
channel_profile
async
¶
The requester's identity usable by this channel, never supplied by a tool.
Source code in octomate/managers/gateway.py
prepare_address
async
¶
Verify identity, then let the owning channel validate its address.
Source code in octomate/managers/gateway.py
direct_destination
async
¶
Resolve the requesting user's DM on the selected channel.
Source code in octomate/managers/gateway.py
claimed_route ¶
claimed_route(
agent_id: str,
model: str,
effort: str | None,
*,
spell: str,
offered: list[AgentRoute] | None = None,
) -> AgentRoute
The offered route for (agent_id, model), with the requested effort
validated against its claim — the shared gatekeeping of summon and
commission. Both arrive as free strings, so this is where an unrouteable
pair is caught; callers build from the returned route, never from the args.
offered is the list to check against, defaulting to this channel's. A
summon that crosses passes the far channel's, since that is who will be
asked to run it.
Source code in octomate/managers/gateway.py
inspect
async
¶
inspect(
reveal: Literal["routes"],
channel: str | None = None,
inside: str | None = None,
) -> list[AgentRoute]
inspect(
reveal: InspectFacet,
channel: str | None = None,
inside: str | None = None,
) -> (
list[AgentRoute]
| list[ChannelAddress]
| list[ProjectSummary]
)
Reveal current or selected-channel routes, addresses, or projects.
Only the requested facet is computed. Destinations with no channel are the
suggested addresses; with one they are a level of that channel, the top
or what inside holds, as list_addresses lists it. Neither limits which
addresses execution can validate.
Source code in octomate/managers/gateway.py
projects
async
¶
The projects this deployment can work on — a registered user's to see, being theirs to bind; a visitor is refused rather than shown nothing.
Source code in octomate/managers/gateway.py
summon
async
¶
summon(
*,
agent_id: str,
model: str,
hint: str,
reason: str,
brief: str,
effort: str | None = None,
) -> str
Validate and record a handoff of this conversation, where it is, for the
graph to perform. Continuing somewhere else is teleport's.
Source code in octomate/managers/gateway.py
teleport
async
¶
teleport(
*,
hint: str,
destination: ChannelAddress | None = None,
new_thread: bool = True,
project: str | None = None,
ref: str | None = None,
resume: bool = False,
prompt: str | None = None,
) -> TeleportDecision
Validate and record a teleport decision — the same agent continuing somewhere else, its history with it. How the move happens is the graph's: the run ends on the decision and the Teleport node performs it.
A thread about a project carries it: the graph lands the move in a thread
about the same project, with the work as it stands, so a teleport never
switches one and naming a project there is refused. A project binds a
thread about none: the thread landed in — a new sub-thread or crossing,
or this thread when new_thread is false, the one case a teleport may
stay put. The project and the ref are validated here, where a refusal
reaches the model; the binding itself is the graph's, on the thread that
turns out to be landed in. Binding is a trust act (a project's own
AGENTS.md reaches the agent as instructions), so it takes a registered
user; only a thread binds, so staying put is refused for a DM or a group,
before a mirror is synced for nothing.
Native history requires a stored thread and a runtime that can import its uploaded transcript. Anonymous native tool sessions still cannot teleport.
Source code in octomate/managers/gateway.py
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 | |
dismiss
async
¶
Record that this thread's workspace may go: its agent has said the work in it is done. Validated here, where a refusal reaches the model; the release is the graph's, once the turn ends and its work is saved, so no tree is pulled out from under a run still in it.
No registered user is needed, unlike a binding: what a release costs is a fork on the next turn, never work. A thread about no project has nothing to release — its tree goes with the turn — and a native session runs in a directory of its own that Octomate never forked.
Source code in octomate/managers/gateway.py
scheme
async
¶
Validate and record a scheme decision, returning the sentence the scheming agent is told. The move itself is the graph's, after the turn.
Source code in octomate/managers/gateway.py
resolve_send
async
¶
The address a send delivers to, or None for this conversation itself.
Being in their direct messages already stops a scheme — nowhere to move
the conversation to — but never a send: that is where it was asked to go,
so it lands here rather than being refused.
Source code in octomate/managers/gateway.py
attach_native_thread
async
¶
Bind a native call to the thread its own session is filed under, as Trunkline's thread operations bind theirs, so a spell it casts acts on that history. Only a thread the caller has written to is found: naming another session, theirs or anyone's, finds nothing.
Source code in octomate/managers/gateway.py
thread_operation ¶
Package a validated user action for the graph's existing-thread entry.
Source code in octomate/managers/gateway.py
native_handoff ¶
This native session's recorded decision, packaged to be kicked as its own turn. Only a native spell leaves one, so anything else asking is a wiring bug, not a refusal a model could correct from.
Source code in octomate/managers/gateway.py
GatewayManager ¶
Bases: Manager
The live Octomate sessions, one per driven turn, keyed by conversation id.
In-process on purpose: a session is only meaningful while its turn is in flight, so a restart rightly forgets them all. An external runtime's tool call presents a conversation id, and this is where it finds the session of the turn driving it.
Source code in octomate/managers/gateway.py
892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 | |
register ¶
Hold the conversation for session, first arrival only.
Nothing else serialises turns of one conversation, so two can overlap; an external caller naming the conversation must find exactly one session, and a second run racing the first would otherwise have its calls land on the first's. So the second is refused outright rather than queued or ignored.
Source code in octomate/managers/gateway.py
unregister ¶
Source code in octomate/managers/gateway.py
get ¶
available_routes ¶
available_routes(
channels: dict[str, ChannelTentacle],
agents: dict[str, AgentTentacle],
) -> dict[str, list[AgentRoute]]
What each channel can route to: every connected agent it exposes, each answering with its own discovered or configured model routes.
The one computation behind both ReflexDeps.available_routes and the
served gateway's ephemeral native session, so a driven turn and a native
call cannot disagree about what a channel offers.
Source code in octomate/managers/gateway.py
driving
async
¶
driving(
session: OctomateSession | None,
*,
conversation_id: UUID7 | None = None,
) -> AsyncGenerator[None]
The registration span of one driven turn: external tool calls reach
session only while the run that mounted it is in flight, and a second
turn of the same conversation is refused at the door. A caller without
gateway spells supplies its conversation id to hold the same guard
without exposing a gateway session. Calls with neither remain untracked.
Source code in octomate/managers/gateway.py
octomate.managers.todos ¶
Conversation-scoped todo persistence.
TodoManager ¶
Bases: Manager
Conversation-scoped todo persistence, keyed on the short hex ref.
Persistence only — event derivation and cycle/blocking validation live in the todo capability, which owns the agent-facing behaviour.
Source code in octomate/managers/todos.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
list_todos
async
¶
Source code in octomate/managers/todos.py
get_todo
async
¶
Source code in octomate/managers/todos.py
add_todo
async
¶
add_todo(
conversation_id: UUID7,
*,
content: str,
active_form: str,
parent_ref: str | None = None,
) -> Todo
Source code in octomate/managers/todos.py
update_todo
async
¶
update_todo(
conversation_id: UUID7,
ref: str,
*,
content: str | None = None,
status: TodoStatus | None = None,
active_form: str | None = None,
parent_ref: str | None = None,
depends_on: list[str] | None = None,
) -> Todo | None
Source code in octomate/managers/todos.py
remove_todo
async
¶
Source code in octomate/managers/todos.py
write_todos
async
¶
Replace the conversation's todos with items; return (deleted, created).