qitos and accessible as:
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.HooksOverride these methods in your subclass. Only
init_state and reduce are required.init_state (required)
init_state (required)
Engine.run() before the step loop begins. Use **kwargs to accept extra parameters forwarded from AgentModule.run().reduce (required)
reduce (required)
build_system_prompt
build_system_prompt
None to use no system prompt. Called at the start of each step’s decide phase. Default returns None.prepare
prepare
str(state).decide
decide
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
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.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.Methods
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.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.Engine constructor (same parameters as Engine.__init__).MethodsEngineResult as Engine.run().EngineEvent objects in real time. The stream begins with run_start and ends with run_end.Engine.run().PropertiesEngineEvent, EngineEventType, EventStream
EngineEvent, EngineEventType, EventStream
EngineEvent is the structured event emitted by AsyncEngine.arun_stream().EventStream is an async-compatible event queue for consuming engine events.EngineResult
EngineResult
EngineResult is the dataclass returned by Engine.run().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.Factory methods
.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.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.Key methods
Task, TaskBudget, TaskResource, TaskResult
Task, TaskBudget, TaskResource, TaskResult
Use
Task when you need to pass structured metadata, resources, and budget constraints alongside the objective string.Task helper methodsEnv, EnvSpec
Env, EnvSpec
Env is the abstract environment interface. Implement it to provide a custom observe/step lifecycle for your agent.EnvSpec is a dataclass used inside Task to declare the environment type and configuration:tool decorator
tool decorator
The
tool decorator marks a callable as a QitOS tool and attaches metadata to it without changing its call semantics.Example
ToolRegistry
ToolRegistry
ToolRegistry stores tools and toolsets and is passed to AgentModule and Engine at construction time.ToolRegistry() (no parameters)MethodsBaseTool. Returns self for chaining.namespace (defaults to toolset.name).@tool and register them all.Memory
Memory
Memory is the abstract interface for long-term memory adapters.MemoryRecord is the unit of storage:History, HistoryPolicy
History, HistoryPolicy
History is the abstract interface for model message history adapters.HistoryPolicy controls how the Engine assembles history for model calls:HistoryMessage is the unit of storage:StopReason
StopReason
StopReason is a string enum. Its value is written to state.stop_reason when a run ends.QitosRuntimeError
QitosRuntimeError
QitosRuntimeError is the base class for all structured runtime errors in QitOS.RuntimeErrorInfo carries structured context:ModelExecutionError, ParseExecutionError, ToolExecutionError, StateExecutionError, SystemExecutionError.