qitos and accessible as:
Signature reference (not executable):
AgentModule
AgentModule
AgentModule is the strategy layer of QitOS. You subclass it to define your agent’s state shape, system prompt, decision logic, and reduction rules. The Engine drives the execution loop (the kernel) and calls each hook in order.Signature reference (not executable):HooksOverride these methods in your subclass. Only
init_state and reduce are required.init_state (required)
init_state (required)
Signature reference (not executable):Create and return the initial typed state for a run. Called once by
Engine.run() before the step loop begins. Use **kwargs to accept extra parameters forwarded from AgentModule.run().reduce (required)
reduce (required)
Signature reference (not executable):Fold the current observation and decision into the next state. Called at the end of every step. Return the updated state.
build_system_prompt
build_system_prompt
Signature reference (not executable):Return a dynamic system prompt string, or
None to use no system prompt. Called at the start of each step’s decide phase. Default returns None.prepare
prepare
Signature reference (not executable):Convert the current state into a model-ready text string (the user turn). Default returns
str(state).decide
decide
Signature reference (not executable):Optional custom decision hook. Return a
Decision to bypass the Engine’s model call, or None to let the Engine call the LLM and parse the output. Default returns None.should_stop
should_stop
Signature reference (not executable):Optional additional stop condition checked after each step. Return
True to terminate the run with StopReason.AGENT_CONDITION. Default returns False..run() methodConvenience method that builds an Engine, runs it, and returns the final result.Signature reference (not executable):Returns
state.final_result by default, or an EngineResult when return_state=True.Engine
Engine
Engine is the execution kernel (the core AgentModule + Engine execution loop). It owns the phase loop, tool execution, recovery, tracing, and stop-criteria evaluation. You normally obtain an Engine through AgentModule.build_engine() or AgentModule.run(), but you can also construct one directly.Signature reference (not executable):MethodsSignature reference (not executable):
task. Resets run state, initialises the env, calls agent.init_state(), then iterates the decide→act→reduce→check_stop cycle until a stop condition triggers. Returns an EngineResult.Signature reference (not executable):
Signature reference (not executable):
Signature reference (not executable):
AsyncEngine
AsyncEngine
AsyncEngine provides non-blocking execution for agent workflows. It wraps the same Engine loop but runs blocking calls in a thread pool, making it safe to use inside asyncio event loops.Signature reference (not executable):Engine constructor (same parameters as Engine.__init__).MethodsSignature reference (not executable):EngineResult as Engine.run().Signature reference (not executable):
EngineEvent objects in real time. The stream begins with run_start and ends with run_end.Signature reference (not executable):
Engine.run().PropertiesEngineEvent, EngineEventType, EventStream
EngineEvent, EngineEventType, EventStream
EngineEvent is the structured event emitted by AsyncEngine.arun_stream().Illustrative fragment (not a standalone program; use the complete example linked on this page).EventStream is an async-compatible event queue for consuming engine events.Signature reference (not executable):EngineResult
EngineResult
EngineResult is the dataclass returned by Engine.run().Illustrative fragment (not a standalone program; use the complete example linked on this page).Decision
Decision
Decision is the canonical output of the decide phase. Use the factory class methods rather than constructing directly. A Decision captures what the agent wants to do next — execute actions, produce a final answer, wait, or propose branch candidates.Illustrative fragment (not a standalone program; use the complete example linked on this page).Factory methodsSignature reference (not executable):
.validate() — Raises ValueError if the decision is structurally invalid (e.g. act with no actions).Action
Action
Action is the normalized action (a tool invocation) contract emitted by the policy and consumed by the executor.Illustrative fragment (not a standalone program; use the complete example linked on this page).Action.from_dict(payload) — Construct from a plain dict.StateSchema
StateSchema
StateSchema is the canonical typed state base class. Subclass it to define your agent’s state fields.Illustrative fragment (not a standalone program; use the complete example linked on this page).Key methodsSignature reference (not executable):
Task, TaskBudget, TaskResource, TaskResult
Task, TaskBudget, TaskResource, TaskResult
Use Illustrative fragment (not a standalone program; use the complete example linked on this page).Illustrative fragment (not a standalone program; use the complete example linked on this page).Illustrative fragment (not a standalone program; use the complete example linked on this page).
Task when you need to pass structured metadata, resources, and budget constraints alongside the objective string.Illustrative fragment (not a standalone program; use the complete example linked on this page).Task helper methodsSignature reference (not executable):Env, EnvSpec
Env, EnvSpec
Env is the abstract environment interface. Implement it to provide a custom observe/step lifecycle for your agent.Illustrative fragment (not a standalone program; use the complete example linked on this page).EnvSpec is a dataclass used inside Task to declare the environment type and configuration:Illustrative fragment (not a standalone program; use the complete example linked on this page).tool decorator
tool decorator
The
tool decorator marks a callable as a QitOS tool and attaches metadata to it without changing its call semantics.Signature reference (not executable):ExampleIllustrative fragment (not a standalone program; use the complete example linked on this page).
ToolRegistry
ToolRegistry
ToolRegistry stores tools and toolsets and is passed to AgentModule and Engine at construction time.Signature reference (not executable):ToolRegistry() (no parameters)MethodsSignature reference (not executable):BaseTool. Returns self for chaining.Signature reference (not executable):
namespace (defaults to toolset.name).Signature reference (not executable):
@tool and register them all.Signature reference (not executable):
Memory
Memory
Memory is the abstract interface for long-term memory adapters.Illustrative fragment (not a standalone program; use the complete example linked on this page).MemoryRecord is the unit of storage:Illustrative fragment (not a standalone program; use the complete example linked on this page).History, HistoryPolicy
History, HistoryPolicy
History is the abstract interface for model message history adapters.Illustrative fragment (not a standalone program; use the complete example linked on this page).HistoryPolicy controls how the Engine assembles history for model calls:Illustrative fragment (not a standalone program; use the complete example linked on this page).HistoryMessage is the unit of storage:Illustrative fragment (not a standalone program; use the complete example linked on this page).StopReason
StopReason
StopReason is a string enum. Its value is written to state.stop_reason when a run ends.Illustrative fragment (not a standalone program; use the complete example linked on this page).QitosRuntimeError
QitosRuntimeError
QitosRuntimeError is the base class for all structured runtime errors in QitOS.Illustrative fragment (not a standalone program; use the complete example linked on this page).RuntimeErrorInfo carries structured context:Illustrative fragment (not a standalone program; use the complete example linked on this page).ModelExecutionError, ParseExecutionError, ToolExecutionError, StateExecutionError, SystemExecutionError.