Command discovery¶
octomate.managers.commands ¶
Command discovery and guarded execution for host-authorized contexts.
CommandCatalogKey ¶
Bases: NamedTuple
One user's agent catalog, before or after a conversation exists.
Source code in octomate/managers/commands.py
ValidatedCommand ¶
Bases: NamedTuple
Authorized command inputs, valid while the validation scope remains open.
Source code in octomate/managers/commands.py
CommandManager ¶
Bases: Manager
Keep one LRU catalog per user, agent and conversation until invalidated.
Callers must resolve and authorize a fresh context before every lookup, even
a cache hit. Adapters must call invalidate on runtime reconnects and
catalog-change events. Context changes replace the existing catalog and
discard its pending result. Discovery errors are explicit, never empty lists.
Source code in octomate/managers/commands.py
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 | |
catalogs
instance-attribute
¶
discover
async
¶
discover(
agent: AgentTentacle,
context: CommandContext,
*,
refresh: bool = False,
) -> CommandCatalog
Read or refresh a catalog, sharing active discovery in the same context.
Loading and failed results are reprobed on the next lookup. Canceling one caller leaves shared discovery alive under its timeout. New composers share a catalog per user and agent while their contexts match.
Source code in octomate/managers/commands.py
probe
async
¶
Replace a loading catalog only while it still represents this discovery.
Source code in octomate/managers/commands.py
validate
async
¶
validate(
agent: AgentTentacle,
context: CommandContext,
invocation: CommandInvocation,
*,
delivery_id: str,
session: OctomateSession | None = None,
) -> AsyncGenerator[ValidatedCommand | CommandOutcome]
Hold the turn guard while validating a delivery and its execution.
Refresh the catalog, then check access and current context once. Refusals
and matching retries yield their outcome. Otherwise yield a ValidatedCommand
with the authorized surface, profile and descriptor. The surface and
profile may be absent before a conversation exists. Prepare available user
capabilities and call execute inside this scope; validation never dispatches
a command. The guard remains held through the caller's runtime cleanup.
Source code in octomate/managers/commands.py
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 | |
execute
async
¶
execute(
agent: AgentTentacle[OutputT, DepsT],
context: CommandContext,
invocation: CommandInvocation,
validated: ValidatedCommand,
*,
delivery_id: str,
deferred_suspender: DeferredSuspender | None = None,
capabilities: list[AgentCapability[DepsT]]
| None = None,
) -> AsyncGenerator[
CommandOutcome
| AsyncGenerator[ReactStreamEvent[OutputT], None]
]
Record and execute a delivery inside its successful validate scope.
Validation and user preparation belong to the caller. Persist the receipt before native dispatch, preserve arguments, and invalidate the catalog on exit. Consume streamed events inside this context so runtime cleanup and outcome recording finish before the validation scope releases its guard. Without a conversation, dispatch produces only a direct outcome: no receipt, run or thread is created, and retries are not deduplicated. Direct adapter failures become failed outcomes; stream errors and cancellation propagate to the caller.
Source code in octomate/managers/commands.py
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 | |
record_stream
async
¶
record_stream(
stream: AsyncGenerator[
CommandOutcome | ReactStreamEvent[OutputT], None
],
first_event: ReactStreamEvent[OutputT],
receipt_id: UUID,
interrupted: CommandError,
) -> AsyncGenerator[
AsyncGenerator[ReactStreamEvent[OutputT], None]
]
Record completion only after consumption and runtime cleanup both finish.
Events remain owned by the normal stream consumer; a duplicate delivery receives completion status rather than replayed events. An abandoned or failed stream keeps the failure outcome prepared before dispatch.
Source code in octomate/managers/commands.py
invalidate ¶
Forget matching catalogs; pending results cannot repopulate them.
No filters clears all. Invalidated waiters receive loading and must resolve context again before requesting another catalog.
Source code in octomate/managers/commands.py
close
async
¶
Cancel and drain discovery before the host shuts down its agents.
Source code in octomate/managers/commands.py
octomate.commands ¶
Authenticated command discovery and execution for browser clients.
command_router
module-attribute
¶
command_router = APIRouter(
prefix="/api/commands",
tags=["commands"],
dependencies=[Depends(browser_request)],
)
command_context
async
¶
command_context(
agent_id: Annotated[
str,
Body(
min_length=1, description="The selected agent."
),
],
address: Annotated[
ChannelAddress,
Body(
description="The originating channel surface."
),
],
user: Annotated[User, Depends(current_user)],
app: Annotated[Octomate, Depends(application)],
conversations: Annotated[
ConversationManager, Depends(conversation_manager)
],
threads: Annotated[
ThreadManager, Depends(thread_manager)
],
workspaces: Annotated[
WorkspaceManager, Depends(workspace_manager)
],
conversation_id: Annotated[
UUID | None,
Body(
description="An existing conversation; omit for a new composer."
),
] = None,
model: Annotated[
str | None,
Body(
description="A model selection for a new composer; existing conversations use their stored model."
),
] = None,
permission_mode: Annotated[
str | None,
Body(
description="An approval posture for a new composer; existing conversations use their stored permissions."
),
] = None,
) -> CommandContext
Resolve inspection context; reject foreign-agent conversations with HTTP 422 before discovery, workspace lookup, or graph execution.
Source code in octomate/commands.py
discover_commands
async
¶
discover_commands(
context: Annotated[
CommandContext, Depends(command_context)
],
app: Annotated[Octomate, Depends(application)],
refresh: Annotated[
bool,
Body(
description="Rediscover rather than reuse a completed catalog."
),
] = False,
prefix: Annotated[
str,
Body(
description="Case-insensitive command-name prefix; omitted means the full catalog."
),
] = "",
) -> CommandCatalog
Discover or complete commands without creating a conversation or model turn.
Source code in octomate/commands.py
execute_command
async
¶
execute_command(
context: Annotated[
CommandContext, Depends(command_context)
],
app: Annotated[Octomate, Depends(application)],
command_id: Annotated[
str,
Body(
min_length=1,
description="The selected descriptor's opaque ID.",
),
],
delivery_id: Annotated[
str,
Body(
min_length=1,
description="Delivery ID. Existing conversations deduplicate matching retries; executions without a conversation have no persisted receipt.",
),
],
arguments: Annotated[
str,
Body(
description="Raw command arguments, preserved unchanged."
),
] = "",
attachments: Annotated[
list[JsonValue] | None,
Body(
max_length=0,
description="Must be empty until browser uploads are supported.",
),
] = None,
) -> CommandOutcomeEvent
Execute explicit command intent in the resolved context.
A descriptor may permit a direct result before a conversation exists. Such execution creates no thread, conversation, run or receipt; it is not replayable.
Every execution answers with the terminal command outcome, after cleanup and persistence; clients must not render it as another channel message. Every channel executes through the Reflex command node, which publishes feedback, run output and approvals on the nerve: the destination channel draws them, and the thread's live socket carries them to a watching console, up to the reflex falling asleep. A failed execution answers no outcome. Authentication and request-validation errors remain non-2xx JSON responses.