> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Gateway Protocol • Rust AI Agent SDK

> GatewayProtocol: Protocol for gateway/control plane implementations. The gateway coordinates communication between clients and agents, manages sessions, and provides...

# GatewayProtocol

> Defined in the [**gateway**](../modules/gateway) module.

<Badge color="orange">Rust AI Agent SDK</Badge>

Protocol for gateway/control plane implementations. The gateway coordinates communication between clients and agents, manages sessions, and provides health/presence tracking.

## Methods

### `is_running`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn is_running(&self) -> bool
```

Whether the gateway is currently running.

### `port`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn port(&self) -> u16
```

Port the gateway is listening on.

### `host`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn host(&self) -> &str
```

Host the gateway is bound to.

### `start`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
async fn start(&mut self) -> Result<()>
```

Start the gateway server.

### `stop`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
async fn stop(&mut self) -> Result<()>
```

Stop the gateway server.

### `register_agent`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn register_agent(&mut self, agent: Arc<Agent>, agent_id: Option<String>) -> String
```

Register an agent with the gateway.

**Parameters:**

| Name       | Type                   |
| ---------- | ---------------------- |
| `agent`    | `Arc&lt;Agent&gt;`     |
| `agent_id` | `Option&lt;String&gt;` |

### `unregister_agent`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn unregister_agent(&mut self, agent_id: &str) -> bool
```

Unregister an agent from the gateway.

**Parameters:**

| Name       | Type   |
| ---------- | ------ |
| `agent_id` | `&str` |

### `get_agent`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn get_agent(&self, agent_id: &str) -> Option<Arc<Agent>>
```

Get a registered agent by ID.

**Parameters:**

| Name       | Type   |
| ---------- | ------ |
| `agent_id` | `&str` |

### `list_agents`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn list_agents(&self) -> Vec<String>
```

List all registered agent IDs.

### `create_session`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn create_session(
        &mut self,
        agent_id: &str,
        client_id: Option<String>,
        session_id: Option<String>,
    ) -> Result<Box<dyn GatewaySessionProtocol>>
```

Create a new session.

**Parameters:**

| Name         | Type                   |
| ------------ | ---------------------- |
| `agent_id`   | `&str`                 |
| `client_id`  | `Option&lt;String&gt;` |
| `session_id` | `Option&lt;String&gt;` |

### `get_session`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn get_session(&self, session_id: &str) -> Option<&dyn GatewaySessionProtocol>
```

Get a session by ID.

**Parameters:**

| Name         | Type   |
| ------------ | ------ |
| `session_id` | `&str` |

### `close_session`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn close_session(&mut self, session_id: &str) -> bool
```

Close a session.

**Parameters:**

| Name         | Type   |
| ------------ | ------ |
| `session_id` | `&str` |

### `list_sessions`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn list_sessions(&self, agent_id: Option<&str>) -> Vec<String>
```

List session IDs, optionally filtered by agent.

**Parameters:**

| Name       | Type                 |
| ---------- | -------------------- |
| `agent_id` | `Option&lt;&str&gt;` |

### `emit`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
async fn emit(&self, event: GatewayEvent) -> Result<()>
```

Emit an event to registered handlers.

**Parameters:**

| Name    | Type           |
| ------- | -------------- |
| `event` | `GatewayEvent` |

### `broadcast`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
async fn broadcast(&self, event: GatewayEvent, exclude: Option<Vec<String>>) -> Result<()>
```

Broadcast an event to all connected clients.

**Parameters:**

| Name      | Type                              |
| --------- | --------------------------------- |
| `event`   | `GatewayEvent`                    |
| `exclude` | `Option&lt;Vec&lt;String&gt;&gt;` |

### `health`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn health(&self) -> GatewayHealth
```

Get gateway health status.

## Source

<Card title="View on GitHub" icon="github" href="https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-rust/praisonai/src/gateway/mod.rs">
  `praisonai/src/gateway/mod.rs` at line 0
</Card>

***

## Related Documentation

<CardGroup cols={2}>
  <Card title="Rust Gateway" icon="tower-broadcast" href="/docs/rust/gateway" />
</CardGroup>
