AgentFactory is a registered callable that produces a fresh Agent for each request. Register it in AgentOS(agents=[...]) alongside any prototype agents.
basic_factory.py
Async Factories
Use an async callable when you need to fetch context from a database, an HTTP service, or any other awaitable resource.With an Input Schema
Declare a Pydantic model on the factory to validate client-suppliedfactory_input before the factory runs.
input_schema_factory.py
factory_input as a JSON string in the run request:
factory_input does not validate, AgentOS returns 400 before the factory runs. If factory_input is omitted entirely, AgentOS validates {} against the schema: the request succeeds when every field has a default (like ResearchInput above), and 400s otherwise. Without an input_schema, omitted factory_input leaves ctx.input as None.
Authorization From Verified Context
Usectx.trusted.claims and ctx.trusted.scopes for any decision that affects authorization. Trusted fields are populated by middleware that has verified the request, never by client input.
Error Handling
RaiseFactoryPermissionError from inside the factory to reject unauthorized callers with HTTP 403. AgentOS raises FactoryValidationError (400) automatically when factory_input fails input_schema validation.
Developer Resources
- Factories overview
- RequestContext fields
- Factories reference for the full API surface.
- Factory examples for runnable cookbooks.