Skip to main content
This preserves the previous page as historical text. Its signatures, defaults and export claims may not match current source; it is not the current API contract. Current API Every symbol listed here is exported from qitos and accessible as: Signature reference (not executable):

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):
ConstructorSignature reference (not executable):
HooksOverride these methods in your subclass. Only init_state and reduce are 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().
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.
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.
Signature reference (not executable):
Convert the current state into a model-ready text string (the user turn). Default returns str(state).
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.
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 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):
ConstructorSignature reference (not executable):
MethodsSignature reference (not executable):
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.
Signature reference (not executable):
Append one hook instance to the active hook list.
Signature reference (not executable):
Remove one hook instance from the active hook list (identity comparison).
Signature reference (not executable):
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.Signature reference (not executable):
ConstructorSignature reference (not executable):
All keyword arguments are forwarded to the internal Engine constructor (same parameters as Engine.__init__).MethodsSignature reference (not executable):
Execute the agent loop asynchronously. Returns the same EngineResult as Engine.run().
Signature reference (not executable):
Execute the agent loop and yield EngineEvent objects in real time. The stream begins with run_start and ends with run_end.
Signature reference (not executable):
Synchronous fallback — delegates to the underlying Engine.run().Properties
EngineEvent is the structured event emitted by AsyncEngine.arun_stream().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).
EventStream is an async-compatible event queue for consuming engine events.Signature reference (not executable):
EngineResult is the dataclass returned by Engine.run().Illustrative fragment (not a standalone program; use the complete example linked on this page).
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).
ModesFactory methodsSignature reference (not executable):
Signature reference (not executable):
Signature reference (not executable):
Signature reference (not executable):
.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.Illustrative fragment (not a standalone program; use the complete example linked on this page).
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.Illustrative fragment (not a standalone program; use the complete example linked on this page).
Key methodsSignature reference (not executable):
Use 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).
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 helper methodsSignature reference (not executable):
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).
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 stores tools and toolsets and is passed to AgentModule and Engine at construction time.Signature reference (not executable):
ConstructorToolRegistry() (no parameters)MethodsSignature reference (not executable):
Register a single callable or BaseTool. Returns self for chaining.
Signature reference (not executable):
Register all tools from a toolset object. Tool names are prefixed with namespace (defaults to toolset.name).
Signature reference (not executable):
Scan an object for methods decorated with @tool and register them all.
Signature reference (not executable):
ExampleIllustrative fragment (not a standalone program; use the complete example linked on this page).
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 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 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 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).
Typed subclasses: ModelExecutionError, ParseExecutionError, ToolExecutionError, StateExecutionError, SystemExecutionError.