Advanced/compatible programmatic examples. Fragments illustrate mechanisms; HostEnv or workspace does not provide isolation. New projects start with Quickstart, Session and explicit resource configuration.
AgentModule is the contract you implement to define agent behavior. It owns everything about how your agent thinks — state initialization, prompt construction, decision logic, and state reduction — but it never runs the loop itself. That is the Engine’s job.
Generic type parameters
AgentModule is generic over three type variables:
Illustrative fragment (not a standalone program; use the complete example linked on this page).
A fully-typed declaration looks like:
Illustrative fragment (not a standalone program; use the complete example linked on this page).
The six hooks
AgentModule defines six hooks. Two are required (init_state and reduce). The rest are optional and have sensible defaults.
init_state (required)
Called once at the start of every run. Return your typed state object, initialized from the task string.
Illustrative fragment (not a standalone program; use the complete example linked on this page).
Engine.run() flow through here, so you can accept max_steps or other initial fields via kwargs.
reduce (required)
Called after every action cycle (one full round of decide → act → observe). Transform the previous state plus the new observation and decision into the next state. This is where your agent absorbs what just happened and updates its progress.
Illustrative fragment (not a standalone program; use the complete example linked on this page).
build_system_prompt (optional)
Return a dynamic system prompt string, or None to skip. Called before every decide step, so your prompt can adapt to the current state.
Illustrative fragment (not a standalone program; use the complete example linked on this page).
None.
prepare (optional)
Converts current state into the model-ready text that becomes the user turn (the message sent to the LLM as the user’s input). Defaults to str(state). Override this to format a structured prompt from your state fields.
Illustrative fragment (not a standalone program; use the complete example linked on this page).
decide (optional)
Override to provide your own decision logic before the Engine calls the LLM. Return None to let the Engine use its standard model decision path.
Illustrative fragment (not a standalone program; use the complete example linked on this page).
should_stop (optional)
An additional stop condition checked each step after reduce. Return True to halt the run. The Engine’s built-in stop criteria (step budget, FinalResultCriteria, etc.) still apply on top of this.
Illustrative fragment (not a standalone program; use the complete example linked on this page).
Minimal example
In QitOS, the minimal public example is still a real coding agent: it configures a model, mounts a workspace, and lets the Engine drive tool use and verification. Illustrative fragment (not a standalone program; use the complete example linked on this page).Running an agent
Callagent.run() to execute a task. This is the primary entry point — it creates an Engine internally, runs the loop, and returns the result.
Illustrative fragment (not a standalone program; use the complete example linked on this page).
agent.run():
Constructor arguments
AgentModule.__init__ accepts these keyword arguments, all optional:
Illustrative fragment (not a standalone program; use the complete example linked on this page).
