# Get TPS (Transactions Per Second)

The `Get TPS` tool, part of AgentiPy, is used to fetch and analyze Transactions Per Second (TPS) data from the Solana blockchain. It can retrieve current TPS and also track performance metrics over time.

## Functionality

The tool consists of a standalone function `fetch_performance_samples` and a class `SolanaPerformanceTracker`.

### Key Functions/Classes:

* `fetch_performance_samples(agent: SolanaAgentKit, sample_count: int = 1) -> List[NetworkPerformanceMetrics]`:
  * Asynchronously fetches a specified number of recent performance samples from the Solana network using `agent.connection.get_recent_performance_samples()`.
  * Each sample contains data like the number of transactions and the sample period.
  * Converts these samples into a list of `NetworkPerformanceMetrics` objects, which include calculated TPS, total transactions, sampling period, and current slot.
* `SolanaPerformanceTracker`:
  * **`__init__(self, agent: SolanaAgentKit)`**: Initializes the tracker with a `SolanaAgentKit` instance.
  * **`record_latest_metrics(self) -> NetworkPerformanceMetrics`**: Fetches the single latest performance sample using `fetch_performance_samples` and stores it in an internal `metrics_history`.
  * **`calculate_average_tps(self) -> Optional[float]`**: Calculates the average TPS from all metrics stored in `metrics_history`.
  * **`find_maximum_tps(self) -> Optional[float]`**: Finds the maximum TPS from the `metrics_history`.
  * **`reset_metrics_history(self) -> None`**: Clears the `metrics_history`.
  * **`fetch_current_tps(agent: SolanaAgentKit) -> float`** (static method): A static method to quickly fetch the current TPS based on the latest single performance sample. This is likely the most commonly used function for a quick TPS check.

##

## Source Code

You can find the source code for this tool on GitHub: <https://github.com/niceberginc/agentipy/blob/main/agentipy/tools/get_tps.py>


---

# Agent Instructions: 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.agentipy.fun/tools/get-tps-transactions-per-second.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.
