Escalation Pipeline

Agent-centric progressive escalation from direct response to autonomous mode

The escalation pipeline adjusts execution complexity from simple answers to full autonomous loops — all via Agent(autonomy=True).

Diagram

Escalation Pipeline

📋 User Request

⚙️ Escalation Pipeline

✅ Result

Diagram
Escalation PipelineAgentUserEscalation PipelineAgentUserRequestProcess requestResultResponse
python
from praisonaiagents import Agent

agent = Agent(
    instructions="You are a helpful coding assistant.",
    llm="gpt-4o-mini",
    autonomy=True,
)

stage = agent.get_recommended_stage("Refactor the auth module")
print(stage)  # "autonomous"

response = agent.start("What is Python?")
print(response)

The user sends a prompt; the agent escalates from direct answers to heuristic, planned, or autonomous execution based on task signals.

Diagram

Escalation Pipeline

📝 Prompt

🔍 Signal Detection

⚙️ Pick Stage

🤖 Agent

✅ Response

How It Works

Diagram
EscalatorAgentUserEscalatorAgentUserSend promptget_recommended_stage(task)direct / heuristic / planned / autonomousResponse at the right complexity

Escalation Stages

Diagram

📋 Prompt

🔍 Signal detection

Direct

Heuristic

Planned

Autonomous

🛡 Loop guard + doom loop

Quick Start

  1. Enable autonomy
    python
    from praisonaiagents import Agent
    
    agent = Agent(
        instructions="You are a helpful coding assistant.",
        llm="gpt-4o-mini",
        autonomy=True,
    )
    
    # Fast heuristics — no LLM call
    stage = agent.get_recommended_stage("What is Python?")
    signals = agent.analyze_prompt("Refactor the auth module")
    
    print(stage)    # direct
    print(signals)  # {'refactor_intent', 'complex_keywords'}
    
    response = agent.start("What is Python?")
    print(response)
  2. Custom configuration
    python
    from praisonaiagents import Agent, AutonomyConfig
    
    agent = Agent(
        instructions="You are a coding assistant.",
        autonomy=AutonomyConfig(
            max_iterations=30,
            doom_loop_threshold=5,
            auto_escalate=True,
        ),
    )
    
    print(agent.autonomy_enabled)
    print(agent.autonomy_config)

Stages and Signals

StageNameTypical trigger
0DIRECTSimple questions (simple_question)
1HEURISTICFile paths, code blocks
2PLANNEDEdit, test, or build intent
3AUTONOMOUSMulti-step refactor, complex keywords
python
from praisonaiagents import Agent

agent = Agent(instructions="Assistant", autonomy=True)

agent.get_recommended_stage("What is Python?")           # direct
agent.get_recommended_stage("Read src/main.py")          # heuristic
agent.get_recommended_stage("Fix the bug in auth.py")    # planned
agent.get_recommended_stage("Refactor auth and add tests") # autonomous
SignalTrigger examples
simple_question“what is”, “define”, “explain”
file_referencesPaths like src/main.py
edit_intent“edit”, “modify”, “fix”
refactor_intent“refactor”, “restructure”
complex_keywords“analyse”, “optimise”, “refactor”

CLI

bash
# Simple question — DIRECT stage
praisonai "What is Python?"

# Complex task — escalates to AUTONOMOUS
praisonai "Refactor the auth module and add tests"

praisonai chat --autonomy

Pipeline Components

Under praisonaiagents/escalation/:

  • Doom loop detector — identical calls and no-progress patterns
  • Loop guard — idempotency-aware tool-call guardrails on every Agent. See Loop Guard.
  • Pipeline orchestration — escalation triggers and recovery
  • Observability hooks — metrics for escalation events

Best Practices

Enable with autonomy=True

Pass autonomy=True or an AutonomyConfig — the agent selects the stage automatically during execution.

Inspect signals before heavy runs

Call analyze_prompt() to preview complexity without an LLM call when building UIs or routing logic.

Override a false-positive doom-loop stop

A detected doom loop is now a recoverable approval decision, not a hardcoded block. The default still stops (backward-compatible), but a legitimate repeat — e.g. polling a build-status endpoint — can continue with doom_loop=allow:

yaml
permissions:
  doom_loop: allow
python
from praisonaiagents import Agent
from praisonaiagents.permissions import PermissionManager

agent = Agent(
    instructions="Poll the build until it finishes.",
    permission_manager=PermissionManager(rules={"doom_loop": "allow"}),
)

The gate is fail-closed: deny, timeout, no backend, or any error falls back to the historical hard-stop. See Approval.

Awaiting execute() is non-blocking and concurrency-safe

EscalationPipeline.execute() runs agent.chat via asyncio.to_thread, so awaiting it does not stall the event loop. The heuristic stage passes tools per call (agent.chat(prompt, tools=...)) and never mutates agent.tools, so concurrent execute() calls sharing one agent don’t leak tool lists into each other.

get_current_stage() and get_context() still reflect a single in-flight call per pipeline instance — for parallel inspection, use one pipeline per request.

Stay agent-centric

No standalone pipeline objects — escalation, loop guard, and doom-loop detection live on Agent.


Related