Harness¶
octomate.capabilities.harness.agent ¶
Agent: a Pydantic AI Agent subclass that streams events AND the typed output.
run_stream_events gives raw events but not validated output; stream_output
gives validated partial output but not thinking/tool events. stream_events drives
iter() ourselves and emits BOTH from each node:
- thinking + tool-call events pass through unchanged,
- text replies stream as Pydantic AI's native text events; every validated output
type surfaces as Pydantic AI's own
FinalResult[OutputT]; outputs that validate tolist[MessageSegment]also stream oneResultSegmentEventper segment as partial validation reveals them. Other structured outputs surface only atFinalResult. - capability-injected events (e.g. todo events) flow through the capability wrapper that Pydantic AI applies to each node's stream,
- a terminal
AgentRunResultEventcloses the stream (run-complete / deferred).
The two output_type overloads carry the output type into the event stream, so the
final Agent[Deps, list[Row]].stream_events(...) value is a FinalResult[list[Row]].
Agent ¶
Bases: Agent[AgentDepsT, OutputDataT]
A Pydantic AI agent that can stream events and the typed output together.
Source code in octomate/capabilities/harness/agent.py
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 | |
stream_events
async
¶
stream_events(
user_prompt: str | Sequence[UserContent] | None = None,
*,
output_type: None = None,
message_history: Sequence[ModelMessage] | None = None,
deferred_tool_results: DeferredToolResults
| None = None,
conversation_id: str | None = None,
deps: AgentDepsT = None,
model: Model | KnownModelName | str | None = None,
instructions: AgentInstructions[AgentDepsT] = None,
model_settings: AgentModelSettings[AgentDepsT]
| None = None,
usage_limits: UsageLimits | None = None,
usage: RunUsage | None = None,
metadata: AgentMetadata[AgentDepsT] | None = None,
output_retries: int | None = None,
infer_name: bool = True,
toolsets: Sequence[AbstractToolset[AgentDepsT]]
| None = None,
builtin_tools: Sequence[AgentNativeTool[AgentDepsT]]
| None = None,
capabilities: Sequence[AgentCapability[AgentDepsT]]
| None = None,
spec: dict[str, Any] | AgentSpec | None = None,
) -> AsyncIterator[
StreamEvents[OutputDataT]
| AgentRunResultEvent[OutputDataT]
]
stream_events(
user_prompt: str | Sequence[UserContent] | None = None,
*,
output_type: OutputSpec[RunOutputDataT],
message_history: Sequence[ModelMessage] | None = None,
deferred_tool_results: DeferredToolResults
| None = None,
conversation_id: str | None = None,
deps: AgentDepsT = None,
model: Model | KnownModelName | str | None = None,
instructions: AgentInstructions[AgentDepsT] = None,
model_settings: AgentModelSettings[AgentDepsT]
| None = None,
usage_limits: UsageLimits | None = None,
usage: RunUsage | None = None,
metadata: AgentMetadata[AgentDepsT] | None = None,
output_retries: int | None = None,
infer_name: bool = True,
toolsets: Sequence[AbstractToolset[AgentDepsT]]
| None = None,
builtin_tools: Sequence[AgentNativeTool[AgentDepsT]]
| None = None,
capabilities: Sequence[AgentCapability[AgentDepsT]]
| None = None,
spec: dict[str, Any] | AgentSpec | None = None,
) -> AsyncIterator[
StreamEvents[RunOutputDataT]
| AgentRunResultEvent[RunOutputDataT]
]
stream_events(
user_prompt: str | Sequence[UserContent] | None = None,
*,
output_type: OutputSpec[Any] | None = None,
message_history: Sequence[ModelMessage] | None = None,
deferred_tool_results: DeferredToolResults
| None = None,
conversation_id: str | None = None,
deps: AgentDepsT = None,
model: Model | KnownModelName | str | None = None,
instructions: AgentInstructions[AgentDepsT] = None,
model_settings: AgentModelSettings[AgentDepsT]
| None = None,
usage_limits: UsageLimits | None = None,
usage: RunUsage | None = None,
metadata: AgentMetadata[AgentDepsT] | None = None,
output_retries: int | None = None,
infer_name: bool = True,
toolsets: Sequence[AbstractToolset[AgentDepsT]]
| None = None,
builtin_tools: Sequence[AgentNativeTool[AgentDepsT]]
| None = None,
capabilities: Sequence[AgentCapability[AgentDepsT]]
| None = None,
spec: dict[str, Any] | AgentSpec | None = None,
) -> AsyncIterator[
StreamEvents[Any] | AgentRunResultEvent[Any]
]
Source code in octomate/capabilities/harness/agent.py
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 | |
octomate.capabilities.harness.events ¶
Typed event stream the agent run produces and channels consume.
One stream, with these event families:
- Pydantic AI passthrough (
AgentStreamEvent) — thinking + tool-call events. - Output values — text replies stream as Pydantic AI's native
TextPartevents, every validated output type is emitted as Pydantic AI's ownFinalResult[OutputT], and outputs that validate tolist[MessageSegment]additionally stream oneResultSegmentEventper completed segment as partial validation reveals it — except a trailing text segment, whose growth streams asResultTextDeltaEvents instead. Rendering (typing text, sending segments, or handling any other structured value) is a consumer concern; the event just carries the typed value. - Display events (
DisplayEvent) — fire-and-forget, e.g. the granular todo events (TodoCreatedEvent/TodoUpdatedEvent/TodoStatusChangedEvent/TodoCompletedEvent/TodoDeletedEvent), each carrying the affectedTodo. - Action batch (
ActionBatchEvent) — a persisted batch of deferred actions (questions + approvals) presented as one unit; the run suspends until the user replies.batch_idcorrelates the reply through the deferred-action machinery. - Thread metadata (
ThreadEvent) — committed titles, project bindings, handoffs, ledger entries and command outcomes published by the thread manager. - Subagent lifecycle (
SubagentStartedEvent/SubagentSettledEvent) — an accomplice's run opening and finishing around itscommissionorwhispercall.
Display, action and subagent events are emitted by capabilities (a capability
bundles a tool + instructions + wrap_run_event_stream) or the suspender; the
output events are emitted by Agent.stream_events (see
octomate/capabilities/harness/agent.py).
The reflex graph also reports outside any run (GatewayEvent, RunErrorEvent),
handing each to a channel's Feelers.present, and brackets what a kick does on
the nerve: ReflexAwakeEvent and ReflexAsleepEvent around the kick,
RunStartedEvent and RunEndedEvent around each agent run in it. Channels
present every event and build none; the one consumer-made form is
RunResultEvent, the wire shape of a run result.
The run-stream union itself stays generic (FinalResult[OutputT]), so it has
no single serialized form — but the wire family is concrete, so WireEvent and
its wire_event_adapter live here too: the run stream as a wire consumer sees
it, with the generic/unserializable members replaced by their wire forms.
SubagentActivityStatus
module-attribute
¶
wire_event_adapter
module-attribute
¶
wire_event_adapter: TypeAdapter[WireEvent] = TypeAdapter(
WireEvent, config=ConfigDict(ser_json_bytes="base64")
)
ThreadEvent ¶
ThreadEvent = (
ThreadTitleChangedEvent
| ThreadProjectBoundEvent
| ThreadHandoffRecordedEvent
| ThreadMessageRecordedEvent
| ThreadCommandOutcomeRecordedEvent
)
TodoEvent ¶
TodoEvent = (
TodoCreatedEvent
| TodoUpdatedEvent
| TodoStatusChangedEvent
| TodoCompletedEvent
| TodoDeletedEvent
)
StreamEvents ¶
StreamEvents = (
AgentStreamEvent
| ResultSegmentEvent
| ResultTextDeltaEvent
| FinalResult[OutputT]
| TodoEvent
| MessageSentEvent
| OAuthAuthorizationEvent
| ActionBatchEvent
| ActionBatchAnsweredEvent
| SubagentStartedEvent
| SubagentSettledEvent
)
WireEvent ¶
WireEvent = (
Annotated[
AgentStreamEvent,
Field(json_schema_extra=omit_native_discriminator),
]
| ResultSegmentEvent
| ResultTextDeltaEvent
| TodoEvent
| MessageSentEvent
| ArtifactAvailableEvent
| OAuthDeviceAuthorizationEvent
| OAuthAuthorizationEvent
| ActionBatchEvent
| ActionBatchAnsweredEvent
| SubagentStartedEvent
| SubagentSettledEvent
| RunResultEvent
| ReflexAwakeEvent
| ReflexAsleepEvent
| ThreadEvent
| RunStartedEvent
| RunEndedEvent
| RunErrorEvent
| GatewayEvent
)
SubagentStartedEvent
pydantic-model
¶
Bases: BaseModel
An accomplice's run opened, named by the call that started it; a channel draws it on a timeline of its own.
Fields:
-
event_kind(Literal['subagent_started']) -
invocation_id(str) -
kind(SubagentActivityKind) -
name(str)
Source code in octomate/capabilities/harness/events.py
SubagentSettledEvent
pydantic-model
¶
Bases: BaseModel
The child run finished; response is its accumulated reply text.
Fields:
-
event_kind(Literal['subagent_settled']) -
invocation_id(str) -
status(SubagentActivityStatus) -
detail(str | None) -
response(str)
Source code in octomate/capabilities/harness/events.py
ReflexAwakeEvent
pydantic-model
¶
Bases: BaseModel
A kick's first word: the reflex woken, before anything it does.
Fields:
-
event_kind(Literal['reflex_awake'])
Source code in octomate/capabilities/harness/events.py
ReflexAsleepEvent
pydantic-model
¶
Bases: BaseModel
A kick's last word, the counterpart of ReflexAwakeEvent: the reflex
asleep again, every run and move of the kick over, finished or failed. What
a console waits for before it reads the thread again.
Fields:
-
event_kind(Literal['reflex_asleep'])
Source code in octomate/capabilities/harness/events.py
ThreadTitleChangedEvent
pydantic-model
¶
Bases: BaseModel
A committed title change, including a title derived from an opening message.
Fields:
-
event_kind(Literal['thread_title_changed']) -
thread_id(UUID7) -
title(str | None) -
updated_at(AwareDatetime)
Source code in octomate/capabilities/harness/events.py
ThreadProjectBoundEvent
pydantic-model
¶
Bases: BaseModel
A thread committed its project binding.
Fields:
-
event_kind(Literal['thread_project_bound']) -
thread_id(UUID7) -
project_id(UUID7) -
updated_at(AwareDatetime)
Source code in octomate/capabilities/harness/events.py
ThreadHandoffRecordedEvent
pydantic-model
¶
Bases: BaseModel
A committed handoff identifies the thread's new agent and model.
Fields:
-
event_kind(Literal['thread_handoff_recorded']) -
thread_id(UUID7) -
handoff(Handoff)
Source code in octomate/capabilities/harness/events.py
ThreadMessageRecordedEvent
pydantic-model
¶
Bases: BaseModel
A ledger entry committed, advancing the thread's listing timestamp.
Includes command receipts and fork notices. The first recorded entry makes the thread visible to its registered participants; an unknown thread can be loaded by its id. No message content is copied into a listing notification.
Fields:
-
event_kind(Literal['thread_message_recorded']) -
thread_id(UUID7) -
message_id(UUID7) -
updated_at(AwareDatetime)
Source code in octomate/capabilities/harness/events.py
ThreadCommandOutcomeRecordedEvent
pydantic-model
¶
Bases: BaseModel
A command's terminal outcome committed to its receipt.
Fields:
-
event_kind(Literal['thread_command_outcome_recorded']) -
thread_id(UUID7) -
receipt_id(UUID7) -
outcome(CommandOutcome) -
updated_at(AwareDatetime)
Source code in octomate/capabilities/harness/events.py
event_kind
pydantic-field
¶
RunStartedEvent
pydantic-model
¶
Bases: BaseModel
An agent run beginning, before anything it streams: the thread it reports into — another than the one asked about when a move carried the turn there. A kick holds one run or several, one after another.
Fields:
-
event_kind(Literal['run_started']) -
address(ChannelAddress) -
sender(UserProfile | None)
Source code in octomate/capabilities/harness/events.py
RunEndedEvent
pydantic-model
¶
Bases: BaseModel
An agent run over, finished or failed, after everything it streamed: the
counterpart of RunStartedEvent.
Fields:
-
event_kind(Literal['run_ended']) -
thread_message_id(UUID7 | None)
Source code in octomate/capabilities/harness/events.py
RunResultEvent
pydantic-model
¶
Bases: BaseModel
The serializable projection of AgentRunResultEvent, whose payload
drags the run's private graph state and cannot go on a wire. Carries the
output value so a reply that never streamed (a plain non-streaming model,
a segment-less structured output) still reaches the consumer, and the
usage a session display renders.
Fields:
-
event_kind(Literal['run_result']) -
output(str | list[MessageSegment] | None) -
usage(RunUsage)
Source code in octomate/capabilities/harness/events.py
RunErrorEvent
pydantic-model
¶
Bases: BaseModel
A turn the graph could not finish, reported to the channel it came from, or to the one it was operated from.
Fields:
-
event_kind(Literal['run_error']) -
message(str) -
trace_id(str)
Source code in octomate/capabilities/harness/events.py
GatewayEvent
pydantic-model
¶
Bases: BaseModel
A spell carried the conversation: the console's own operation, or one the agent cast itself mid-turn.
Fields:
-
event_kind(Literal['gateway']) -
action(GatewayAction) -
destination(ChannelAddress) -
announcement(str | None) -
thread_message_id(UUID7 | None)
Source code in octomate/capabilities/harness/events.py
destination
pydantic-field
¶
Where the conversation is now; a summon's own thread.
announcement
pydantic-field
¶
The line the move leaves where the conversation was, or None when it leaves none there.
thread_message_id
pydantic-field
¶
The ledger row of that line, for the channel to mark with the platform id it posts the line as; None when the move recorded none.
ResultSegmentEvent
dataclass
¶
One completed message segment from a list[MessageSegment] output.
This is a convenience streaming event for channel renderers. The full typed
output, segment list or otherwise, still arrives as FinalResult[OutputT].
Source code in octomate/capabilities/harness/events.py
ResultTextDeltaEvent
dataclass
¶
The trailing text segment of a list[MessageSegment] output, as it grows.
A tool-backed segment reply carries its visible text inside the output
tool's streamed arguments, where no native text events exist; partial
validation reveals the trailing segment's text as it grows, and each event
carries the newly revealed piece so the channel renders the reply while the
model is still writing it. A segment that streamed this way is settled by
its last delta and never re-emitted as a ResultSegmentEvent.
Source code in octomate/capabilities/harness/events.py
DisplayEvent
pydantic-model
¶
ArtifactAvailableEvent
pydantic-model
¶
Bases: DisplayEvent
An artifact and its ledger reference have been committed.
The message ID deduplicates this appearance across live events and history; the artifact ID identifies the content for an independently authorized read. No invocation data or resource contents travel in this event.
Fields:
-
event_kind(Literal['artifact_available']) -
message_id(UUID7) -
artifact_id(UUID7)
Source code in octomate/capabilities/harness/events.py
TodoCreatedEvent
pydantic-model
¶
Bases: DisplayEvent
A todo was created.
Fields:
-
event_kind(Literal['todo_created']) -
todo(Todo)
Source code in octomate/capabilities/harness/events.py
TodoUpdatedEvent
pydantic-model
¶
Bases: DisplayEvent
A todo's content or placement changed.
Fields:
-
event_kind(Literal['todo_updated']) -
todo(Todo) -
previous(Todo | None)
Source code in octomate/capabilities/harness/events.py
TodoStatusChangedEvent
pydantic-model
¶
Bases: DisplayEvent
A todo moved to another status.
Fields:
-
event_kind(Literal['todo_status_changed']) -
todo(Todo) -
previous(Todo | None)
Source code in octomate/capabilities/harness/events.py
TodoCompletedEvent
pydantic-model
¶
Bases: DisplayEvent
A todo was completed.
Fields:
-
event_kind(Literal['todo_completed']) -
todo(Todo)
Source code in octomate/capabilities/harness/events.py
TodoDeletedEvent
pydantic-model
¶
Bases: DisplayEvent
A todo was deleted.
Fields:
-
event_kind(Literal['todo_deleted']) -
todo(Todo)
Source code in octomate/capabilities/harness/events.py
MessageSentEvent
pydantic-model
¶
Bases: DisplayEvent
The gate's send emitted segments to be delivered mid-run, without ending
the turn. Emit-only: the tool touches no channel. Where it goes is settled by
the time this is emitted — destination is None for the run's own conversation,
and otherwise a surface the gate resolved from the identity registry.
Fields:
-
event_kind(Literal['message_sent']) -
segments(list[MessageSegment]) -
destination(ChannelAddress | None) -
thread_message_id(UUID7 | None)
Source code in octomate/capabilities/harness/events.py
destination
pydantic-field
¶
None for this conversation. Otherwise the address the gate already resolved from the target the model named, so the consumer delivers without re-deciding anything and a refused destination never reaches one.
thread_message_id
pydantic-field
¶
The ledger row the send left, for the channel to mark with the platform id it delivers it as; None for a send recorded nowhere.
OAuthAuthorizationEvent
pydantic-model
¶
Bases: DisplayEvent
An integration is waiting for this user to authorize their own account.
Carries the authorization itself rather than a rendered message, so each channel
presents it as well as it can — a link in a plain timeline, a card whose button
opens the page where the platform has one. connector_id is the connection this
authorization belongs to.
Emitted as it stands by an authorization-code flow, where opening the link and approving is the whole errand: nothing to copy, and nothing to come back for because the provider's callback finishes the connection.
Fields:
-
event_kind(Literal['oauth_authorization', 'oauth_device_authorization']) -
connector_id(str) -
label(str) -
authorization_uri(str)
Source code in octomate/capabilities/harness/events.py
OAuthDeviceAuthorizationEvent
pydantic-model
¶
Bases: OAuthAuthorizationEvent
A device flow, which asks the user for one thing more.
Finishing is a second errand they have to come back for, which is why the code travels with the link and why a presenter asks them to return. A presenter that does not distinguish the two renders this as its base and simply leaves the code out — wrong, but not misleading.
Fields:
-
connector_id(str) -
label(str) -
authorization_uri(str) -
event_kind(Literal['oauth_authorization', 'oauth_device_authorization']) -
user_code(str)
Source code in octomate/capabilities/harness/events.py
LinkProfileAuthorizationEvent
pydantic-model
¶
Bases: DisplayEvent
A channel requests account authorization from the Octomate host.
Delivered directly through private feelers, not the agent's run stream. The host keeps the request; browser consent links its profile without returning an OAuth credential to the channel.
Fields:
-
event_kind(Literal['link_profile_authorization']) -
host(str) -
authorization(LinkProfileAuthorization)
Source code in octomate/capabilities/harness/events.py
ActionBatchEvent
pydantic-model
¶
Bases: BaseModel
A persisted batch of deferred actions presented as one unit; the run suspends until the user replies.
Carries the batch's questions and approvals (the persisted actions) so the
consumer renders + marks them together, and batch_id to correlate the reply
back to the right run.
Fields:
-
event_kind(Literal['action_batch']) -
batch_id(str) -
questions(list[DeferredQuestion]) -
approvals(list[DeferredApproval])
Source code in octomate/capabilities/harness/events.py
from_batch
classmethod
¶
ActionBatchAnsweredEvent
pydantic-model
¶
Bases: BaseModel
A batch's actions answered, from whichever surface answered them: every reader still showing the batch's cards marks them, so a card answered in one console, or on another channel, stops waiting everywhere.
Fields:
-
event_kind(Literal['action_batch_answered']) -
batch_id(str) -
approvals(dict[UUID7, bool]) -
answers(dict[UUID7, QuestionAnswer])
Source code in octomate/capabilities/harness/events.py
omit_native_discriminator ¶
Keep native event variants without OpenAPI-invalid registry mappings.
Native registries emit inline discriminator targets, while OpenAPI requires references. The generated oneOf still describes every event variant.
Source code in octomate/capabilities/harness/events.py
to_wire ¶
One run stream item as its wire event, or None for the shapes the wire replaces (see the wire module docstring).
Source code in octomate/capabilities/harness/events.py
octomate.capabilities.harness.react ¶
ReactStreamEvent ¶
ReactGraphInput ¶
ReactState
dataclass
¶
The react graph holds no history of its own — only the identity needed to
fetch the live conversation from the ConversationManager. Every node
ensure()s the conversation and reads its messages.
Source code in octomate/capabilities/harness/react.py
RunPersistence
dataclass
¶
Source code in octomate/capabilities/harness/react.py
record
async
¶
record(
run_id: str,
messages: Sequence[ModelMessage],
*,
model_name: str | None,
) -> PersistedAgentRun | None
Source code in octomate/capabilities/harness/react.py
PersistRunFailure
dataclass
¶
Bases: AbstractCapability[ReactDepsT]
Source code in octomate/capabilities/harness/react.py
record_failure
async
¶
Source code in octomate/capabilities/harness/react.py
on_node_run_error
async
¶
on_model_request_error
async
¶
PersistStreamRunFailure
dataclass
¶
Bases: PersistRunFailure[ReactDepsT]
Source code in octomate/capabilities/harness/react.py
wrap_run_event_stream
async
¶
wrap_run_event_stream(
ctx: RunContext[ReactDepsT],
*,
stream: AsyncIterable[AgentStreamEvent],
) -> AsyncIterable[AgentStreamEvent]
Source code in octomate/capabilities/harness/react.py
ReactDeps
dataclass
¶
Source code in octomate/capabilities/harness/react.py
event_send_stream
class-attribute
instance-attribute
¶
choose_resolvers
class-attribute
instance-attribute
¶
output_type
class-attribute
instance-attribute
¶
permission_mode
class-attribute
instance-attribute
¶
instructions
class-attribute
instance-attribute
¶
model_settings
class-attribute
instance-attribute
¶
toolsets
class-attribute
instance-attribute
¶
builtin_tools
class-attribute
instance-attribute
¶
capabilities
class-attribute
instance-attribute
¶
StartTurn
dataclass
¶
Bases: BaseNode[ReactState, ReactDeps[ReactOutputT, ReactDepsT], AgentRunResult[ReactOutputT]]
Source code in octomate/capabilities/harness/react.py
run
async
¶
run(
ctx: GraphRunContext[
ReactState, ReactDeps[ReactOutputT, ReactDepsT]
],
) -> RunAgent[ReactOutputT, ReactDepsT]
Source code in octomate/capabilities/harness/react.py
ResumeTurn
dataclass
¶
Bases: BaseNode[ReactState, ReactDeps[ReactOutputT, ReactDepsT], AgentRunResult[ReactOutputT]]
Source code in octomate/capabilities/harness/react.py
run
async
¶
run(
ctx: GraphRunContext[
ReactState, ReactDeps[ReactOutputT, ReactDepsT]
],
) -> RunAgent[ReactOutputT, ReactDepsT]
Source code in octomate/capabilities/harness/react.py
RunAgent
dataclass
¶
Bases: BaseNode[ReactState, ReactDeps[ReactOutputT, ReactDepsT], AgentRunResult[ReactOutputT]]
Source code in octomate/capabilities/harness/react.py
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 | |
user_prompt
class-attribute
instance-attribute
¶
deferred_results
class-attribute
instance-attribute
¶
run
async
¶
run(
ctx: GraphRunContext[
ReactState, ReactDeps[ReactOutputT, ReactDepsT]
],
) -> (
ResolveDeferred[ReactOutputT, ReactDepsT]
| End[AgentRunResult[ReactOutputT]]
)
Source code in octomate/capabilities/harness/react.py
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 | |
next_node
async
¶
next_node(
ctx: GraphRunContext[
ReactState, ReactDeps[ReactOutputT, ReactDepsT]
],
result: AgentRunResult[ReactOutputT],
persistence: RunPersistence,
span: LogfireSpan,
) -> (
ResolveDeferred[ReactOutputT, ReactDepsT]
| End[AgentRunResult[ReactOutputT]]
)
Source code in octomate/capabilities/harness/react.py
ResolveDeferred
dataclass
¶
Bases: BaseNode[ReactState, ReactDeps[ReactOutputT, ReactDepsT], AgentRunResult[ReactOutputT]]
Source code in octomate/capabilities/harness/react.py
run
async
¶
run(
ctx: GraphRunContext[
ReactState, ReactDeps[ReactOutputT, ReactDepsT]
],
) -> (
RunAgent[ReactOutputT, ReactDepsT]
| End[AgentRunResult[ReactOutputT]]
)
Source code in octomate/capabilities/harness/react.py
ReactEventStream ¶
Deterministic-cleanup handle over a react event stream: entering the
context yields the underlying generator, exiting closes it. Mirrors
pydantic-ai's AgentEventStream, but typed over ReactStreamEvent — a
react run also streams octomate output/display/action-batch events.
Source code in octomate/capabilities/harness/react.py
resolve_conversation
async
¶
resolve_conversation(
ctx: GraphRunContext[
ReactState, ReactDeps[ReactOutputT, ReactDepsT]
],
) -> Conversation
The node's conversation: the pre-ensured one when the run is addressed by id, otherwise the agent's own (thread, agent) conversation.
Source code in octomate/capabilities/harness/react.py
build_react_graph ¶
build_react_graph(
start_node: ReactGraphInput[ReactOutputT, ReactDepsT],
) -> Graph[
ReactState,
ReactDeps[ReactOutputT, ReactDepsT],
ReactGraphInput[ReactOutputT, ReactDepsT],
AgentRunResult[ReactOutputT],
]
Wire the react nodes into a runnable graph for start_node to run through.
The node it will be run with is what binds the graph's type parameters — the output and deps types live only in annotations, so there is nothing else here to infer them from.
Source code in octomate/capabilities/harness/react.py
iter_react_graph_events
async
¶
iter_react_graph_events(
start_node: StartTurn[ReactOutputT, ReactDepsT]
| ResumeTurn[ReactOutputT, ReactDepsT],
*,
state: ReactState,
deps: ReactDeps[ReactOutputT, ReactDepsT],
) -> AsyncGenerator[ReactStreamEvent[ReactOutputT], None]
Source code in octomate/capabilities/harness/react.py
octomate.capabilities.harness.deferred ¶
Deferred-tool resolution protocols — harness interfaces for the react loop.
Two complementary hooks (keep both):
DeferredResolver: resolve deferred calls in-process and let the loop continue.DeferredSuspender: persist + present the requests out-of-band; the run ends and is resumed later by feeding the collected results back through a fresh run.
Which of the two a deferral gets is ResolverChoice's answer, and the loop asks it
anew every time round rather than once per run.
The concrete, channel-coupled suspender (ReflexSuspender) lives in the
triage layer (octomate.reflex.suspender) so the harness never imports
channels.
DeferredResolver ¶
Bases: Protocol
Resolve deferred tool calls in-process so the react loop can continue.
A resolver answers what it speaks for and leaves the rest alone — a posture has
an opinion about approvals and questions, and none at all about a teleport. It
is not the resolver's job to notice that it covered only part of the batch:
ResolveDeferred is where that is noticed, once, for whatever ran. The runner
refuses results covering only some of the calls it deferred, so a batch nobody
wholly answered goes to the suspender entire.
Source code in octomate/capabilities/harness/deferred.py
ResolverChoice ¶
Bases: Protocol
Choose the resolvers for one deferral, from the conversation as it stands at that moment.
Asked at every deferral rather than once per run, because what may be resolved without a human is the conversation's approval posture — and that is switched while runs are going. Composed once, a switch would only reach the run after the one it was made during, which is the turn nobody was watching.
Several, in order, because one batch can hold deferrals of different kinds and no single policy speaks for all of them: each resolver answers its own and earlier ones win, so a catch-all goes last. An empty sequence means nothing answers this batch in-process — it goes to the suspender, and back to the caller when there is none.
Source code in octomate/capabilities/harness/deferred.py
DeclineResolver
dataclass
¶
Resolves every deferred action by declining it immediately — the catch-all that closes a non-interactive run's chain (e.g. a commissioned accomplice). There is no human to ask, so approvals are denied and asks are answered with the decline, and the react loop continues to a final answer in-process instead of parking anything for review.
Last in the chain and answering everything, which is what guarantees a batch is covered: a run with no human has no suspender either, so anything left open would end the run holding requests nobody is coming to answer. Whatever ran before it has already had its say — earlier answers stand.
Source code in octomate/capabilities/harness/deferred.py
message
class-attribute
instance-attribute
¶
message: str = "Declined: this run has no user to ask. Proceed on your best judgment and state the assumption in your report."
resolve
async
¶
Source code in octomate/capabilities/harness/deferred.py
PostureResolver
dataclass
¶
Answers the two things an approval posture speaks about, and nothing else: the approvals it gates, and the questions it says not to put to a human.
What it walks past is the point. A teleport is deferred the same way a question
is, but it is neither an approval nor a question — no posture has an opinion on
it, and the suspender is what performs one. Left unanswered here, the batch is
not wholly covered and all of it goes to the human instead. A deferral arriving
with a kind this does not know goes the same way, so an unrecognized one reaches
a human rather than being answered on their behalf.
Source code in octomate/capabilities/harness/deferred.py
resolve
async
¶
Source code in octomate/capabilities/harness/deferred.py
DeferredSuspender ¶
Bases: Protocol
Human-in-the-loop hook for deferred tool calls the agent cannot resolve
in process. Unlike DeferredResolver, which returns results and lets the
react loop continue, a suspender persists + presents the requests for an
out-of-band response and the run ends; it is resumed later by feeding the
collected DeferredToolResults back through a fresh agent run.
Returning an ActionBatchEvent asks the react loop to put the batch on the
stream, for whoever draws the run to present; returning None means there
is nothing to present, as for a deferral the graph performs itself.
pause is the same for a run that stays live while a human answers, as a
runtime's in-process approval does: the event of the batch it waits on, for
the run's own stream. The caller names the batch, so it is already waiting on
that id when the cards go up and a quick reply finds it.
Source code in octomate/capabilities/harness/deferred.py
suspend
async
¶
Read
dataclass
¶
Ended
dataclass
¶
A runtime's own stream is over, or failed with error.
Source code in octomate/capabilities/harness/deferred.py
Interjections ¶
What a live run's callbacks put on its stream while it waits on the runtime: the batch an approval pauses the run on, and the answer it resumes on, for whoever draws the run.
The runtime's own stream is read in a task of its own, so a batch gets through while the runtime is still waiting for its answer.
Source code in octomate/capabilities/harness/deferred.py
interject ¶
around
async
¶
source's items in order, with each interjection as it is made.