# Syscalls

The `Syscall` class is a fundamental component in the AIOS framework, providing a standardized mechanism for asynchronous system calls between agents and system services. It extends the `Thread` class to handle concurrent operations and includes comprehensive tracking of call status, timing metrics, and response handling.

### Key Features

* **Asynchronous Execution**: Built on Python's threading model for non-blocking operations
* **Status Tracking**: Monitors the lifecycle of system calls from creation to completion
* **Time Management**: Supports time limits and execution timing metrics
* **Priority Handling**: Allows prioritization of system calls
* **Event-Based Control**: Uses event synchronization for coordinated execution

#### Initialization

```python
def __init__(self, agent_name: str, query: Query):
    super().__init__()
    self.agent_name = agent_name
    self.query = query
    self.event = Event()
    
    # Call identification and status
    self.pid: Optional[int] = None
    self.aid: Optional[str] = None
    self.status: Optional[str] = None
    
    # Response and timing information
    self.response: Optional[Any] = None
    self.time_limit: Optional[float] = None
    
    # Timing metrics
    self.created_time: Optional[float] = None
    self.start_time: Optional[float] = None
    self.end_time: Optional[float] = None
    
    # Routing information
    self.source: Optional[str] = None
    self.target: Optional[str] = None
    self.priority: Optional[int] = None
```

#### Key Methods

| Method                   | Description                                     |
| ------------------------ | ----------------------------------------------- |
| `run()`                  | Executes the system call when the thread starts |
| `set_status(status)`     | Updates the call's current status               |
| `set_response(response)` | Sets the call's response data                   |
| `get_response()`         | Retrieves the call's response data              |
| `set_time_limit(limit)`  | Sets maximum execution time                     |
| `get_time_limit()`       | Gets the call's time limit                      |

#### Timing Management

The class includes comprehensive timing tracking:

```python
def set_created_time(self, time: float) -> None:
    self.created_time = time

def set_start_time(self, time: float) -> None:
    self.start_time = time

def set_end_time(self, time: float) -> None:
    self.end_time = time
```

These methods enable precise measurement of:

* Time spent in queue (start\_time - created\_time)
* Execution duration (end\_time - start\_time)
* Total processing time (end\_time - created\_time)

### Usage Examples

#### Creating a Custom Syscall

```python
class LLMSyscall(Syscall):
    def __init__(self, agent_name: str, query: LLMQuery):
        super().__init__(agent_name, query)
        # Add LLM-specific attributes
```

#### Executing a Syscall

```python
# Create the syscall
syscall = LLMSyscall("agent_1", LLMQuery(...))
syscall.set_time_limit(30.0)  # Set 30-second timeout

# Start execution
syscall.start()

# Wait for completion
syscall.join()

# Get the result
response = syscall.get_response()
```
