Skip to main content
Every symbol listed here is exported from qitos and accessible as:

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.
Constructor
HooksOverride these methods in your subclass. Only init_state and reduce are required.
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().
Fold the current observation and decision into the next state. Called at the end of every step. Return the updated state.
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.
Convert the current state into a model-ready text string (the user turn). Default returns str(state).
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.
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.
Returns state.final_result by default, or an EngineResult when return_state=True.
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.
Constructor
Methods
Execute the agent loop for 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.
Append one hook instance to the active hook list.
Remove one hook instance from the active hook list (identity comparison).
Remove all registered hooks.
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.
Constructor
All keyword arguments are forwarded to the internal Engine constructor (same parameters as Engine.__init__).Methods
Execute the agent loop asynchronously. Returns the same EngineResult as Engine.run().
Execute the agent loop and yield EngineEvent objects in real time. The stream begins with run_start and ends with run_end.
Synchronous fallback — delegates to the underlying Engine.run().Properties
EngineEvent is the structured event emitted by AsyncEngine.arun_stream().
EventStream is an async-compatible event queue for consuming engine events.
EngineResult is the dataclass returned by Engine.run().
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.
ModesFactory methods
.validate() — Raises ValueError if the decision is structurally invalid (e.g. act with no actions).
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 is the canonical typed state base class. Subclass it to define your agent’s state fields.
Key methods
Use Task when you need to pass structured metadata, resources, and budget constraints alongside the objective string.
Task helper methods
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:
The tool decorator marks a callable as a QitOS tool and attaches metadata to it without changing its call semantics.
Example
ToolRegistry stores tools and toolsets and is passed to AgentModule and Engine at construction time.
ConstructorToolRegistry() (no parameters)Methods
Register a single callable or BaseTool. Returns self for chaining.
Register all tools from a toolset object. Tool names are prefixed with namespace (defaults to toolset.name).
Scan an object for methods decorated with @tool and register them all.
Example
Memory is the abstract interface for long-term memory adapters.
MemoryRecord is the unit of storage:
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 is a string enum. Its value is written to state.stop_reason when a run ends.
QitosRuntimeError is the base class for all structured runtime errors in QitOS.
RuntimeErrorInfo carries structured context:
Typed subclasses: ModelExecutionError, ParseExecutionError, ToolExecutionError, StateExecutionError, SystemExecutionError.