Model 1: Embedded SDK
Direct Python integration with zero network overhead
Run recipes inside your Python process for the lowest latency and direct access to results.
from praisonaiagents import Agent
agent = Agent(
name="In-Process Runner",
instructions="Execute recipe logic in-process for a notebook workflow.",
)
agent.start("Run the summarisation recipe on this paragraph.")The user calls the SDK from application code; results return in memory with no network hop.
graph LR
U[Input] --> A[Agent]
A --> O[Output]
classDef agent fill:#8B0000,color:#fff
classDef tool fill:#189AB4,color:#fff
class A agent
class U,O toolHow It Works
flowchart LR
subgraph YourApp["Your Python Application"]
A[Application Code] --> B[recipe.run]
B --> C[Recipe Execution]
C --> D[Result Object]
end
style YourApp fill:#e8f5e9
classDef agent fill:#8B0000,color:#fff
classDef tool fill:#189AB4,color:#fffThe Embedded SDK runs recipes directly in your Python process. No network calls, no serialization overhead—just direct function calls.
Pros & Cons
Pros
- Zero network latency – Direct in-process execution
- Direct memory access – Work with Python objects directly
- Simplest integration – Just import and call
- Full Python ecosystem – Use any Python library alongside recipes
- Streaming support – Real-time event streaming
Cons
- Python-only – Not available for other languages
- Shared resources – Recipe runs in same process (memory, CPU)
- No built-in multi-tenancy – Single-tenant by design
- No process isolation – Errors can affect host process
Step-by-Step Tutorial
- Install PraisonAI
bash pip install praisonai - Set API Keys
bash export OPENAI_API_KEY=your-key - List Available Recipes
python from praisonai import recipe # List all available recipes recipes = recipe.list_recipes() for r in recipes: print(f"{r.name}: {r.description}") - Run a Recipe (Sync)
python from praisonai import recipe result = recipe.run( "my-recipe", input={"query": "Summarize this document"}, options={"timeout_sec": 60} ) if result.ok: print(f"Success: {result.output}") else: print(f"Error: {result.error}") - Run a Recipe (Streaming)
python from praisonai import recipe for event in recipe.run_stream("my-recipe", input={"query": "Hello"}): if event.event_type == "progress": print(f"[{event.data.get('step')}] {event.data.get('message')}") elif event.event_type == "completed": print(f"Done: {event.data.get('output')}")
Production-Ready Example
import logging
from praisonai import recipe
from praisonai.recipe import RecipeError, RecipeResult
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def process_with_recipe(
recipe_name: str,
input_data: dict,
timeout_sec: int = 60,
retries: int = 3
) -> RecipeResult:
"""
Production-ready recipe invocation with retries and error handling.
"""
last_error = None
for attempt in range(retries):
try:
result = recipe.run(
recipe_name,
input=input_data,
options={
"timeout_sec": timeout_sec,
"trace_id": f"req-{attempt}",
}
)
if result.ok:
logger.info(f"Recipe {recipe_name} completed: run_id={result.run_id}")
return result
else:
logger.warning(f"Recipe failed (attempt {attempt + 1}): {result.error}")
last_error = result.error
except RecipeError as e:
logger.error(f"Recipe error (attempt {attempt + 1}): {e}")
last_error = str(e)
# All retries exhausted
raise RuntimeError(f"Recipe {recipe_name} failed after {retries} attempts: {last_error}")
# Usage
if __name__ == "__main__":
result = process_with_recipe(
"support-reply-drafter",
input_data={"ticket_id": "T-123", "message": "I need help"},
timeout_sec=30,
retries=3
)
print(result.output)Troubleshooting
ImportError: No module named 'praisonai'
Ensure PraisonAI is installed in your Python environment:
pip install praisonaiIf using a virtual environment, make sure it’s activated.
Recipe not found
Check available recipes:
praisonai recipe listRecipes are discovered from:
~/.praisonai/templates~/.config/praison/templates./.praison/templates(current directory)
API key error
Verify your API key is set:
import os
print(os.environ.get("OPENAI_API_KEY", "NOT SET"))Set it in your environment:
export OPENAI_API_KEY=sk-...Timeout errors
Increase the timeout or check if the recipe is hanging:
result = recipe.run(
"my-recipe",
input=data,
options={"timeout_sec": 120} # 2 minutes
)Security & Ops Notes
- Process isolation: Recipes run in your process—malicious recipes could access your memory
- API keys: Ensure API keys are not logged or exposed
- Input validation: Validate inputs before passing to recipes
- Resource limits: Consider memory/CPU limits for long-running recipes
API Reference
recipe.run()
def run(
name: str,
input: dict = None,
config: dict = None,
session_id: str = None,
options: dict = None
) -> RecipeResult| Parameter | Type | Description |
|---|---|---|
name | str | Recipe name |
input | dict | Input data for the recipe |
config | dict | Recipe configuration overrides |
session_id | str | Session ID for stateful recipes |
options | dict | Execution options (timeout_sec, trace_id, etc.) |
recipe.run_stream()
def run_stream(
name: str,
input: dict = None,
config: dict = None,
session_id: str = None,
options: dict = None
) -> Iterator[RecipeEvent]Returns an iterator of RecipeEvent objects with:
event_type: “started”, “progress”, “completed”, “error”data: Event-specific data dictionary
Next Steps
- CLI Invocation – For scripts and automation
- Local HTTP Sidecar – For polyglot environments
- Use Cases – Real-world implementation patterns