CubeLoop — a Pythonic, async-native agent harness core designed for high performance, readability, and production-grade persistence.
Python agent-frameworkagent-harnessagent-runtimeagentic-aiai-agentsai-frameworkanthropicharnessharness-engineeringharness-frameworklanggraphlanggraph-alternativellmmcpopenaipi-agentpi-agent-corepythonpython-agent
---
id: cubepi-middleware
title: cubepi.middleware
sidebar_position: 4
hide_table_of_contents: false
---
# `cubepi.middleware`
### Middleware
_class_
[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/middleware/base.py#L23)
### TurnAction
_class_
```python
TurnAction(self, response: AssistantMessage | None = None, inject_messages: list[Message] = list(), decision: Literal['natural', 'stop', 'loop_to_model'] = 'natural')
```
Directs the agent loop's next step after a model response.
Composition (chain): each middleware sees previous middleware's
TurnAction. Last middleware's value wins for response and decision.
inject_messages concatenates across the chain.
[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/middleware/base.py#L9)
### compose_middleware
_function_
```python
compose_middleware(middlewares: list[Middleware]) -> dict[str, Callable]
```
[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/middleware/base.py#L63)
<!-- GENERATED by build-api-reference.py — DO NOT EDIT -->