How It Works
Quick Start
When to Use build_host_app vs build_ui_app
Both APIs remain supported. Choose based on how much control you need:
| Pattern | Best for |
|---|---|
build_ui_app(UIPreset(...)) | Chat/dashboard/bot UIs with sensible defaults |
build_host_app(...) | Quick host with keyword arguments |
configure_host + create_host_app | Custom bridges, agents list, theme hooks |
Integration Patterns
Choose your integration pattern based on your needs:Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
pages | Sequence[str] | None | UI pages to include |
title | str | "PraisonAI" | Application title |
logo | str | "🤖" | Logo or emoji |
sidebar | bool | True | Show navigation sidebar |
page_header | bool | True | Show page header |
style | str | "dashboard" | UI layout: "dashboard" or "chat" |
context_paths | Sequence[str] | None | Context file paths. None → walk-up auto-discovery from context_cwd (or process cwd). [] → authoritative “load nothing” sentinel; discovery is skipped. ["AGENTS.md", ...] → load exactly those paths from cwd; no walk-up. |
no_context | bool | False | Skip all project-context loading. Honoured as a first-class param and when threaded through agent_kwargs={"no_context": True} (backward compat). |
context_cwd | Optional[str] | None | Starting directory for walk-up discovery. Falls back to process cwd. Ignored when context_paths is explicitly provided. |
context_token_budget | int | 8000 | Maximum characters of discovered context to inject. Excess is truncated and \n... [project context truncated] is appended. |
theme | Dict[str, Any] | None | Custom theme settings |
agents | List[Any] | None | Pre-configured agents |
agent_kwargs | Dict[str, Any] | None | Default agent parameters |
gateway | Any | None | External gateway reference |
modules | Sequence[str] | None | Additional modules to load |
API Reference
Core Functions
configure_host()
configure_host()
Apply host settings and wire backends. Must be called before
create_host_app().create_host_app()
create_host_app()
Return the Starlette app instance. Call after
configure_host().build_host_app()
build_host_app()
One-shot configuration and app creation. Simplest approach.
run_integrated_gateway()
run_integrated_gateway()
Pattern C: Start gateway with integrated UI on single port. Sync wrapper for CLI and scripts.For async usage, use the async variant:
Legacy Mode
@aiui.reply callbacks work - no automatic agent integration.
Common Patterns
Pattern B: In-Process Host
Embed the UI in your existing application:Pattern C via CLI
Use the integrated UI-Gateway command for quick setup:Pattern C: Integrated Gateway
Single process serving UI + API + WebSocket:Custom Bridges
Wire your own backend services:Bridge failures are now logged as warnings for non-ImportError exceptions (previously debug level). This improves visibility when optional services fail to initialize.
Best Practices
Environment Configuration
Environment Configuration
Use environment variables for configuration that changes between deployments:
Error Handling
Error Handling
Handle import errors gracefully for optional features:
Resource Cleanup
Resource Cleanup
Use context managers for proper cleanup in long-running applications:
Related
Integration Patterns
Compare Pattern B vs C vs D
Backend Injection
Custom backend services

