> For the complete documentation index, see [llms.txt](https://docs.aios.foundation/aios-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aios.foundation/aios-docs/aios-kernel/syscalls.md).

# 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()
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.aios.foundation/aios-docs/aios-kernel/syscalls.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
