Skip to main content
Registered callables that produce a fresh Agent, Team, or Workflow per request. AgentFactory, TeamFactory, and WorkflowFactory are thin subclasses of BaseFactory[T] and share the same constructor; they differ only in the component type produced.

Import

Parameters

Shared constructor signature for AgentFactory, TeamFactory, and WorkflowFactory: After the factory returns, AgentOS enforces the component’s id to match the factory’s id, fills the component’s db from the factory if unset, sets store_events=True so per-step run events persist on the run output, and runs the component-specific initialize_*().

RequestContext

AgentOS passes a RequestContext as the sole argument to every factory call.

factory_input by endpoint

Identity precedence

user_id and session_id follow the same precedence as the prototype path. Verified middleware wins over the form field. On POST /runs, if both are set and disagree, the form value is overridden and a warning is logged.
  1. request.state.user_id / request.state.session_id set by verified middleware (e.g. JWTMiddleware lifting the sub claim). Wins if present.
  2. Explicit form field on the run request. Used only when no verified value is set.
  3. None.

Exceptions

All factory exceptions inherit from FactoryError. The router maps them to HTTP status codes:

Usage

Mixing Factories and Prototypes

Sending factory_input

See Also