HEX
Server: LiteSpeed
System: Linux houston.panomity.com 6.8.0-100-generic #100-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 13 16:40:06 UTC 2026 x86_64
User: nudepix (1011)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //opt/PraisonAI/docs/examples/emergency-response.mdx
---
title: "Emergency Response"
sidebarTitle: "Emergency Response"
description: "Learn how to create AI agents for coordinated emergency response and resource management."
icon: "truck-medical"
---

```mermaid
flowchart LR
    In[In] --> Router[Emergency Router]
    Router -->|critical/high| Dispatcher[Resource Dispatcher]
    Router -->|medium/low| Dispatcher
    Dispatcher --> Monitor[Response Monitor]
    Monitor -->|ongoing| Coordinator[Response Coordinator]
    Monitor -->|completed| Out[Out]
    Coordinator --> Out
    
    style In fill:#8B0000,color:#fff
    style Router fill:#2E8B57,color:#fff
    style Dispatcher fill:#2E8B57,color:#fff
    style Monitor fill:#2E8B57,color:#fff
    style Coordinator fill:#2E8B57,color:#fff
    style Out fill:#8B0000,color:#fff
```

A workflow demonstrating how AI agents can coordinate emergency response, from initial assessment through resource dispatch and response monitoring.

## Quick Start

<Steps>
    <Step title="Install Package">
        First, install the PraisonAI Agents package:
        ```bash
        pip install praisonaiagents
        ```
    </Step>

    <Step title="Set API Key">
        Set your OpenAI API key as an environment variable in your terminal:
        ```bash
        export OPENAI_API_KEY=your_api_key_here
        ```
    </Step>

    <Step title="Create a file">
        Create a new file `app.py` with the basic setup:
        ```python
        from praisonaiagents import Agent, Task, PraisonAIAgents
        import time
        from typing import Dict, List

        def assess_emergency(incident: Dict):
            """Simulates emergency assessment"""
            severity_levels = ["low", "medium", "high", "critical"]
            current_time = int(time.time())
            severity = severity_levels[current_time % 4]
            print(f"Incident assessed with {severity} severity")
            return severity

        def dispatch_resources(severity: str):
            """Simulates resource dispatch"""
            resources = {
                "low": ["local_police"],
                "medium": ["local_police", "ambulance"],
                "high": ["local_police", "ambulance", "fire"],
                "critical": ["local_police", "ambulance", "fire", "special_units"]
            }
            dispatched = resources.get(severity, ["local_police"])
            print(f"Dispatching resources: {dispatched}")
            return dispatched

        def monitor_response():
            """Simulates response monitoring"""
            current_time = int(time.time())
            status = "completed" if current_time % 3 == 0 else "ongoing"
            return status

        # Create specialized agents
        router = Agent(
            name="Emergency Router",
            role="Emergency Assessment",
            goal="Evaluate emergency severity and type",
            instructions="Assess incident and determine required response",
            tools=[assess_emergency]
        )

        dispatcher = Agent(
            name="Resource Dispatcher",
            role="Resource Management",
            goal="Coordinate and dispatch appropriate resources",
            instructions="Deploy resources based on emergency assessment",
            tools=[dispatch_resources]
        )

        monitor = Agent(
            name="Response Monitor",
            role="Response Tracking",
            goal="Track response progress and effectiveness",
            instructions="Monitor ongoing response and provide status updates",
            tools=[monitor_response]
        )

        synthesizer = Agent(
            name="Response Coordinator",
            role="Response Synthesis",
            goal="Coordinate multi-agency response",
            instructions="Synthesize information and coordinate overall response"
        )

        # Create workflow tasks
        assessment_task = Task(
            name="assess_emergency",
            description="Evaluate emergency severity and type",
            expected_output="Emergency severity level",
            agent=router,
            is_start=True,
            task_type="decision",
            condition={
                "critical": ["dispatch_resources", "monitor_response"],
                "high": ["dispatch_resources", "monitor_response"],
                "medium": ["dispatch_resources"],
                "low": ["dispatch_resources"]
            }
        )

        dispatch_task = Task(
            name="dispatch_resources",
            description="Deploy appropriate emergency resources",
            expected_output="List of dispatched resources",
            agent=dispatcher,
            next_tasks=["monitor_response"]
        )

        monitor_task = Task(
            name="monitor_response",
            description="Track response progress",
            expected_output="Response status",
            agent=monitor,
            task_type="decision",
            condition={
                "ongoing": ["coordinate_response"],
                "completed": ""
            }
        )

        coordinate_task = Task(
            name="coordinate_response",
            description="Coordinate overall emergency response",
            expected_output="Coordinated response plan",
            agent=synthesizer,
            context=[assessment_task, dispatch_task, monitor_task]
        )

        # Create workflow
        workflow = PraisonAIAgents(
            agents=[router, dispatcher, monitor, synthesizer],
            tasks=[assessment_task, dispatch_task, monitor_task, coordinate_task],
            process="workflow",
            verbose=True
        )

        def main():
            # Simulate emergency incident
            incident = {
                "type": "fire",
                "location": "123 Main St",
                "reported_time": time.time()
            }
            
            print("\nStarting Emergency Response Workflow...")
            print("=" * 50)
            
            # Run workflow
            results = workflow.start(initial_input=incident)
            
            # Print results
            print("\nEmergency Response Results:")
            print("=" * 50)
            for task_id, result in results["task_results"].items():
                if result:
                    print(f"\nTask: {task_id}")
                    print(f"Result: {result.raw}")
                    print("-" * 50)

        if __name__ == "__main__":
            main()
        ```
    </Step>

    <Step title="Start Agents">
        Type this in your terminal to run your agents:
        ```bash
        python app.py
        ```
    </Step>
</Steps>

<Note>
  **Requirements**
  - Python 3.10 or higher
  - OpenAI API key. Generate OpenAI API key [here](https://platform.openai.com/api-keys). Use Other models using [this guide](/models).   
  - Basic understanding of Python
</Note>

## Understanding Emergency Response

<Card title="What is Emergency Response?" icon="question">
  Emergency response workflow enables:
  - Dynamic severity assessment
  - Automated resource dispatch
  - Real-time response monitoring
  - Multi-agency coordination
</Card>

## Features

<CardGroup cols={2}>
  <Card title="Severity Assessment" icon="gauge-high">
    Automatically evaluate incident severity and type.
  </Card>
  <Card title="Resource Management" icon="truck">
    Dispatch appropriate resources based on severity.
  </Card>
  <Card title="Response Monitoring" icon="eye">
    Track response progress and effectiveness.
  </Card>
  <Card title="Response Coordination" icon="people-group">
    Coordinate multi-agency response efforts.
  </Card>
</CardGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Prompt Chaining" icon="link" href="/features/promptchaining">
    Learn about sequential prompt execution
  </Card>
  <Card title="Evaluator Optimizer" icon="magnifying-glass-chart" href="/features/evaluator-optimiser">
    Explore optimization techniques
  </Card>
</CardGroup>